111be35a1SLionel Sambuc# 211be35a1SLionel Sambuc# Automated Testing Framework (atf) 311be35a1SLionel Sambuc# 411be35a1SLionel Sambuc# Copyright (c) 2010 The NetBSD Foundation, Inc. 511be35a1SLionel Sambuc# All rights reserved. 611be35a1SLionel Sambuc# 711be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 811be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 911be35a1SLionel Sambuc# are met: 1011be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 1111be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 1211be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 1311be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 1411be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 1511be35a1SLionel Sambuc# 1611be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 1711be35a1SLionel Sambuc# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 1811be35a1SLionel Sambuc# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1911be35a1SLionel Sambuc# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2011be35a1SLionel Sambuc# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 2111be35a1SLionel Sambuc# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2211be35a1SLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 2311be35a1SLionel Sambuc# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2411be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2511be35a1SLionel Sambuc# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2611be35a1SLionel Sambuc# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2711be35a1SLionel Sambuc# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2811be35a1SLionel Sambuc# 2911be35a1SLionel Sambuc 3011be35a1SLionel Sambuccreate_test_program() { 3111be35a1SLionel Sambuc echo '#! /usr/bin/env atf-sh' >"${1}" 3211be35a1SLionel Sambuc cat >>"${1}" 3311be35a1SLionel Sambuc chmod +x "${1}" 3411be35a1SLionel Sambuc} 3511be35a1SLionel Sambuc 3611be35a1SLionel Sambucatf_test_case no_args 3711be35a1SLionel Sambucno_args_body() 3811be35a1SLionel Sambuc{ 3911be35a1SLionel Sambuc cat >experr <<EOF 4011be35a1SLionel Sambucatf-sh: ERROR: No test program provided 41*0a6a1f1dSLionel Sambucatf-sh: See atf-sh(1) for usage details. 4211be35a1SLionel SambucEOF 4311be35a1SLionel Sambuc atf_check -s eq:1 -o ignore -e file:experr atf-sh 4411be35a1SLionel Sambuc} 4511be35a1SLionel Sambuc 4611be35a1SLionel Sambucatf_test_case missing_script 4711be35a1SLionel Sambucmissing_script_body() 4811be35a1SLionel Sambuc{ 4911be35a1SLionel Sambuc cat >experr <<EOF 5011be35a1SLionel Sambucatf-sh: ERROR: The test program 'non-existent' does not exist 5111be35a1SLionel SambucEOF 5211be35a1SLionel Sambuc atf_check -s eq:1 -o ignore -e file:experr atf-sh non-existent 5311be35a1SLionel Sambuc} 5411be35a1SLionel Sambuc 5511be35a1SLionel Sambucatf_test_case arguments 5611be35a1SLionel Sambucarguments_body() 5711be35a1SLionel Sambuc{ 5811be35a1SLionel Sambuc create_test_program tp <<EOF 5911be35a1SLionel Sambucmain() { 6011be35a1SLionel Sambuc echo ">>>\${0}<<<" 6111be35a1SLionel Sambuc while test \${#} -gt 0; do 6211be35a1SLionel Sambuc echo ">>>\${1}<<<" 6311be35a1SLionel Sambuc shift 6411be35a1SLionel Sambuc done 6511be35a1SLionel Sambuc true 6611be35a1SLionel Sambuc} 6711be35a1SLionel SambucEOF 6811be35a1SLionel Sambuc 6911be35a1SLionel Sambuc cat >expout <<EOF 7011be35a1SLionel Sambuc>>>./tp<<< 7111be35a1SLionel Sambuc>>> a b <<< 7211be35a1SLionel Sambuc>>>foo<<< 7311be35a1SLionel SambucEOF 7411be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./tp ' a b ' foo 7511be35a1SLionel Sambuc 7611be35a1SLionel Sambuc cat >expout <<EOF 7711be35a1SLionel Sambuc>>>tp<<< 7811be35a1SLionel Sambuc>>> hello bye <<< 7911be35a1SLionel Sambuc>>>foo bar<<< 8011be35a1SLionel SambucEOF 8111be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty atf-sh tp ' hello bye ' 'foo bar' 8211be35a1SLionel Sambuc} 8311be35a1SLionel Sambuc 8411be35a1SLionel Sambucatf_init_test_cases() 8511be35a1SLionel Sambuc{ 8611be35a1SLionel Sambuc atf_add_test_case no_args 8711be35a1SLionel Sambuc atf_add_test_case missing_script 8811be35a1SLionel Sambuc atf_add_test_case arguments 8911be35a1SLionel Sambuc} 9011be35a1SLionel Sambuc 9111be35a1SLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4 92