1240116Smarcel#
2240116Smarcel# Automated Testing Framework (atf)
3240116Smarcel#
4240116Smarcel# Copyright (c) 2007 The NetBSD Foundation, Inc.
5240116Smarcel# All rights reserved.
6240116Smarcel#
7240116Smarcel# Redistribution and use in source and binary forms, with or without
8240116Smarcel# modification, are permitted provided that the following conditions
9240116Smarcel# are met:
10240116Smarcel# 1. Redistributions of source code must retain the above copyright
11240116Smarcel#    notice, this list of conditions and the following disclaimer.
12240116Smarcel# 2. Redistributions in binary form must reproduce the above copyright
13240116Smarcel#    notice, this list of conditions and the following disclaimer in the
14240116Smarcel#    documentation and/or other materials provided with the distribution.
15240116Smarcel#
16240116Smarcel# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17240116Smarcel# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18240116Smarcel# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19240116Smarcel# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20240116Smarcel# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21240116Smarcel# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22240116Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23240116Smarcel# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24240116Smarcel# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25240116Smarcel# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26240116Smarcel# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27240116Smarcel# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28240116Smarcel#
29240116Smarcel
30240116Smarcelatf_test_case atf_run_warnings
31240116Smarcelatf_run_warnings_head()
32240116Smarcel{
33240116Smarcel    # The fact that this test case is in this test program is an abuse.
34240116Smarcel    atf_set "descr" "Tests that the test case prints a warning because" \
35240116Smarcel                    "it is not being run by atf-run"
36240116Smarcel}
37240116Smarcelatf_run_warnings_body()
38240116Smarcel{
39240116Smarcel    unset __RUNNING_INSIDE_ATF_RUN
40240116Smarcel    srcdir="$(atf_get_srcdir)"
41240116Smarcel    for h in $(get_helpers); do
42240116Smarcel        atf_check -s eq:0 -o match:"passed" -e match:"WARNING.*atf-run" \
43240116Smarcel            "${h}" -s "${srcdir}" result_pass
44240116Smarcel    done
45240116Smarcel}
46240116Smarcel
47240116Smarcelatf_test_case result_on_stdout
48240116Smarcelresult_on_stdout_head()
49240116Smarcel{
50240116Smarcel    atf_set "descr" "Tests that the test case result is printed on stdout" \
51240116Smarcel                    "by default"
52240116Smarcel}
53240116Smarcelresult_on_stdout_body()
54240116Smarcel{
55240116Smarcel    srcdir="$(atf_get_srcdir)"
56240116Smarcel    for h in $(get_helpers); do
57240116Smarcel        atf_check -s eq:0 -o match:"passed" -o match:"msg" \
58240116Smarcel            -e ignore "${h}" -s "${srcdir}" result_pass
59240116Smarcel        atf_check -s eq:1 -o match:"failed: Failure reason" -o match:"msg" \
60240116Smarcel            -e ignore "${h}" -s "${srcdir}" result_fail
61240116Smarcel        atf_check -s eq:0 -o match:"skipped: Skipped reason" -o match:"msg" \
62240116Smarcel            -e ignore "${h}" -s "${srcdir}" result_skip
63240116Smarcel    done
64240116Smarcel}
65240116Smarcel
66240116Smarcelatf_test_case result_to_file
67240116Smarcelresult_to_file_head()
68240116Smarcel{
69240116Smarcel    atf_set "descr" "Tests that the test case result is sent to a file if -r" \
70240116Smarcel                    "is used"
71240116Smarcel}
72240116Smarcelresult_to_file_body()
73240116Smarcel{
74240116Smarcel    srcdir="$(atf_get_srcdir)"
75240116Smarcel    for h in $(get_helpers); do
76240116Smarcel        atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
77240116Smarcel            -r resfile result_pass
78240116Smarcel        atf_check -o inline:"passed\n" cat resfile
79240116Smarcel
80240116Smarcel        atf_check -s eq:1 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
81240116Smarcel            -r resfile result_fail
82240116Smarcel        atf_check -o inline:"failed: Failure reason\n" cat resfile
83240116Smarcel
84240116Smarcel        atf_check -s eq:0 -o inline:"msg\n" -e ignore "${h}" -s "${srcdir}" \
85240116Smarcel            -r resfile result_skip
86240116Smarcel        atf_check -o inline:"skipped: Skipped reason\n" cat resfile
87240116Smarcel    done
88240116Smarcel}
89240116Smarcel
90240116Smarcelatf_test_case result_to_file_fail
91240116Smarcelresult_to_file_fail_head()
92240116Smarcel{
93240116Smarcel    atf_set "descr" "Tests controlled failure if the test program fails to" \
94240116Smarcel        "create the results file"
95240116Smarcel    atf_set "require.user" "unprivileged"
96240116Smarcel}
97240116Smarcelresult_to_file_fail_body()
98240116Smarcel{
99240116Smarcel    mkdir dir
100240116Smarcel    chmod 444 dir
101240116Smarcel
102240116Smarcel    srcdir="$(atf_get_srcdir)"
103240116Smarcel
104240116Smarcel    for h in $(get_helpers c_helpers cpp_helpers); do
105240116Smarcel        atf_check -s signal -o ignore \
106240116Smarcel            -e match:"FATAL ERROR: Cannot create.*'dir/resfile'" \
107240116Smarcel            "${h}" -s "${srcdir}" -r dir/resfile result_pass
108240116Smarcel    done
109240116Smarcel
110240116Smarcel    for h in $(get_helpers sh_helpers); do
111240116Smarcel        atf_check -s exit -o ignore \
112240116Smarcel            -e match:"ERROR: Cannot create.*'dir/resfile'" \
113240116Smarcel            "${h}" -s "${srcdir}" -r dir/resfile result_pass
114240116Smarcel    done
115240116Smarcel}
116240116Smarcel
117240116Smarcelatf_test_case result_exception
118240116Smarcelresult_exception_head()
119240116Smarcel{
120240116Smarcel    atf_set "descr" "Tests that an unhandled exception is correctly captured"
121240116Smarcel}
122240116Smarcelresult_exception_body()
123240116Smarcel{
124240116Smarcel    for h in $(get_helpers cpp_helpers); do
125240116Smarcel        atf_check -s exit:1 -o match:'failed: .*This is unhandled' \
126240116Smarcel            "${h}" -s "${srcdir}" result_exception
127240116Smarcel    done
128240116Smarcel}
129240116Smarcel
130240116Smarcelatf_init_test_cases()
131240116Smarcel{
132240116Smarcel    atf_add_test_case atf_run_warnings
133240116Smarcel    atf_add_test_case result_on_stdout
134240116Smarcel    atf_add_test_case result_to_file
135240116Smarcel    atf_add_test_case result_to_file_fail
136240116Smarcel    atf_add_test_case result_exception
137240116Smarcel}
138240116Smarcel
139240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
140