-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.butt
86 lines (67 loc) · 1.37 KB
/
example.butt
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/env butt
# define user functions
function before {
:
}
function after {
:
}
start "simple test"
before
debug echo "test"
assert_equal $status 0
assert_equal "$stdout" test
after
end
start "test stderr"
before
debug echo "test >&2"
assert_equal $status 0
assert_equal "$stderr" test
after
end
start "complex test"
# call user function
before
# some custom code before test
# debug tested command
debug echo -e "test$'\n'test1"
# assert command output
assert_equal $status 0
assert_equal "${outlines[0]}" test
assert_equal "${outlines[1]}" test1
# debug second tested command
debug 'echo "aaa bbb" | cut -d" " -f2'
# assert command output
assert_equal $status 0
assert_equal $stdout bbb
# debug second tested command (another way)
out="$(echo "aaa bbb" | cut -d" " -f2)"
assert_equal $? 0
assert_equal $out bbb
# call user function
after
# end test
end
# test case can be placed in loop
for (( i = 0; i < 3; i++ )); do
start "test in loop #$i"
debug echo $i
assert_equal $status 0
end
done
# dynamic test case
function test_number {
start "test '${1-}' is a number"
[[ "${1-}" =~ ^-?[1-9][0-9]*$ ]]
assert_equal $? 0
end
}
test_number 1
test_number
test_number abc
# start "example of disabled test"
# debug echo "test"
# assert_equal $status 0
# assert_equal "$stdout" test
# end