1240116Smarcel#
2240116Smarcel# Automated Testing Framework (atf)
3240116Smarcel#
4240116Smarcel# Copyright (c) 2010 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
30240116Smarcelcreate_test_program() {
31240116Smarcel    echo '#! /usr/bin/env atf-sh' >"${1}"
32240116Smarcel    cat >>"${1}"
33240116Smarcel    chmod +x "${1}"
34240116Smarcel}
35240116Smarcel
36240116Smarcelatf_test_case no_args
37240116Smarcelno_args_body()
38240116Smarcel{
39240116Smarcel    cat >experr <<EOF
40240116Smarcelatf-sh: ERROR: No test program provided
41262855Sjmmvatf-sh: See atf-sh(1) for usage details.
42240116SmarcelEOF
43240116Smarcel    atf_check -s eq:1 -o ignore -e file:experr atf-sh
44240116Smarcel}
45240116Smarcel
46240116Smarcelatf_test_case missing_script
47240116Smarcelmissing_script_body()
48240116Smarcel{
49240116Smarcel    cat >experr <<EOF
50240116Smarcelatf-sh: ERROR: The test program 'non-existent' does not exist
51240116SmarcelEOF
52240116Smarcel    atf_check -s eq:1 -o ignore -e file:experr atf-sh non-existent
53240116Smarcel}
54240116Smarcel
55240116Smarcelatf_test_case arguments
56240116Smarcelarguments_body()
57240116Smarcel{
58240116Smarcel    create_test_program tp <<EOF
59240116Smarcelmain() {
60240116Smarcel    echo ">>>\${0}<<<"
61240116Smarcel    while test \${#} -gt 0; do
62240116Smarcel        echo ">>>\${1}<<<"
63240116Smarcel        shift
64240116Smarcel    done
65240116Smarcel    true
66240116Smarcel}
67240116SmarcelEOF
68240116Smarcel
69240116Smarcel    cat >expout <<EOF
70240116Smarcel>>>./tp<<<
71240116Smarcel>>> a b <<<
72240116Smarcel>>>foo<<<
73240116SmarcelEOF
74240116Smarcel    atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo
75240116Smarcel
76240116Smarcel    cat >expout <<EOF
77240116Smarcel>>>tp<<<
78240116Smarcel>>> hello bye <<<
79240116Smarcel>>>foo bar<<<
80240116SmarcelEOF
81240116Smarcel    atf_check -s eq:0 -o file:expout -e empty atf-sh tp ' hello bye ' 'foo bar'
82240116Smarcel}
83240116Smarcel
84240116Smarcelatf_init_test_cases()
85240116Smarcel{
86240116Smarcel    atf_add_test_case no_args
87240116Smarcel    atf_add_test_case missing_script
88240116Smarcel    atf_add_test_case arguments
89240116Smarcel}
90240116Smarcel
91240116Smarcel# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
92