Commit d76eba5 1 parent e080a37 commit d76eba5 Copy full SHA for d76eba5
File tree 3 files changed +13
-1
lines changed
3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 1
1
# Testing
2
+ Returns non-zero exit code when assertion fails.
3
+ Total count of assertion errors stored in ` global_assert_errors ` .
2
4
3
5
## test_assertions
4
6
Unit test functions
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
3
+ global_assert_errors=0
4
+
3
5
function assert_exited_with_success() {
4
6
local description
5
7
local exit_code
@@ -28,6 +30,7 @@ function assert_exited_with_success() {
28
30
fi
29
31
fi
30
32
33
+ (( global_assert_errors += ${exit_code} ))
31
34
return ${exit_code}
32
35
}
33
36
@@ -61,7 +64,7 @@ function assert_contains_text() {
61
64
if [[ ! " ${text} " = * " ${check} " * ]]
62
65
then
63
66
(( exit_code += 1 ))
64
- echo " Failure: ${check} not found" >&2
67
+ echo " Failure: ' ${check} ' not found" >&2
65
68
fi
66
69
done
67
70
@@ -71,6 +74,8 @@ function assert_contains_text() {
71
74
else
72
75
echo " SUCCESS ${description} "
73
76
fi
77
+
78
+ (( global_assert_errors += ${exit_code} ))
74
79
fi
75
80
fi
76
81
Original file line number Diff line number Diff line change @@ -26,22 +26,27 @@ assert_result_fails_with_error_text "$(assert_contains_text description 'input'
26
26
27
27
if [ ${run_tests} -eq 1 ]
28
28
then
29
+ global_assert_errors=0
29
30
echo
30
31
echo ' ---Example tests---'
31
32
echo ' This should succeed'
32
33
laugh_maniacally_and_exit 0 > /dev/null
33
34
assert_exited_with_success ' Happy laughter' ${?}
35
+ echo " Global assert errors: ${global_assert_errors} "
34
36
echo
35
37
echo ' This should fail'
36
38
laugh_maniacally_and_exit 1 > /dev/null
37
39
assert_exited_with_success ' Sad laughter' ${?}
40
+ echo " Global assert errors: ${global_assert_errors} "
38
41
echo
39
42
echo ' This should find some text'
40
43
laugh_result=$( laugh_maniacally_and_exit 0)
41
44
assert_exited_with_success ' Textual laughter' ${?}
42
45
assert_contains_text ' laughed a lot' " ${laugh_result} " ' muah' ' ha' ' phew'
46
+ echo " Global assert errors: ${global_assert_errors} "
43
47
echo
44
48
echo ' This should fail to find yuck and muck'
45
49
assert_contains_text ' laughed a lot text search' " ${laugh_result} " ' muah' ' ha' ' phew' ' yuck' ' muck'
50
+ echo " Global assert errors: ${global_assert_errors} "
46
51
echo " And now the exit code is ${?} "
47
52
fi
You can’t perform that action at this time.
0 commit comments