atf_check_test.sh revision 1.1 1 1.1 jmmv #
2 1.1 jmmv # Automated Testing Framework (atf)
3 1.1 jmmv #
4 1.1 jmmv # Copyright (c) 2007, 2008, 2010 The NetBSD Foundation, Inc.
5 1.1 jmmv # All rights reserved.
6 1.1 jmmv #
7 1.1 jmmv # Redistribution and use in source and binary forms, with or without
8 1.1 jmmv # modification, are permitted provided that the following conditions
9 1.1 jmmv # are met:
10 1.1 jmmv # 1. Redistributions of source code must retain the above copyright
11 1.1 jmmv # notice, this list of conditions and the following disclaimer.
12 1.1 jmmv # 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmmv # notice, this list of conditions and the following disclaimer in the
14 1.1 jmmv # documentation and/or other materials provided with the distribution.
15 1.1 jmmv #
16 1.1 jmmv # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 1.1 jmmv # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 1.1 jmmv # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 1.1 jmmv # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 jmmv # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 1.1 jmmv # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 jmmv # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 1.1 jmmv # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.1 jmmv # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 1.1 jmmv # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 1.1 jmmv # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 1.1 jmmv # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 jmmv #
29 1.1 jmmv
30 1.1 jmmv # TODO: Bring in the checks in the bootstrap testsuite for atf_check.
31 1.1 jmmv
32 1.1 jmmv atf_test_case info_ok
33 1.1 jmmv info_ok_head()
34 1.1 jmmv {
35 1.1 jmmv atf_set "descr" "Verifies that atf_check prints an informative" \
36 1.1 jmmv "message even when the command is successful"
37 1.1 jmmv atf_set "use.fs" "true"
38 1.1 jmmv }
39 1.1 jmmv info_ok_body()
40 1.1 jmmv {
41 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
42 1.1 jmmv
43 1.1 jmmv atf_check -s eq:0 -o save:stdout -e save:stderr -x \
44 1.1 jmmv "${h} atf_check_info_ok"
45 1.1 jmmv grep 'Executing command.*true' stdout >/dev/null || \
46 1.1 jmmv atf_fail "atf_check does not print an informative message"
47 1.1 jmmv
48 1.1 jmmv atf_check -s eq:0 -o save:stdout -e save:stderr -x \
49 1.1 jmmv "${h} atf_check_info_fail"
50 1.1 jmmv grep 'Executing command.*false' stdout >/dev/null || \
51 1.1 jmmv atf_fail "atf_check does not print an informative message"
52 1.1 jmmv }
53 1.1 jmmv
54 1.1 jmmv atf_test_case expout_mismatch
55 1.1 jmmv expout_mismatch_head()
56 1.1 jmmv {
57 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a diff of the" \
58 1.1 jmmv "stdout and the expected stdout if the two do no" \
59 1.1 jmmv "match"
60 1.1 jmmv atf_set "use.fs" "true"
61 1.1 jmmv }
62 1.1 jmmv expout_mismatch_body()
63 1.1 jmmv {
64 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
65 1.1 jmmv
66 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \
67 1.1 jmmv "${h} atf_check_expout_mismatch"
68 1.1 jmmv grep 'Executing command.*echo bar' stdout >/dev/null || \
69 1.1 jmmv atf_fail "atf_check does not print an informative message"
70 1.1 jmmv grep 'stdout does not match golden output' stderr >/dev/null || \
71 1.1 jmmv atf_fail "atf_check does not print the stdout header"
72 1.1 jmmv grep 'stderr' stderr >/dev/null && \
73 1.1 jmmv atf_fail "atf_check prints the stderr header"
74 1.1 jmmv grep '^-foo' stderr >/dev/null || \
75 1.1 jmmv atf_fail "atf_check does not print the stdout's diff"
76 1.1 jmmv grep '^+bar' stderr >/dev/null || \
77 1.1 jmmv atf_fail "atf_check does not print the stdout's diff"
78 1.1 jmmv }
79 1.1 jmmv
80 1.1 jmmv atf_test_case experr_mismatch
81 1.1 jmmv experr_mismatch_head()
82 1.1 jmmv {
83 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a diff of the" \
84 1.1 jmmv "stderr and the expected stderr if the two do no" \
85 1.1 jmmv "match"
86 1.1 jmmv atf_set "use.fs" "true"
87 1.1 jmmv }
88 1.1 jmmv experr_mismatch_body()
89 1.1 jmmv {
90 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
91 1.1 jmmv
92 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \
93 1.1 jmmv "${h} atf_check_experr_mismatch"
94 1.1 jmmv grep 'Executing command.*echo bar' stdout >/dev/null || \
95 1.1 jmmv atf_fail "atf_check does not print an informative message"
96 1.1 jmmv grep 'stdout' stderr >/dev/null && \
97 1.1 jmmv atf_fail "atf_check prints the stdout header"
98 1.1 jmmv grep 'stderr does not match golden output' stderr >/dev/null || \
99 1.1 jmmv atf_fail "atf_check does not print the stderr header"
100 1.1 jmmv grep '^-foo' stderr >/dev/null || \
101 1.1 jmmv atf_fail "atf_check does not print the stderr's diff"
102 1.1 jmmv grep '^+bar' stderr >/dev/null || \
103 1.1 jmmv atf_fail "atf_check does not print the stderr's diff"
104 1.1 jmmv }
105 1.1 jmmv
106 1.1 jmmv atf_test_case null_stdout
107 1.1 jmmv null_stdout_head()
108 1.1 jmmv {
109 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a the stdout it got" \
110 1.1 jmmv "when it was supposed to be null"
111 1.1 jmmv atf_set "use.fs" "true"
112 1.1 jmmv }
113 1.1 jmmv null_stdout_body()
114 1.1 jmmv {
115 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
116 1.1 jmmv
117 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \
118 1.1 jmmv "${h} atf_check_null_stdout"
119 1.1 jmmv grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \
120 1.1 jmmv atf_fail "atf_check does not print an informative message"
121 1.1 jmmv grep 'stdout not empty' stderr >/dev/null || \
122 1.1 jmmv atf_fail "atf_check does not print the stdout header"
123 1.1 jmmv grep 'stderr' stderr >/dev/null && \
124 1.1 jmmv atf_fail "atf_check prints the stderr header"
125 1.1 jmmv grep 'These are the contents' stderr >/dev/null || \
126 1.1 jmmv atf_fail "atf_check does not print stdout's contents"
127 1.1 jmmv }
128 1.1 jmmv
129 1.1 jmmv atf_test_case null_stderr
130 1.1 jmmv null_stderr_head()
131 1.1 jmmv {
132 1.1 jmmv atf_set "descr" "Verifies that atf_check prints a the stderr it got" \
133 1.1 jmmv "when it was supposed to be null"
134 1.1 jmmv atf_set "use.fs" "true"
135 1.1 jmmv }
136 1.1 jmmv null_stderr_body()
137 1.1 jmmv {
138 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
139 1.1 jmmv
140 1.1 jmmv atf_check -s eq:1 -o save:stdout -e save:stderr -x \
141 1.1 jmmv "${h} atf_check_null_stderr"
142 1.1 jmmv grep 'Executing command.*echo.*These.*contents' stdout >/dev/null || \
143 1.1 jmmv atf_fail "atf_check does not print an informative message"
144 1.1 jmmv grep 'stdout' stderr >/dev/null && \
145 1.1 jmmv atf_fail "atf_check prints the stdout header"
146 1.1 jmmv grep 'stderr not empty' stderr >/dev/null || \
147 1.1 jmmv atf_fail "atf_check does not print the stderr header"
148 1.1 jmmv grep 'These are the contents' stderr >/dev/null || \
149 1.1 jmmv atf_fail "atf_check does not print stderr's contents"
150 1.1 jmmv }
151 1.1 jmmv
152 1.1 jmmv atf_test_case equal
153 1.1 jmmv equal_head()
154 1.1 jmmv {
155 1.1 jmmv atf_set "descr" "Verifies that atf_check_equal works"
156 1.1 jmmv atf_set "use.fs" "true"
157 1.1 jmmv }
158 1.1 jmmv equal_body()
159 1.1 jmmv {
160 1.1 jmmv h="$(atf_get_srcdir)/misc_helpers -s $(atf_get_srcdir)"
161 1.1 jmmv
162 1.1 jmmv atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_ok"
163 1.1 jmmv
164 1.1 jmmv atf_check -s eq:1 -o ignore -e ignore -x \
165 1.1 jmmv "${h} -r resfile atf_check_equal_fail"
166 1.1 jmmv atf_check -s eq:0 -o ignore -e empty grep '^failed: a != b (a != b)$' \
167 1.1 jmmv resfile
168 1.1 jmmv
169 1.1 jmmv atf_check -s eq:0 -o ignore -e ignore -x "${h} atf_check_equal_eval_ok"
170 1.1 jmmv
171 1.1 jmmv atf_check -s eq:1 -o ignore -e ignore -x \
172 1.1 jmmv "${h} -r resfile atf_check_equal_eval_fail"
173 1.1 jmmv atf_check -s eq:0 -o ignore -e empty \
174 1.1 jmmv grep '^failed: \${x} != \${y} (a != b)$' resfile
175 1.1 jmmv }
176 1.1 jmmv
177 1.1 jmmv atf_init_test_cases()
178 1.1 jmmv {
179 1.1 jmmv atf_add_test_case info_ok
180 1.1 jmmv atf_add_test_case expout_mismatch
181 1.1 jmmv atf_add_test_case experr_mismatch
182 1.1 jmmv atf_add_test_case null_stdout
183 1.1 jmmv atf_add_test_case null_stderr
184 1.1 jmmv atf_add_test_case equal
185 1.1 jmmv }
186 1.1 jmmv
187 1.1 jmmv # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
188