Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/kyua/doc/manbuild_test.sh
39478 views
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.
31
MANBUILD="__MANBUILD__"
32
33
34
atf_test_case empty
35
empty_body() {
36
touch input
37
atf_check "${MANBUILD}" input output
38
atf_check cat output
39
}
40
41
42
atf_test_case no_replacements
43
no_replacements_body() {
44
cat >input <<EOF
45
This is a manpage.
46
47
With more than one line.
48
EOF
49
atf_check "${MANBUILD}" input output
50
atf_check -o file:input cat output
51
}
52
53
54
atf_test_case one_replacement
55
one_replacement_body() {
56
cat >input <<EOF
57
This is a manpage.
58
Where __FOO__ gets replaced.
59
And nothing more.
60
EOF
61
atf_check "${MANBUILD}" -v FOO=this input output
62
cat >expout <<EOF
63
This is a manpage.
64
Where this gets replaced.
65
And nothing more.
66
EOF
67
atf_check -o file:expout cat output
68
}
69
70
71
atf_test_case some_replacements
72
some_replacements_body() {
73
cat >input <<EOF
74
This is a manpage.
75
Where __FOO__ gets __BAR__.
76
And nothing more.
77
EOF
78
atf_check "${MANBUILD}" -v FOO=this -v BAR=replaced input output
79
cat >expout <<EOF
80
This is a manpage.
81
Where this gets replaced.
82
And nothing more.
83
EOF
84
atf_check -o file:expout cat output
85
}
86
87
88
atf_test_case preserve_tricky_lines
89
preserve_tricky_lines_body() {
90
cat >input <<EOF
91
Begin
92
This line is intended.
93
This other \\
94
continues later.
95
\*(LtAnd this has strange characters\*(Gt
96
End
97
EOF
98
atf_check "${MANBUILD}" input output
99
cat >expout <<EOF
100
Begin
101
This line is intended.
102
This other \\
103
continues later.
104
\*(LtAnd this has strange characters\*(Gt
105
End
106
EOF
107
atf_check -o file:expout cat output
108
}
109
110
111
atf_test_case includes_ok
112
includes_ok_body() {
113
mkdir doc doc/subdir
114
cat >doc/input <<EOF
115
This is a manpage.
116
__include__ subdir/chunk
117
There is more...
118
__include__ chunk
119
And done!
120
EOF
121
cat >doc/subdir/chunk <<EOF
122
This is the first inclusion
123
and worked __OK__.
124
EOF
125
cat >doc/chunk <<EOF
126
This is the second inclusion.
127
EOF
128
atf_check "${MANBUILD}" -v OK=ok doc/input output
129
cat >expout <<EOF
130
This is a manpage.
131
This is the first inclusion
132
and worked ok.
133
There is more...
134
This is the second inclusion.
135
And done!
136
EOF
137
atf_check -o file:expout cat output
138
}
139
140
141
atf_test_case includes_parameterized
142
includes_parameterized_body() {
143
cat >input <<EOF
144
__include__ chunk value=first
145
__include__ chunk value=second
146
EOF
147
cat >chunk <<EOF
148
This is a chunk with value: __value__.
149
EOF
150
atf_check "${MANBUILD}" input output
151
cat >expout <<EOF
152
This is a chunk with value: first.
153
This is a chunk with value: second.
154
EOF
155
atf_check -o file:expout cat output
156
}
157
158
159
atf_test_case includes_fail
160
includes_fail_body() {
161
cat >input <<EOF
162
This is a manpage.
163
__include__ missing
164
EOF
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
173
atf_test_case generate_fail
174
generate_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
184
atf_test_case validate_fail
185
validate_fail_body() {
186
cat >input <<EOF
187
This is a manpage.
188
Where __FOO__ gets replaced.
189
But where __BAR__ doesn't.
190
EOF
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
199
atf_test_case bad_args
200
bad_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
215
atf_test_case bad_option
216
bad_option_body() {
217
atf_check -s exit:1 -e match:'manbuild.sh: Unknown option -Z' \
218
"${MANBUILD}" -Z
219
}
220
221
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
235
}
236
237