1269902Sngie#
2269902Sngie# Copyright 2014 EMC Corp.
3269902Sngie# All rights reserved.
4269902Sngie#
5269902Sngie# Redistribution and use in source and binary forms, with or without
6269902Sngie# modification, are permitted provided that the following conditions are
7269902Sngie# met:
8269902Sngie#
9269902Sngie# * Redistributions of source code must retain the above copyright
10269902Sngie#   notice, this list of conditions and the following disclaimer.
11269902Sngie# * Redistributions in binary form must reproduce the above copyright
12269902Sngie#   notice, this list of conditions and the following disclaimer in the
13269902Sngie#   documentation and/or other materials provided with the distribution.
14269902Sngie#
15269902Sngie# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16269902Sngie# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17269902Sngie# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18269902Sngie# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19269902Sngie# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20269902Sngie# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21269902Sngie# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22269902Sngie# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23269902Sngie# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24269902Sngie# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25269902Sngie# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26269902Sngie#
27269902Sngie# $FreeBSD: releng/11.0/bin/sh/tests/functional_test.sh 270101 2014-08-17 14:26:12Z jilles $
28269902Sngie
29269902SngieSRCDIR=$(atf_get_srcdir)
30269902Sngie
31269902Sngiecheck()
32269902Sngie{
33269902Sngie	local tc=${1}; shift
34269902Sngie
35269902Sngie	export SH=$(atf_config_get bin.sh.test_shell /bin/sh)
36269902Sngie
37269902Sngie	local err_file="${SRCDIR}/${tc}.stderr"
38269902Sngie	[ -f "${err_file}" ] && err_flag="-e file:${err_file}"
39269902Sngie	local out_file="${SRCDIR}/${tc}.stdout"
40269902Sngie	[ -f "${out_file}" ] && out_flag="-o file:${out_file}"
41269902Sngie
42270101Sjilles	atf_check -s exit:${tc##*.} ${err_flag} ${out_flag} ${SH} "${SRCDIR}/${tc}"
43269902Sngie}
44269902Sngie
45269902Sngieadd_testcase()
46269902Sngie{
47269902Sngie	local tc=${1}
48269902Sngie	local tc_escaped word
49269902Sngie
50269902Sngie	case "${tc%.*}" in
51269902Sngie	*-*)
52269902Sngie		local IFS="-"
53269902Sngie		for word in ${tc%.*}; do
54269902Sngie			tc_escaped="${tc_escaped:+${tc_escaped}_}${word}"
55269902Sngie		done
56269902Sngie		;;
57269902Sngie	*)
58269902Sngie		tc_escaped=${tc%.*}
59269902Sngie		;;
60269902Sngie	esac
61269902Sngie
62269902Sngie	atf_test_case ${tc_escaped}
63269902Sngie	eval "${tc_escaped}_body() { check ${tc}; }"
64269902Sngie	atf_add_test_case ${tc_escaped}
65269902Sngie}
66269902Sngie
67269902Sngieatf_init_test_cases()
68269902Sngie{
69269902Sngie	for path in $(find -Es "${SRCDIR}" -regex '.*\.[0-9]+$'); do
70269902Sngie		add_testcase ${path##*/}
71269902Sngie	done
72269902Sngie}
73