xref: /freebsd/usr.bin/awk/tests/bugs-fixed/bug_fix_test.sh (revision ba7b7f94c239ce43343d7af403734fdc941b7664)
1517e52b6SWarner Losh#
2517e52b6SWarner Losh# Copyright 2014 EMC Corp.
3517e52b6SWarner Losh# All rights reserved.
4517e52b6SWarner Losh#
5517e52b6SWarner Losh# Redistribution and use in source and binary forms, with or without
6517e52b6SWarner Losh# modification, are permitted provided that the following conditions are
7517e52b6SWarner Losh# met:
8517e52b6SWarner Losh#
9517e52b6SWarner Losh# * Redistributions of source code must retain the above copyright
10517e52b6SWarner Losh#   notice, this list of conditions and the following disclaimer.
11517e52b6SWarner Losh# * Redistributions in binary form must reproduce the above copyright
12517e52b6SWarner Losh#   notice, this list of conditions and the following disclaimer in the
13517e52b6SWarner Losh#   documentation and/or other materials provided with the distribution.
14517e52b6SWarner Losh#
15517e52b6SWarner Losh# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16517e52b6SWarner Losh# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17517e52b6SWarner Losh# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18517e52b6SWarner Losh# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19517e52b6SWarner Losh# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20517e52b6SWarner Losh# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21517e52b6SWarner Losh# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22517e52b6SWarner Losh# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23517e52b6SWarner Losh# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24517e52b6SWarner Losh# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25517e52b6SWarner Losh# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26517e52b6SWarner Losh#
27517e52b6SWarner Losh
28*ba7b7f94SWarner Loshexport LANG=C.UTF-8
29517e52b6SWarner LoshSRCDIR=$(atf_get_srcdir)
30517e52b6SWarner Losh
31517e52b6SWarner Loshcheck()
32517e52b6SWarner Losh{
33517e52b6SWarner Losh	local tc=${1%.awk}; shift
34517e52b6SWarner Losh	local in_flag out_flag err_flag
35517e52b6SWarner Losh
36517e52b6SWarner Losh	awk=awk
37517e52b6SWarner Losh
38517e52b6SWarner Losh	local out_file="${SRCDIR}/${tc}.ok"
39517e52b6SWarner Losh	[ -f "${out_file}" ] && out_flag="-o file:${out_file}"
40517e52b6SWarner Losh	local err_file="${SRCDIR}/${tc}.err"
41517e52b6SWarner Losh	[ -f "${err_file}" ] && err_flag="-e file:${err_file} -s exit:2"
42517e52b6SWarner Losh	local in_file="${SRCDIR}/${tc}.in"
43517e52b6SWarner Losh	[ -f "${in_file}" ] && in_flag="${in_file}"
44517e52b6SWarner Losh
45517e52b6SWarner Losh	(cd ${SRCDIR} ; atf_check ${out_flag} ${err_flag} ${awk} -f "${tc}.awk" ${in_flag})
46517e52b6SWarner Losh}
47517e52b6SWarner Losh
48517e52b6SWarner Loshadd_testcase()
49517e52b6SWarner Losh{
50517e52b6SWarner Losh	local tc=${1%.awk}
51517e52b6SWarner Losh	local tc_escaped word
52517e52b6SWarner Losh
53517e52b6SWarner Losh	case "${tc%.*}" in
54517e52b6SWarner Losh	*-*)
55517e52b6SWarner Losh		local IFS="-"
56517e52b6SWarner Losh		for word in ${tc}; do
57517e52b6SWarner Losh			tc_escaped="${tc_escaped:+${tc_escaped}_}${word}"
58517e52b6SWarner Losh		done
59517e52b6SWarner Losh		;;
60517e52b6SWarner Losh	*)
61517e52b6SWarner Losh		tc_escaped=${tc}
62517e52b6SWarner Losh		;;
63517e52b6SWarner Losh	esac
64517e52b6SWarner Losh
65517e52b6SWarner Losh	atf_test_case ${tc_escaped}
66517e52b6SWarner Losh	eval "${tc_escaped}_body() { check ${tc}; }"
67517e52b6SWarner Losh	atf_add_test_case ${tc_escaped}
68517e52b6SWarner Losh}
69517e52b6SWarner Losh
70517e52b6SWarner Loshatf_init_test_cases()
71517e52b6SWarner Losh{
72517e52b6SWarner Losh	for path in $(find -s "${SRCDIR}" -name '*.awk'); do
73517e52b6SWarner Losh		add_testcase ${path##*/}
74517e52b6SWarner Losh	done
75517e52b6SWarner Losh}
76