xref: /netbsd-src/external/bsd/kyua-atf-compat/dist/atf-report_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
34atf_test_case ticker__no_tests
35ticker__no_tests_body() {
36    cat >Kyuafile <<EOF
37syntax('kyuafile', 1)
38EOF
39
40    atf_check -s exit:0 -o save:run.log -e ignore atf-run
41
42    cat >expout <<EOF
43===> Summary
44Action: 1
45Test cases: 0 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
46Total time: X.XXXs
47EOF
48    atf_check -s exit:0 -o save:report.log -e empty atf-report <run.log
49    strip_timestamps report.log
50    atf_check -s exit:0 -o file:expout cat report.log
51}
52
53
54atf_test_case ticker__some_tests
55ticker__some_tests_body() {
56    create_test_program program1 skip
57    create_test_program program2 fail skip pass
58    cat >Kyuafile <<EOF
59syntax('kyuafile', 1)
60test_suite('foo')
61atf_test_program{name='program1'}
62atf_test_program{name='program2'}
63EOF
64    atf_check -s exit:1 -o save:run.log -e ignore atf-run
65
66    cat >expout <<EOF
67program1:skip  ->  skipped: Skipped reason  [X.XXXs]
68program2:fail  ->  failed: On purpose  [X.XXXs]
69program2:skip  ->  skipped: Skipped reason  [X.XXXs]
70program2:pass  ->  passed  [X.XXXs]
71===> Skipped tests
72program1:skip  ->  skipped: Skipped reason  [X.XXXs]
73program2:skip  ->  skipped: Skipped reason  [X.XXXs]
74===> Failed tests
75program2:fail  ->  failed: On purpose  [X.XXXs]
76===> Summary
77Action: 1
78Test cases: 4 total, 2 skipped, 0 expected failures, 0 broken, 1 failed
79Total time: X.XXXs
80EOF
81    atf_check -s exit:0 -o save:report.log -e empty atf-report <run.log
82    strip_timestamps report.log
83    atf_check -s exit:0 -o file:expout cat report.log
84}
85
86
87atf_test_case ticker__explicit
88ticker__explicit_body() {
89    cat >Kyuafile <<EOF
90syntax('kyuafile', 1)
91EOF
92
93    atf_check -s exit:0 -o save:run.log -e ignore atf-run
94
95    cat >expout <<EOF
96===> Summary
97Action: 1
98Test cases: 0 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
99Total time: X.XXXs
100EOF
101    atf_check -s exit:0 -o empty -e empty \
102        atf-report -o ticker:my-report.log <run.log
103    strip_timestamps my-report.log
104    atf_check -s exit:0 -o file:expout cat my-report.log
105}
106
107
108atf_test_case html__no_tests
109html__no_tests_body() {
110    cat >Kyuafile <<EOF
111syntax('kyuafile', 1)
112EOF
113    atf_check -s exit:0 -o save:run.log -e ignore atf-run
114    atf_check -s exit:0 -o ignore -e empty \
115        atf-report -o html:report.html <run.log
116
117    echo "All generated files"
118    ls -l report.html report.files
119
120    for file in index.html context.html report.css; do
121        test -f report.files/"${file}" || \
122            atf_fail "Expected file ${file} not found"
123    done
124
125    test report.html -ef report.files/index.html || \
126        atf_fail "Index file link not created properly"
127}
128
129
130atf_test_case html__some_tests
131html__some_tests_body() {
132    create_test_program program1 skip
133    create_test_program program2 fail skip pass
134    cat >Kyuafile <<EOF
135syntax('kyuafile', 1)
136test_suite('foo')
137atf_test_program{name='program1'}
138atf_test_program{name='program2'}
139EOF
140    atf_check -s exit:1 -o save:run.log -e ignore atf-run
141    atf_check -s exit:0 -o ignore -e empty \
142        atf-report -o html:report.html <run.log
143
144    echo "All generated files"
145    ls -l report.html report.files
146
147    for file in index.html context.html report.css \
148        program1_skip.html program2_fail.html  program2_skip.html \
149        program2_pass.html
150    do
151        test -f report.files/"${file}" || \
152            atf_fail "Expected file ${file} not found"
153    done
154
155    test report.html -ef report.files/index.html || \
156        atf_fail "Index file link not created properly"
157}
158
159
160atf_test_case html__other_directory
161html__other_directory_body() {
162    cat >Kyuafile <<EOF
163syntax('kyuafile', 1)
164EOF
165    atf_check -s exit:0 -o save:run.log -e ignore atf-run
166    mkdir -p a/b/c
167    atf_check -s exit:0 -o ignore -e empty \
168        atf-report -o html:$(pwd)/a/b/c/report.html <run.log
169
170    echo "All generated files"
171    ls -l a/b/c/*
172
173    for file in index.html context.html report.css; do
174        test -f a/b/c/report.files/"${file}" || \
175            atf_fail "Expected file ${file} not found"
176    done
177
178    test a/b/c/report.html -ef a/b/c/report.files/index.html || \
179        atf_fail "Index file link not created properly"
180}
181
182
183atf_test_case html__to_stdout
184html__to_stdout_body() {
185    atf_check -s exit:1 -o empty \
186        -e match:'E: Cannot write HTML reports to stdout' \
187        atf-report -o html:-
188    atf_check -s exit:1 -o empty \
189        -e match:'E: Cannot write HTML reports to stdout' \
190        atf-report -o html:/dev/stdout
191}
192
193
194atf_test_case xml_is_html
195xml_is_html_body() {
196    cat >Kyuafile <<EOF
197syntax('kyuafile', 1)
198EOF
199    atf_check -s exit:0 -o save:run.log -e ignore atf-run
200    atf_check -s exit:0 -o ignore \
201        -e match:'XML.*not supported.*generating HTML' \
202        atf-report -o xml:report.html <run.log
203
204    for file in index.html context.html report.css; do
205        test -f report.files/"${file}" || \
206            atf_fail "Expected file ${file} not found"
207    done
208
209    test report.html -ef report.files/index.html || \
210        atf_fail "Index file link not created properly"
211}
212
213
214atf_test_case unknown_option
215unknown_option_body() {
216    atf_check -s exit:1 -o empty -e match:'E: Unknown option -Z' \
217        atf-report -Z -A
218}
219
220
221atf_test_case too_many_arguments
222too_many_arguments_body() {
223    atf_check -s exit:1 -o empty -e match:'E: No arguments allowed' \
224        atf-report first
225}
226
227
228atf_test_case unknown_format
229unknown_format_body() {
230    atf_check -s exit:1 -o empty -e match:"E: Unknown output format 'csv'" \
231        atf-report -o csv:file.csv
232}
233
234
235atf_init_test_cases() {
236    atf_add_test_case ticker__no_tests
237    atf_add_test_case ticker__some_tests
238    atf_add_test_case ticker__explicit
239
240    atf_add_test_case html__no_tests
241    atf_add_test_case html__some_tests
242    atf_add_test_case html__other_directory
243    atf_add_test_case html__to_stdout
244
245    atf_add_test_case xml_is_html
246
247    atf_add_test_case unknown_option
248    atf_add_test_case too_many_arguments
249    atf_add_test_case unknown_format
250}
251