Deleted Added
full compact
expect_test.sh (240120) expect_test.sh (273929)
1#
2# Automated Testing Framework (atf)
3#
4# Copyright (c) 2007 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1# Copyright (c) 2007 The NetBSD Foundation, Inc.
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
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10# notice, this list of conditions and the following disclaimer in the
11# documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30check_result() {
31 file="${1}"; shift
32
33 atf_check -s eq:0 -o match:"${*}" -e empty cat "${file}"
34 rm "${file}"
35}
36
37atf_test_case expect_pass
38expect_pass_body() {
39 for h in $(get_helpers); do
40 atf_check -s eq:0 -e ignore "${h}" -r result expect_pass_and_pass
41 check_result result "passed"
42
43 atf_check -s eq:1 -e ignore "${h}" -r result \
44 expect_pass_but_fail_requirement
45 check_result result "failed: Some reason"
46
47 # atf-sh does not support non-fatal failures yet; skip checks for
48 # such conditions.
49 case "${h}" in *sh_helpers*) continue ;; esac
50
51 atf_check -s eq:1 -o empty -e match:"Some reason" \
52 "${h}" -r result expect_pass_but_fail_check
53 check_result result "failed: 1 checks failed"
54 done
55}
56
57atf_test_case expect_fail
58expect_fail_body() {
59 for h in $(get_helpers c_helpers cpp_helpers); do
60 atf_check -s eq:0 "${h}" -r result expect_fail_and_fail_requirement
61 check_result result "expected_failure: Fail reason: The failure"
62
63 atf_check -s eq:1 -e match:"Expected check failure: Fail first: abc" \
64 -e not-match:"And fail again" "${h}" -r result expect_fail_but_pass
65 check_result result "failed: .*expecting a failure"
66
67 # atf-sh does not support non-fatal failures yet; skip checks for
68 # such conditions.
69 case "${h}" in *sh_helpers*) continue ;; esac
70
71 atf_check -s eq:0 -e match:"Expected check failure: Fail first: abc" \
72 -e match:"Expected check failure: And fail again: def" \
73 "${h}" -r result expect_fail_and_fail_check
74 check_result result "expected_failure: And fail again: 2 checks" \
75 "failed as expected"
76 done
77
78 # atf-sh does not support non-fatal failures yet; skip checks for
79 # such conditions.
80 for h in $(get_helpers sh_helpers); do
81 atf_check -s eq:0 -e ignore "${h}" -r result \
82 expect_fail_and_fail_requirement
83 check_result result "expected_failure: Fail reason: The failure"
84
85 atf_check -s eq:1 -e ignore "${h}" -r result expect_fail_but_pass
86 check_result result "failed: .*expecting a failure"
87 done
88}
89
90atf_test_case expect_exit
91expect_exit_body() {
92 for h in $(get_helpers); do
93 atf_check -s eq:0 -e ignore "${h}" -r result expect_exit_any_and_exit
94 check_result result "expected_exit: Call will exit"
95
96 atf_check -s eq:123 -e ignore "${h}" -r result expect_exit_code_and_exit
97 check_result result "expected_exit\(123\): Call will exit"
98
99 atf_check -s eq:1 -e ignore "${h}" -r result expect_exit_but_pass
100 check_result result "failed: .*expected to exit"
101 done
102}
103
104atf_test_case expect_signal
105expect_signal_body() {
106 for h in $(get_helpers); do
107 atf_check -s signal:9 -e ignore "${h}" -r result \
108 expect_signal_any_and_signal
109 check_result result "expected_signal: Call will signal"
110
111 atf_check -s signal:hup -e ignore "${h}" -r result \
112 expect_signal_no_and_signal
113 check_result result "expected_signal\(1\): Call will signal"
114
115 atf_check -s eq:1 -e ignore "${h}" -r result \
116 expect_signal_but_pass
117 check_result result "failed: .*termination signal"
118 done
119}
120
121atf_test_case expect_death
122expect_death_body() {
123 for h in $(get_helpers); do
124 atf_check -s eq:123 -e ignore "${h}" -r result expect_death_and_exit
125 check_result result "expected_death: Exit case"
126
127 atf_check -s signal:kill -e ignore "${h}" -r result \
128 expect_death_and_signal
129 check_result result "expected_death: Signal case"
130
131 atf_check -s eq:1 -e ignore "${h}" -r result expect_death_but_pass
132 check_result result "failed: .*terminate abruptly"
133 done
134}
135
136atf_test_case expect_timeout
137expect_timeout_body() {
138 for h in $(get_helpers); do
139 atf_check -s eq:1 -e ignore "${h}" -r result expect_timeout_but_pass
140 check_result result "failed: Test case was expected to hang but it" \
141 "continued execution"
142 done
143}
144
145atf_init_test_cases()
146{
147 atf_add_test_case expect_pass
148 atf_add_test_case expect_fail
149 atf_add_test_case expect_exit
150 atf_add_test_case expect_signal
151 atf_add_test_case expect_death
152 atf_add_test_case expect_timeout
153}
154
155# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
25
26check_result() {
27 file="${1}"; shift
28
29 atf_check -s eq:0 -o match:"${*}" -e empty cat "${file}"
30 rm "${file}"
31}
32
33atf_test_case expect_pass
34expect_pass_body() {
35 for h in $(get_helpers); do
36 atf_check -s eq:0 -e ignore "${h}" -r result expect_pass_and_pass
37 check_result result "passed"
38
39 atf_check -s eq:1 -e ignore "${h}" -r result \
40 expect_pass_but_fail_requirement
41 check_result result "failed: Some reason"
42
43 # atf-sh does not support non-fatal failures yet; skip checks for
44 # such conditions.
45 case "${h}" in *sh_helpers*) continue ;; esac
46
47 atf_check -s eq:1 -o empty -e match:"Some reason" \
48 "${h}" -r result expect_pass_but_fail_check
49 check_result result "failed: 1 checks failed"
50 done
51}
52
53atf_test_case expect_fail
54expect_fail_body() {
55 for h in $(get_helpers c_helpers cpp_helpers); do
56 atf_check -s eq:0 "${h}" -r result expect_fail_and_fail_requirement
57 check_result result "expected_failure: Fail reason: The failure"
58
59 atf_check -s eq:1 -e match:"Expected check failure: Fail first: abc" \
60 -e not-match:"And fail again" "${h}" -r result expect_fail_but_pass
61 check_result result "failed: .*expecting a failure"
62
63 # atf-sh does not support non-fatal failures yet; skip checks for
64 # such conditions.
65 case "${h}" in *sh_helpers*) continue ;; esac
66
67 atf_check -s eq:0 -e match:"Expected check failure: Fail first: abc" \
68 -e match:"Expected check failure: And fail again: def" \
69 "${h}" -r result expect_fail_and_fail_check
70 check_result result "expected_failure: And fail again: 2 checks" \
71 "failed as expected"
72 done
73
74 # atf-sh does not support non-fatal failures yet; skip checks for
75 # such conditions.
76 for h in $(get_helpers sh_helpers); do
77 atf_check -s eq:0 -e ignore "${h}" -r result \
78 expect_fail_and_fail_requirement
79 check_result result "expected_failure: Fail reason: The failure"
80
81 atf_check -s eq:1 -e ignore "${h}" -r result expect_fail_but_pass
82 check_result result "failed: .*expecting a failure"
83 done
84}
85
86atf_test_case expect_exit
87expect_exit_body() {
88 for h in $(get_helpers); do
89 atf_check -s eq:0 -e ignore "${h}" -r result expect_exit_any_and_exit
90 check_result result "expected_exit: Call will exit"
91
92 atf_check -s eq:123 -e ignore "${h}" -r result expect_exit_code_and_exit
93 check_result result "expected_exit\(123\): Call will exit"
94
95 atf_check -s eq:1 -e ignore "${h}" -r result expect_exit_but_pass
96 check_result result "failed: .*expected to exit"
97 done
98}
99
100atf_test_case expect_signal
101expect_signal_body() {
102 for h in $(get_helpers); do
103 atf_check -s signal:9 -e ignore "${h}" -r result \
104 expect_signal_any_and_signal
105 check_result result "expected_signal: Call will signal"
106
107 atf_check -s signal:hup -e ignore "${h}" -r result \
108 expect_signal_no_and_signal
109 check_result result "expected_signal\(1\): Call will signal"
110
111 atf_check -s eq:1 -e ignore "${h}" -r result \
112 expect_signal_but_pass
113 check_result result "failed: .*termination signal"
114 done
115}
116
117atf_test_case expect_death
118expect_death_body() {
119 for h in $(get_helpers); do
120 atf_check -s eq:123 -e ignore "${h}" -r result expect_death_and_exit
121 check_result result "expected_death: Exit case"
122
123 atf_check -s signal:kill -e ignore "${h}" -r result \
124 expect_death_and_signal
125 check_result result "expected_death: Signal case"
126
127 atf_check -s eq:1 -e ignore "${h}" -r result expect_death_but_pass
128 check_result result "failed: .*terminate abruptly"
129 done
130}
131
132atf_test_case expect_timeout
133expect_timeout_body() {
134 for h in $(get_helpers); do
135 atf_check -s eq:1 -e ignore "${h}" -r result expect_timeout_but_pass
136 check_result result "failed: Test case was expected to hang but it" \
137 "continued execution"
138 done
139}
140
141atf_init_test_cases()
142{
143 atf_add_test_case expect_pass
144 atf_add_test_case expect_fail
145 atf_add_test_case expect_exit
146 atf_add_test_case expect_signal
147 atf_add_test_case expect_death
148 atf_add_test_case expect_timeout
149}
150
151# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4