1 # Copyright (c) 2007 The NetBSD Foundation, Inc.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
13 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 # TODO: Bring in the checks in the bootstrap testsuite for atf_check.
31 atf_set "descr" "Verifies that atf_check prints an informative" \
32 "message even when the command is successful"
36 h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
38 atf_check -s eq:0 -o save:stdout -e save:stderr -x \
39 "${h} atf_check_info_ok"
40 grep 'Executing command.*true' stdout >/dev/null || \
41 atf_fail "atf_check does not print an informative message"
43 atf_check -s eq:0 -o save:stdout -e save:stderr -x \
44 "${h} atf_check_info_fail"
45 grep 'Executing command.*false' stdout >/dev/null || \
46 atf_fail "atf_check does not print an informative message"
49 atf_test_case expout_mismatch
50 expout_mismatch_head()
52 atf_set "descr" "Verifies that atf_check prints a diff of the" \
53 "stdout and the expected stdout if the two do not" \
56 expout_mismatch_body()
58 h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
60 atf_check -s eq:1 -o save:stdout -e save:stderr -x \
61 "${h} atf_check_expout_mismatch"
62 grep 'Executing command.*echo bar' stdout >/dev/null || \
63 atf_fail "atf_check does not print an informative message"
64 grep 'stdout does not match golden output' stderr >/dev/null || \
65 atf_fail "atf_check does not print the stdout header"
66 grep 'stderr' stderr >/dev/null && \
67 atf_fail "atf_check prints the stderr header"
68 grep '^-foo' stderr >/dev/null || \
69 atf_fail "atf_check does not print the stdout's diff"
70 grep '^+bar' stderr >/dev/null || \
71 atf_fail "atf_check does not print the stdout's diff"
74 atf_test_case experr_mismatch
75 experr_mismatch_head()
77 atf_set "descr" "Verifies that atf_check prints a diff of the" \
78 "stderr and the expected stderr if the two do not" \
81 experr_mismatch_body()
83 h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
85 atf_check -s eq:1 -o save:stdout -e save:stderr -x \
86 "${h} atf_check_experr_mismatch"
87 grep 'Executing command.*echo bar' stdout >/dev/null || \
88 atf_fail "atf_check does not print an informative message"
89 grep 'stdout' stderr >/dev/null && \
90 atf_fail "atf_check prints the stdout header"
91 grep 'stderr does not match golden output' stderr >/dev/null || \
92 atf_fail "atf_check does not print the stderr header"
93 grep '^-foo' stderr >/dev/null || \
94 atf_fail "atf_check does not print the stderr's diff"
95 grep '^+bar' stderr >/dev/null || \
96 atf_fail "atf_check does not print the stderr's diff"
99 atf_test_case null_stdout
102 atf_set "descr" "Verifies that atf_check prints a the stdout it got" \
103 "when it was supposed to be null"
107 h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
109 atf_check -s eq:1 -o save:stdout -e save:stderr -x \
110 "${h} atf_check_null_stdout"
111 grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \
112 atf_fail "atf_check does not print an informative message"
113 grep 'stdout not empty' stderr >/dev/null || \
114 atf_fail "atf_check does not print the stdout header"
115 grep 'stderr' stderr >/dev/null && \
116 atf_fail "atf_check prints the stderr header"
117 grep 'These are the contents' stderr >/dev/null || \
118 atf_fail "atf_check does not print stdout's contents"
121 atf_test_case null_stderr
124 atf_set "descr" "Verifies that atf_check prints a the stderr it got" \
125 "when it was supposed to be null"
129 h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
131 atf_check -s eq:1 -o save:stdout -e save:stderr -x \
132 "${h} atf_check_null_stderr"
133 grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \
134 atf_fail "atf_check does not print an informative message"
135 grep 'stdout' stderr >/dev/null && \
136 atf_fail "atf_check prints the stdout header"
137 grep 'stderr not empty' stderr >/dev/null || \
138 atf_fail "atf_check does not print the stderr header"
139 grep 'These are the contents' stderr >/dev/null || \
140 atf_fail "atf_check does not print stderr's contents"
146 atf_set "descr" "Verifies that atf_check_equal works"
150 h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
152 atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_ok"
154 atf_check -s eq:1 -o ignore -e ignore -x \
155 "${h} -r resfile atf_check_equal_fail"
156 atf_check -s eq:0 -o ignore -e empty grep '^failed: a != b (a != b)$' \
159 atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_eval_ok"
161 atf_check -s eq:1 -o ignore -e ignore -x \
162 "${h} -r resfile atf_check_equal_eval_fail"
163 atf_check -s eq:0 -o ignore -e empty \
164 grep '^failed: \${x} != \${y} (a != b)$' resfile
167 atf_test_case flush_stdout_on_death
168 flush_stdout_on_death_body()
170 CONTROL_FILE="$(pwd)/done" "$(atf_get_srcdir)/misc_helpers" \
171 -s "$(atf_get_srcdir)" atf_check_flush_stdout >out 2>err &
173 while [ ! -f ./done ]; do
174 echo "Still waiting for helper to create control file"
180 grep 'Executing command.*true' out \
181 || atf_fail 'First command not in output'
182 grep 'Executing command.*false' out \
183 || atf_fail 'Second command not in output'
186 atf_init_test_cases()
188 atf_add_test_case info_ok
189 atf_add_test_case expout_mismatch
190 atf_add_test_case experr_mismatch
191 atf_add_test_case null_stdout
192 atf_add_test_case null_stderr
193 atf_add_test_case equal
194 atf_add_test_case flush_stdout_on_death
197 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4