1*11be35a1SLionel Sambuc#! __ATF_SH__
2*11be35a1SLionel Sambuc# Copyright 2012 Google Inc.
3*11be35a1SLionel Sambuc# All rights reserved.
4*11be35a1SLionel Sambuc#
5*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without
6*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions are
7*11be35a1SLionel Sambuc# met:
8*11be35a1SLionel Sambuc#
9*11be35a1SLionel Sambuc# * Redistributions of source code must retain the above copyright
10*11be35a1SLionel Sambuc#   notice, this list of conditions and the following disclaimer.
11*11be35a1SLionel Sambuc# * Redistributions in binary form must reproduce the above copyright
12*11be35a1SLionel Sambuc#   notice, this list of conditions and the following disclaimer in the
13*11be35a1SLionel Sambuc#   documentation and/or other materials provided with the distribution.
14*11be35a1SLionel Sambuc# * Neither the name of Google Inc. nor the names of its contributors
15*11be35a1SLionel Sambuc#   may be used to endorse or promote products derived from this software
16*11be35a1SLionel Sambuc#   without specific prior written permission.
17*11be35a1SLionel Sambuc#
18*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*11be35a1SLionel Sambuc# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*11be35a1SLionel Sambuc# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21*11be35a1SLionel Sambuc# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22*11be35a1SLionel Sambuc# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23*11be35a1SLionel Sambuc# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24*11be35a1SLionel Sambuc# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*11be35a1SLionel Sambuc# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*11be35a1SLionel Sambuc# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*11be35a1SLionel Sambuc# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*11be35a1SLionel Sambuc# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*11be35a1SLionel Sambuc
30*11be35a1SLionel Sambuc
31*11be35a1SLionel Sambuc. "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/tests_lib.subr"
32*11be35a1SLionel Sambuc
33*11be35a1SLionel Sambuc
34*11be35a1SLionel Sambucatf_test_case ticker__no_tests
35*11be35a1SLionel Sambucticker__no_tests_body() {
36*11be35a1SLionel Sambuc    cat >Kyuafile <<EOF
37*11be35a1SLionel Sambucsyntax('kyuafile', 1)
38*11be35a1SLionel SambucEOF
39*11be35a1SLionel Sambuc
40*11be35a1SLionel Sambuc    atf_check -s exit:0 -o save:run.log -e ignore atf-run
41*11be35a1SLionel Sambuc
42*11be35a1SLionel Sambuc    cat >expout <<EOF
43*11be35a1SLionel Sambuc===> Summary
44*11be35a1SLionel SambucAction: 1
45*11be35a1SLionel SambucTest cases: 0 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
46*11be35a1SLionel SambucTotal time: X.XXXs
47*11be35a1SLionel SambucEOF
48*11be35a1SLionel Sambuc    atf_check -s exit:0 -o save:report.log -e empty atf-report <run.log
49*11be35a1SLionel Sambuc    strip_timestamps report.log
50*11be35a1SLionel Sambuc    atf_check -s exit:0 -o file:expout cat report.log
51*11be35a1SLionel Sambuc}
52*11be35a1SLionel Sambuc
53*11be35a1SLionel Sambuc
54*11be35a1SLionel Sambucatf_test_case ticker__some_tests
55*11be35a1SLionel Sambucticker__some_tests_body() {
56*11be35a1SLionel Sambuc    create_test_program program1 skip
57*11be35a1SLionel Sambuc    create_test_program program2 fail skip pass
58*11be35a1SLionel Sambuc    cat >Kyuafile <<EOF
59*11be35a1SLionel Sambucsyntax('kyuafile', 1)
60*11be35a1SLionel Sambuctest_suite('foo')
61*11be35a1SLionel Sambucatf_test_program{name='program1'}
62*11be35a1SLionel Sambucatf_test_program{name='program2'}
63*11be35a1SLionel SambucEOF
64*11be35a1SLionel Sambuc    atf_check -s exit:1 -o save:run.log -e ignore atf-run
65*11be35a1SLionel Sambuc
66*11be35a1SLionel Sambuc    cat >expout <<EOF
67*11be35a1SLionel Sambucprogram1:skip  ->  skipped: Skipped reason  [X.XXXs]
68*11be35a1SLionel Sambucprogram2:fail  ->  failed: On purpose  [X.XXXs]
69*11be35a1SLionel Sambucprogram2:skip  ->  skipped: Skipped reason  [X.XXXs]
70*11be35a1SLionel Sambucprogram2:pass  ->  passed  [X.XXXs]
71*11be35a1SLionel Sambuc===> Skipped tests
72*11be35a1SLionel Sambucprogram1:skip  ->  skipped: Skipped reason  [X.XXXs]
73*11be35a1SLionel Sambucprogram2:skip  ->  skipped: Skipped reason  [X.XXXs]
74*11be35a1SLionel Sambuc===> Failed tests
75*11be35a1SLionel Sambucprogram2:fail  ->  failed: On purpose  [X.XXXs]
76*11be35a1SLionel Sambuc===> Summary
77*11be35a1SLionel SambucAction: 1
78*11be35a1SLionel SambucTest cases: 4 total, 2 skipped, 0 expected failures, 0 broken, 1 failed
79*11be35a1SLionel SambucTotal time: X.XXXs
80*11be35a1SLionel SambucEOF
81*11be35a1SLionel Sambuc    atf_check -s exit:0 -o save:report.log -e empty atf-report <run.log
82*11be35a1SLionel Sambuc    strip_timestamps report.log
83*11be35a1SLionel Sambuc    atf_check -s exit:0 -o file:expout cat report.log
84*11be35a1SLionel Sambuc}
85*11be35a1SLionel Sambuc
86*11be35a1SLionel Sambuc
87*11be35a1SLionel Sambucatf_test_case ticker__explicit
88*11be35a1SLionel Sambucticker__explicit_body() {
89*11be35a1SLionel Sambuc    cat >Kyuafile <<EOF
90*11be35a1SLionel Sambucsyntax('kyuafile', 1)
91*11be35a1SLionel SambucEOF
92*11be35a1SLionel Sambuc
93*11be35a1SLionel Sambuc    atf_check -s exit:0 -o save:run.log -e ignore atf-run
94*11be35a1SLionel Sambuc
95*11be35a1SLionel Sambuc    cat >expout <<EOF
96*11be35a1SLionel Sambuc===> Summary
97*11be35a1SLionel SambucAction: 1
98*11be35a1SLionel SambucTest cases: 0 total, 0 skipped, 0 expected failures, 0 broken, 0 failed
99*11be35a1SLionel SambucTotal time: X.XXXs
100*11be35a1SLionel SambucEOF
101*11be35a1SLionel Sambuc    atf_check -s exit:0 -o empty -e empty \
102*11be35a1SLionel Sambuc        atf-report -o ticker:my-report.log <run.log
103*11be35a1SLionel Sambuc    strip_timestamps my-report.log
104*11be35a1SLionel Sambuc    atf_check -s exit:0 -o file:expout cat my-report.log
105*11be35a1SLionel Sambuc}
106*11be35a1SLionel Sambuc
107*11be35a1SLionel Sambuc
108*11be35a1SLionel Sambucatf_test_case html__no_tests
109*11be35a1SLionel Sambuchtml__no_tests_body() {
110*11be35a1SLionel Sambuc    cat >Kyuafile <<EOF
111*11be35a1SLionel Sambucsyntax('kyuafile', 1)
112*11be35a1SLionel SambucEOF
113*11be35a1SLionel Sambuc    atf_check -s exit:0 -o save:run.log -e ignore atf-run
114*11be35a1SLionel Sambuc    atf_check -s exit:0 -o ignore -e empty \
115*11be35a1SLionel Sambuc        atf-report -o html:report.html <run.log
116*11be35a1SLionel Sambuc
117*11be35a1SLionel Sambuc    echo "All generated files"
118*11be35a1SLionel Sambuc    ls -l report.html report.files
119*11be35a1SLionel Sambuc
120*11be35a1SLionel Sambuc    for file in index.html context.html report.css; do
121*11be35a1SLionel Sambuc        test -f report.files/"${file}" || \
122*11be35a1SLionel Sambuc            atf_fail "Expected file ${file} not found"
123*11be35a1SLionel Sambuc    done
124*11be35a1SLionel Sambuc
125*11be35a1SLionel Sambuc    test report.html -ef report.files/index.html || \
126*11be35a1SLionel Sambuc        atf_fail "Index file link not created properly"
127*11be35a1SLionel Sambuc}
128*11be35a1SLionel Sambuc
129*11be35a1SLionel Sambuc
130*11be35a1SLionel Sambucatf_test_case html__some_tests
131*11be35a1SLionel Sambuchtml__some_tests_body() {
132*11be35a1SLionel Sambuc    create_test_program program1 skip
133*11be35a1SLionel Sambuc    create_test_program program2 fail skip pass
134*11be35a1SLionel Sambuc    cat >Kyuafile <<EOF
135*11be35a1SLionel Sambucsyntax('kyuafile', 1)
136*11be35a1SLionel Sambuctest_suite('foo')
137*11be35a1SLionel Sambucatf_test_program{name='program1'}
138*11be35a1SLionel Sambucatf_test_program{name='program2'}
139*11be35a1SLionel SambucEOF
140*11be35a1SLionel Sambuc    atf_check -s exit:1 -o save:run.log -e ignore atf-run
141*11be35a1SLionel Sambuc    atf_check -s exit:0 -o ignore -e empty \
142*11be35a1SLionel Sambuc        atf-report -o html:report.html <run.log
143*11be35a1SLionel Sambuc
144*11be35a1SLionel Sambuc    echo "All generated files"
145*11be35a1SLionel Sambuc    ls -l report.html report.files
146*11be35a1SLionel Sambuc
147*11be35a1SLionel Sambuc    for file in index.html context.html report.css \
148*11be35a1SLionel Sambuc        program1_skip.html program2_fail.html  program2_skip.html \
149*11be35a1SLionel Sambuc        program2_pass.html
150*11be35a1SLionel Sambuc    do
151*11be35a1SLionel Sambuc        test -f report.files/"${file}" || \
152*11be35a1SLionel Sambuc            atf_fail "Expected file ${file} not found"
153*11be35a1SLionel Sambuc    done
154*11be35a1SLionel Sambuc
155*11be35a1SLionel Sambuc    test report.html -ef report.files/index.html || \
156*11be35a1SLionel Sambuc        atf_fail "Index file link not created properly"
157*11be35a1SLionel Sambuc}
158*11be35a1SLionel Sambuc
159*11be35a1SLionel Sambuc
160*11be35a1SLionel Sambucatf_test_case html__other_directory
161*11be35a1SLionel Sambuchtml__other_directory_body() {
162*11be35a1SLionel Sambuc    cat >Kyuafile <<EOF
163*11be35a1SLionel Sambucsyntax('kyuafile', 1)
164*11be35a1SLionel SambucEOF
165*11be35a1SLionel Sambuc    atf_check -s exit:0 -o save:run.log -e ignore atf-run
166*11be35a1SLionel Sambuc    mkdir -p a/b/c
167*11be35a1SLionel Sambuc    atf_check -s exit:0 -o ignore -e empty \
168*11be35a1SLionel Sambuc        atf-report -o html:$(pwd)/a/b/c/report.html <run.log
169*11be35a1SLionel Sambuc
170*11be35a1SLionel Sambuc    echo "All generated files"
171*11be35a1SLionel Sambuc    ls -l a/b/c/*
172*11be35a1SLionel Sambuc
173*11be35a1SLionel Sambuc    for file in index.html context.html report.css; do
174*11be35a1SLionel Sambuc        test -f a/b/c/report.files/"${file}" || \
175*11be35a1SLionel Sambuc            atf_fail "Expected file ${file} not found"
176*11be35a1SLionel Sambuc    done
177*11be35a1SLionel Sambuc
178*11be35a1SLionel Sambuc    test a/b/c/report.html -ef a/b/c/report.files/index.html || \
179*11be35a1SLionel Sambuc        atf_fail "Index file link not created properly"
180*11be35a1SLionel Sambuc}
181*11be35a1SLionel Sambuc
182*11be35a1SLionel Sambuc
183*11be35a1SLionel Sambucatf_test_case html__to_stdout
184*11be35a1SLionel Sambuchtml__to_stdout_body() {
185*11be35a1SLionel Sambuc    atf_check -s exit:1 -o empty \
186*11be35a1SLionel Sambuc        -e match:'E: Cannot write HTML reports to stdout' \
187*11be35a1SLionel Sambuc        atf-report -o html:-
188*11be35a1SLionel Sambuc    atf_check -s exit:1 -o empty \
189*11be35a1SLionel Sambuc        -e match:'E: Cannot write HTML reports to stdout' \
190*11be35a1SLionel Sambuc        atf-report -o html:/dev/stdout
191*11be35a1SLionel Sambuc}
192*11be35a1SLionel Sambuc
193*11be35a1SLionel Sambuc
194*11be35a1SLionel Sambucatf_test_case xml_is_html
195*11be35a1SLionel Sambucxml_is_html_body() {
196*11be35a1SLionel Sambuc    cat >Kyuafile <<EOF
197*11be35a1SLionel Sambucsyntax('kyuafile', 1)
198*11be35a1SLionel SambucEOF
199*11be35a1SLionel Sambuc    atf_check -s exit:0 -o save:run.log -e ignore atf-run
200*11be35a1SLionel Sambuc    atf_check -s exit:0 -o ignore \
201*11be35a1SLionel Sambuc        -e match:'XML.*not supported.*generating HTML' \
202*11be35a1SLionel Sambuc        atf-report -o xml:report.html <run.log
203*11be35a1SLionel Sambuc
204*11be35a1SLionel Sambuc    for file in index.html context.html report.css; do
205*11be35a1SLionel Sambuc        test -f report.files/"${file}" || \
206*11be35a1SLionel Sambuc            atf_fail "Expected file ${file} not found"
207*11be35a1SLionel Sambuc    done
208*11be35a1SLionel Sambuc
209*11be35a1SLionel Sambuc    test report.html -ef report.files/index.html || \
210*11be35a1SLionel Sambuc        atf_fail "Index file link not created properly"
211*11be35a1SLionel Sambuc}
212*11be35a1SLionel Sambuc
213*11be35a1SLionel Sambuc
214*11be35a1SLionel Sambucatf_test_case unknown_option
215*11be35a1SLionel Sambucunknown_option_body() {
216*11be35a1SLionel Sambuc    atf_check -s exit:1 -o empty -e match:'E: Unknown option -Z' \
217*11be35a1SLionel Sambuc        atf-report -Z -A
218*11be35a1SLionel Sambuc}
219*11be35a1SLionel Sambuc
220*11be35a1SLionel Sambuc
221*11be35a1SLionel Sambucatf_test_case too_many_arguments
222*11be35a1SLionel Sambuctoo_many_arguments_body() {
223*11be35a1SLionel Sambuc    atf_check -s exit:1 -o empty -e match:'E: No arguments allowed' \
224*11be35a1SLionel Sambuc        atf-report first
225*11be35a1SLionel Sambuc}
226*11be35a1SLionel Sambuc
227*11be35a1SLionel Sambuc
228*11be35a1SLionel Sambucatf_test_case unknown_format
229*11be35a1SLionel Sambucunknown_format_body() {
230*11be35a1SLionel Sambuc    atf_check -s exit:1 -o empty -e match:"E: Unknown output format 'csv'" \
231*11be35a1SLionel Sambuc        atf-report -o csv:file.csv
232*11be35a1SLionel Sambuc}
233*11be35a1SLionel Sambuc
234*11be35a1SLionel Sambuc
235*11be35a1SLionel Sambucatf_init_test_cases() {
236*11be35a1SLionel Sambuc    atf_add_test_case ticker__no_tests
237*11be35a1SLionel Sambuc    atf_add_test_case ticker__some_tests
238*11be35a1SLionel Sambuc    atf_add_test_case ticker__explicit
239*11be35a1SLionel Sambuc
240*11be35a1SLionel Sambuc    atf_add_test_case html__no_tests
241*11be35a1SLionel Sambuc    atf_add_test_case html__some_tests
242*11be35a1SLionel Sambuc    atf_add_test_case html__other_directory
243*11be35a1SLionel Sambuc    atf_add_test_case html__to_stdout
244*11be35a1SLionel Sambuc
245*11be35a1SLionel Sambuc    atf_add_test_case xml_is_html
246*11be35a1SLionel Sambuc
247*11be35a1SLionel Sambuc    atf_add_test_case unknown_option
248*11be35a1SLionel Sambuc    atf_add_test_case too_many_arguments
249*11be35a1SLionel Sambuc    atf_add_test_case unknown_format
250*11be35a1SLionel Sambuc}
251