Debian Codegraph @

tests/test_tap_format

raw
1 #!/usr/bin/env bash
2
3 test_bash_unit_accepts_tap_format_option() {
4 assert "$BASH_UNIT -f tap"
5 }
6
7 test_bash_unit_rejects_invalid_format() {
8 assert_fails "$BASH_UNIT -f invalid_format"
9 }
10
11 test_tap_format_for_one_succesfull_test() {
12 assert_equals \
13 "\
14 # Running tests in code
15 ok - test_ok
16 1..1" \
17 "$(bash_unit_out_for_code <<EOF
18 test_ok() {
19 assert true
20 }
21 EOF
22 )"
23 }
24
25 test_tap_format_for_one_failing_test() {
26 assert_equals \
27 "\
28 # Running tests in code
29 not ok - test_not_ok
30 # ./code:2:test_not_ok()
31 1..1" \
32 "$(bash_unit_out_for_code <<EOF
33 test_not_ok() {
34 assert false
35 }
36 EOF
37 )"
38 }
39
40 test_tap_format_for_one_pending_test() {
41 assert_equals \
42 "\
43 # Running tests in code
44 ok - pending_not_yet_implemented # todo test to be written
45 1..1" \
46 "$(bash_unit_out_for_code <<EOF
47 pending_not_yet_implemented() {
48 assert false
49 }
50 EOF
51 )"
52 }
53
54 test_tap_format_with_skipped_tests() {
55 bash_unit_output="$(bash_unit_out_for_code <<EOF
56 test_one() { echo -n ; }
57 test_two() { fail ; }
58 skip_if true two
59 EOF
60 )"
61
62 assert_equals "\
63 # Running tests in code
64 ok - test_two # skip test not run
65 ok - test_one
66 1..2" \
67 "$bash_unit_output"
68 }
69
70 test_tap_format_for_failing_test_with_stdout_stderr_outputs() {
71 assert_equals \
72 "\
73 # Running tests in code
74 not ok - test_not_ok
75 # out> message on stdout
76 # err> message on stderr
77 # ./code:2:test_not_ok()
78 1..1" \
79 "$(bash_unit_out_for_code <<EOF
80 test_not_ok() {
81 assert_fails "echo message on stdout ; echo message on stderr >&2"
82 }
83 EOF
84 )"
85 }
86
87 test_assertion_message_is_tap_formatted() {
88 assert_equals \
89 "\
90 # Running tests in code
91 not ok - test_not_ok
92 # obvious failure
93 # ./code:2:test_not_ok()
94 1..1" \
95 "$(bash_unit_out_for_code <<EOF
96 test_not_ok() {
97 assert_fails true "obvious failure"
98 }
99 EOF
100 )"
101 }
102
103 test_multi_lines_assertion_message_is_tap_formatted() {
104 assert_equals \
105 "\
106 # Running tests in code
107 not ok - test_not_ok
108 # obvious failure
109 # on multiple lines
110 # ./code:2:test_not_ok()
111 1..1" \
112 "$(bash_unit_out_for_code <<EOF
113 test_not_ok() {
114 assert_fails true "obvious failure\non multiple lines"
115 }
116 EOF
117 )"
118 }
119
120 bash_unit_out_for_code() {
121 $BASH_UNIT -f tap <(cat) | sed -e 's:/dev/fd/[0-9]*:code:' -e 's/[0-9]*:/code:/'
122 }
123
124 BASH_UNIT="eval FORCE_COLOR=false ../bash_unit"