xref: /netbsd-src/external/bsd/kyua-atf-compat/dist/atf2kyua_test.sh (revision b92cbc7321a4a2d13071f4a9bcf671898920c6b4)
1#! __ATF_SH__
2# Copyright 2012 Google Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10#   notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above copyright
12#   notice, this list of conditions and the following disclaimer in the
13#   documentation and/or other materials provided with the distribution.
14# * Neither the name of Google Inc. nor the names of its contributors
15#   may be used to endorse or promote products derived from this software
16#   without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30
31. "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/tests_lib.subr"
32
33
34# Performs a conversion test of an Atffile without recursion.
35#
36# \param source_root The directory in which to create the fake test suite.  Must
37#     exist.
38# \param target_root The directory in which the generated Kyuafiles will be
39#     stored.  May not exist.
40# \param ... Additional parameters to pass to atf2kyua.
41one_level_test() {
42    local source_root="${1}"; shift
43    local target_root="${1}"; shift
44
45    cd "${source_root}"
46    create_test_program p1 pass
47    create_test_program p2 pass
48    create_atffile "Atffile" 'prop: test-suite = "foo"' 'tp: p1' 'tp: p2'
49    cd -
50
51    atf_check -s exit:0 -e ignore atf2kyua "${@}"
52
53    cd "${target_root}"
54    cat >expected <<EOF
55syntax('kyuafile', 1)
56
57test_suite('foo')
58
59atf_test_program{name='p1'}
60atf_test_program{name='p2'}
61EOF
62    atf_check -s exit:0 -o file:expected cat "Kyuafile"
63    cd -
64}
65
66
67# Performs a conversion test of an Atffile with recursion.
68#
69# \param source_root The directory in which to create the fake test suite.  Must
70#     exist.
71# \param target_root The directory in which the generated Kyuafiles will be
72#     stored.  May not exist.
73# \param ... Additional parameters to pass to atf2kyua.
74multiple_levels_test() {
75    local source_root="${1}"; shift
76    local target_root="${1}"; shift
77
78    cd "${source_root}"
79    create_test_program prog1 pass
80
81    mkdir dir1
82    create_test_program dir1/ignore-me pass
83    create_test_program dir1/prog2 fail
84
85    mkdir dir1/dir2
86    create_test_program dir1/dir2/prog3 skip
87    create_test_program dir1/dir2/prog4 pass
88
89    mkdir dir3
90    create_test_program dir3/prog1 fail
91
92    create_atffile Atffile 'prop: test-suite = "foo"' 'tp: prog1' 'tp: dir1'
93    create_atffile dir1/Atffile 'prop: test-suite = "bar"' 'tp-glob: [pd]*'
94    create_atffile dir1/dir2/Atffile 'prop: test-suite = "foo"' 'tp: prog3' \
95        'tp: prog4'
96    create_atffile dir3/Atffile 'prop: test-suite = "foo"' 'tp: prog1'
97    cd -
98
99    atf_check -s exit:0 -e ignore atf2kyua "${@}"
100
101    cd "${target_root}"
102    cat >expected <<EOF
103syntax('kyuafile', 1)
104
105test_suite('foo')
106
107include('dir1/Kyuafile')
108
109atf_test_program{name='prog1'}
110EOF
111    atf_check -s exit:0 -o file:expected cat Kyuafile
112
113    cat >expected <<EOF
114syntax('kyuafile', 1)
115
116test_suite('bar')
117
118include('dir2/Kyuafile')
119
120atf_test_program{name='prog2'}
121EOF
122    atf_check -s exit:0 -o file:expected cat dir1/Kyuafile
123
124    cat >expected <<EOF
125syntax('kyuafile', 1)
126
127test_suite('foo')
128
129atf_test_program{name='prog3'}
130atf_test_program{name='prog4'}
131EOF
132    atf_check -s exit:0 -o file:expected cat dir1/dir2/Kyuafile
133
134    cat >expected <<EOF
135syntax('kyuafile', 1)
136
137test_suite('foo')
138
139atf_test_program{name='prog1'}
140EOF
141    atf_check -s exit:0 -o file:expected cat dir3/Kyuafile
142    cd -
143}
144
145
146atf_test_case default__one_level
147default__one_level_body() {
148    one_level_test . .
149}
150
151
152atf_test_case default__multiple_levels
153default__multiple_levels_body() {
154    multiple_levels_test . .
155}
156
157
158atf_test_case sflag__one_level
159sflag__one_level_body() {
160    mkdir root
161    one_level_test root root -s root
162}
163
164
165atf_test_case sflag__multiple_levels
166sflag__multiple_levels_body() {
167    mkdir root
168    multiple_levels_test root root -s root
169}
170
171
172atf_test_case tflag__one_level
173tflag__one_level_body() {
174    one_level_test . target -t target
175}
176
177
178atf_test_case tflag__multiple_levels
179tflag__multiple_levels_body() {
180    multiple_levels_test . target -t target
181}
182
183
184atf_test_case sflag_tflag__one_level
185sflag_tflag__one_level_body() {
186    mkdir source
187    one_level_test source target -s source -t target
188}
189
190
191atf_test_case sflag_tflag__multiple_levels
192sflag_tflag__multiple_levels_body() {
193    mkdir source
194    multiple_levels_test source target -s source -t target
195}
196
197
198atf_test_case prune_stale_kyuafiles
199prune_stale_kyuafiles_body() {
200    create_test_program p1 fail
201    create_test_program p2 skip
202    chmod +x p1 p2
203    create_atffile Atffile 'prop: test-suite = "foo"' 'tp: p1' 'tp: p2'
204
205    mkdir subdir
206    touch subdir/Kyuafile
207
208    atf_check -s exit:0 -e ignore atf2kyua
209
210    test -f Kyuafile || atf_fail "Kyuafiles not created as expected"
211    test \! -f subdir/Kyuafile || atf_fail "Stale kyuafiles not removed"
212}
213
214
215atf_test_case unknown_option
216unknown_option_body() {
217    atf_check -s exit:1 -o empty -e match:'E: Unknown option -Z' \
218        atf2kyua -Z -A
219}
220
221
222atf_test_case too_many_arguments
223too_many_arguments_body() {
224    atf_check -s exit:1 -o empty -e match:'E: No arguments allowed' \
225        atf2kyua first
226}
227
228
229atf_init_test_cases() {
230    atf_add_test_case default__one_level
231    atf_add_test_case default__multiple_levels
232
233    atf_add_test_case sflag__one_level
234    atf_add_test_case sflag__multiple_levels
235
236    atf_add_test_case tflag__one_level
237    atf_add_test_case tflag__multiple_levels
238
239    atf_add_test_case sflag_tflag__one_level
240    atf_add_test_case sflag_tflag__multiple_levels
241
242    atf_add_test_case prune_stale_kyuafiles
243
244    atf_add_test_case unknown_option
245    atf_add_test_case too_many_arguments
246}
247