xref: /freebsd/contrib/kyua/doc/manbuild_test.sh (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1# Copyright 2014 The Kyua Authors.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
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.
16#
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.
28
29
30# Absolute path to the uninstalled script.
31MANBUILD="__MANBUILD__"
32
33
34atf_test_case empty
35empty_body() {
36    touch input
37    atf_check "${MANBUILD}" input output
38    atf_check cat output
39}
40
41
42atf_test_case no_replacements
43no_replacements_body() {
44    cat >input <<EOF
45This is a manpage.
46
47With more than one line.
48EOF
49    atf_check "${MANBUILD}" input output
50    atf_check -o file:input cat output
51}
52
53
54atf_test_case one_replacement
55one_replacement_body() {
56    cat >input <<EOF
57This is a manpage.
58Where __FOO__ gets replaced.
59And nothing more.
60EOF
61    atf_check "${MANBUILD}" -v FOO=this input output
62    cat >expout <<EOF
63This is a manpage.
64Where this gets replaced.
65And nothing more.
66EOF
67    atf_check -o file:expout cat output
68}
69
70
71atf_test_case some_replacements
72some_replacements_body() {
73    cat >input <<EOF
74This is a manpage.
75Where __FOO__ gets __BAR__.
76And nothing more.
77EOF
78    atf_check "${MANBUILD}" -v FOO=this -v BAR=replaced input output
79    cat >expout <<EOF
80This is a manpage.
81Where this gets replaced.
82And nothing more.
83EOF
84    atf_check -o file:expout cat output
85}
86
87
88atf_test_case preserve_tricky_lines
89preserve_tricky_lines_body() {
90    cat >input <<EOF
91Begin
92    This line is intended.
93This other \\
94    continues later.
95\*(LtAnd this has strange characters\*(Gt
96End
97EOF
98    atf_check "${MANBUILD}" input output
99    cat >expout <<EOF
100Begin
101    This line is intended.
102This other \\
103    continues later.
104\*(LtAnd this has strange characters\*(Gt
105End
106EOF
107    atf_check -o file:expout cat output
108}
109
110
111atf_test_case includes_ok
112includes_ok_body() {
113    mkdir doc doc/subdir
114    cat >doc/input <<EOF
115This is a manpage.
116__include__ subdir/chunk
117There is more...
118__include__ chunk
119And done!
120EOF
121    cat >doc/subdir/chunk <<EOF
122This is the first inclusion
123and worked __OK__.
124EOF
125    cat >doc/chunk <<EOF
126This is the second inclusion.
127EOF
128    atf_check "${MANBUILD}" -v OK=ok doc/input output
129    cat >expout <<EOF
130This is a manpage.
131This is the first inclusion
132and worked ok.
133There is more...
134This is the second inclusion.
135And done!
136EOF
137    atf_check -o file:expout cat output
138}
139
140
141atf_test_case includes_parameterized
142includes_parameterized_body() {
143    cat >input <<EOF
144__include__ chunk value=first
145__include__ chunk value=second
146EOF
147    cat >chunk <<EOF
148This is a chunk with value: __value__.
149EOF
150    atf_check "${MANBUILD}" input output
151    cat >expout <<EOF
152This is a chunk with value: first.
153This is a chunk with value: second.
154EOF
155    atf_check -o file:expout cat output
156}
157
158
159atf_test_case includes_fail
160includes_fail_body() {
161    cat >input <<EOF
162This is a manpage.
163__include__ missing
164EOF
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" \
169        "not have been"
170}
171
172
173atf_test_case generate_fail
174generate_fail_body() {
175    touch input
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" \
180        "not have been"
181}
182
183
184atf_test_case validate_fail
185validate_fail_body() {
186    cat >input <<EOF
187This is a manpage.
188Where __FOO__ gets replaced.
189But where __BAR__ doesn't.
190EOF
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" \
195        "not have been"
196}
197
198
199atf_test_case bad_args
200bad_args_body() {
201    atf_check -s exit:1 \
202        -e match:'manbuild.sh: Must provide input and output names' \
203        "${MANBUILD}"
204
205    atf_check -s exit:1 \
206        -e match:'manbuild.sh: Must provide input and output names' \
207        "${MANBUILD}" foo
208
209    atf_check -s exit:1 \
210        -e match:'manbuild.sh: Must provide input and output names' \
211        "${MANBUILD}" foo bar baz
212}
213
214
215atf_test_case bad_option
216bad_option_body() {
217    atf_check -s exit:1 -e match:'manbuild.sh: Unknown option -Z' \
218        "${MANBUILD}" -Z
219}
220
221
222atf_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
235}
236