-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfailing-tests.sh
executable file
·79 lines (61 loc) · 1.6 KB
/
failing-tests.sh
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
#!/bin/sh
# the exit code will be equal to the number of failed tests
source spec.sh
after_all() {
echo "hihihi ... I am last"
}
it_should_support_defer_even_on_fails() {
echo "hallo" > out
defer rm out # this will be executed when the test is finished or if any of the asserts fails
assert_true "test -e out"
}
# 1
it_should_assert_command() {
# assert_true with one argument will execute the string and pass if the result is 0
assert_true "ls /xxxtmp"
}
# 2
it_should_assert_command_with_description() {
assert_true "ls /xxxtmp" "assert_true with a description"
}
# 3
it_should_negate_assert_match_correctly() {
assert_nmatch "hallo" "ll"
}
# 4
it_should_compare_exit_code() {
false
# make sure that the return code is 0 ... or 1 or something different
assert_eq 0 0
assert_eq 0 0 "0 should be 0"
assert_eq $? 2
}
# 5
it_should_compare_string() {
# match strings
assert_eq "$(echo 'hallo' | tr 'l' 'x')" "haggo"
}
# 6
it_should_compare_string_with_description() {
# pass an optional description as a third argument ... helpful when on test has many asserts
assert_eq "$(echo 'hallo' | tr 'l' 'x')" "haggo" "transforming string should work"
}
# 7
it_should_match_regexp() {
sleep 0.3
# use 'assert_match' to match against an _extended_ regexp (https://www.gnu.org/software/sed/manual/html_node/Extended-regexps.html)
assert_match "aaa:88X09" "aaa:[0-9]{5}"
}
# 8
it_should_negate_assert_correctly() {
assert_false "ls /" "this test should fail"
}
# 9
it_should_negate_assert_eq_correctly() {
assert_neq 1 1
}
# 10
it_should_reflect_exit_code() {
return 3
}
run_tests