1 # Copyright 2014 The Kyua Authors.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of Google Inc. nor the names of its contributors
14 # may be used to endorse or promote products derived from this software
15 # without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # Absolute path to the uninstalled script.
31 MANBUILD="__MANBUILD__"
37 atf_check "${MANBUILD}" input output
42 atf_test_case no_replacements
43 no_replacements_body() {
47 With more than one line.
49 atf_check "${MANBUILD}" input output
50 atf_check -o file:input cat output
54 atf_test_case one_replacement
55 one_replacement_body() {
58 Where __FOO__ gets replaced.
61 atf_check "${MANBUILD}" -v FOO=this input output
64 Where this gets replaced.
67 atf_check -o file:expout cat output
71 atf_test_case some_replacements
72 some_replacements_body() {
75 Where __FOO__ gets __BAR__.
78 atf_check "${MANBUILD}" -v FOO=this -v BAR=replaced input output
81 Where this gets replaced.
84 atf_check -o file:expout cat output
88 atf_test_case preserve_tricky_lines
89 preserve_tricky_lines_body() {
92 This line is intended.
95 \*(LtAnd this has strange characters\*(Gt
98 atf_check "${MANBUILD}" input output
101 This line is intended.
104 \*(LtAnd this has strange characters\*(Gt
107 atf_check -o file:expout cat output
111 atf_test_case includes_ok
116 __include__ subdir/chunk
121 cat >doc/subdir/chunk <<EOF
122 This is the first inclusion
126 This is the second inclusion.
128 atf_check "${MANBUILD}" -v OK=ok doc/input output
131 This is the first inclusion
134 This is the second inclusion.
137 atf_check -o file:expout cat output
141 atf_test_case includes_parameterized
142 includes_parameterized_body() {
144 __include__ chunk value=first
145 __include__ chunk value=second
148 This is a chunk with value: __value__.
150 atf_check "${MANBUILD}" input output
152 This is a chunk with value: first.
153 This is a chunk with value: second.
155 atf_check -o file:expout cat output
159 atf_test_case includes_fail
160 includes_fail_body() {
165 atf_check -s exit:1 -o ignore \
166 -e match:"manbuild.sh: Failed to generate output.*left unreplaced" \
167 "${MANBUILD}" input output
168 [ ! -f output ] || atf_fail "Output file was generated but it should" \
173 atf_test_case generate_fail
174 generate_fail_body() {
176 atf_check -s exit:1 -o ignore \
177 -e match:"manbuild.sh: Failed to generate output" \
178 "${MANBUILD}" -v 'malformed&name=value' input output
179 [ ! -f output ] || atf_fail "Output file was generated but it should" \
184 atf_test_case validate_fail
185 validate_fail_body() {
188 Where __FOO__ gets replaced.
189 But where __BAR__ doesn't.
191 atf_check -s exit:1 -o ignore \
192 -e match:"manbuild.sh: Failed to generate output.*left unreplaced" \
193 "${MANBUILD}" -v FOO=this input output
194 [ ! -f output ] || atf_fail "Output file was generated but it should" \
199 atf_test_case bad_args
201 atf_check -s exit:1 \
202 -e match:'manbuild.sh: Must provide input and output names' \
205 atf_check -s exit:1 \
206 -e match:'manbuild.sh: Must provide input and output names' \
209 atf_check -s exit:1 \
210 -e match:'manbuild.sh: Must provide input and output names' \
211 "${MANBUILD}" foo bar baz
215 atf_test_case bad_option
217 atf_check -s exit:1 -e match:'manbuild.sh: Unknown option -Z' \
222 atf_init_test_cases() {
223 atf_add_test_case empty
224 atf_add_test_case no_replacements
225 atf_add_test_case one_replacement
226 atf_add_test_case some_replacements
227 atf_add_test_case preserve_tricky_lines
228 atf_add_test_case includes_ok
229 atf_add_test_case includes_parameterized
230 atf_add_test_case includes_fail
231 atf_add_test_case generate_fail
232 atf_add_test_case validate_fail
233 atf_add_test_case bad_args
234 atf_add_test_case bad_option