forked from mweitzel/firetower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·57 lines (45 loc) · 1.55 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
SOURCE_FIRETOWER_FOR_UNIT_TESTING=1
source ./firetower
plan=11
function pass() { plan=$(($plan - 1)); }
function fail() { echo fail at $(caller); exit 1 ; }
# get_command returns command whether or not -c is specified
t(){
test "$(get_command -c 'some command')" = 'some command' && pass || fail
test "$(get_command 'some command')" = 'some command' && pass || fail
};t
# is_integer exits with 0 only if string is integer
t(){
is_integer 5 && pass || fail
is_integer asdf && fail || pass
};t
# process_is_alive exits with 0 only if process is alive
t(){
sleep 1 &
local invalid_pid=1111111111111111111 #clearly
process_is_alive $? && pass || fail # test $? -eq 0
process_is_alive $invalid_pid || pass || fail # test $? -eq 1
};t
# should_preserve_scrollback exits with 0 only if --preserve-scrollback is an argument
t() {
should_preserve_scrollback 'banana pants' --preserve-scrollback && pass || fail
should_preserve_scrollback --preserve-scrollback 'banana pants' && pass || fail
should_preserve_scrollback 'there is not preserve scrollback' && fail || pass
};t
# announce_command_start announces command
t() {
announce_command_start 'ls potato sandwich' |
grep -q 'firetower started `ls potato sandwich` at' && pass || fail
};t
# announce_command_finish formats command and exit code into a formatted display
t() {
announce_command_finish 'ls potato sandwich' 123 |
grep -q 'exit code: 123' && pass || fail
};t
test $plan -eq 0 && pass || {
echo "expected $plan more passing tests"
fail
}
echo 'success'
exit 0