xref: /freebsd/lib/libxo/tests/functional_test.sh (revision 4436b51dff5736e74da464946049ea6899a88938)
1*4436b51dSEnji Cooper#
2*4436b51dSEnji Cooper# Copyright 2015 EMC Corp.
3*4436b51dSEnji Cooper# All rights reserved.
4*4436b51dSEnji Cooper#
5*4436b51dSEnji Cooper# Redistribution and use in source and binary forms, with or without
6*4436b51dSEnji Cooper# modification, are permitted provided that the following conditions are
7*4436b51dSEnji Cooper# met:
8*4436b51dSEnji Cooper#
9*4436b51dSEnji Cooper# * Redistributions of source code must retain the above copyright
10*4436b51dSEnji Cooper#   notice, this list of conditions and the following disclaimer.
11*4436b51dSEnji Cooper# * Redistributions in binary form must reproduce the above copyright
12*4436b51dSEnji Cooper#   notice, this list of conditions and the following disclaimer in the
13*4436b51dSEnji Cooper#   documentation and/or other materials provided with the distribution.
14*4436b51dSEnji Cooper#
15*4436b51dSEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16*4436b51dSEnji Cooper# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17*4436b51dSEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18*4436b51dSEnji Cooper# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19*4436b51dSEnji Cooper# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20*4436b51dSEnji Cooper# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21*4436b51dSEnji Cooper# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22*4436b51dSEnji Cooper# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23*4436b51dSEnji Cooper# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*4436b51dSEnji Cooper# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25*4436b51dSEnji Cooper# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*4436b51dSEnji Cooper#
27*4436b51dSEnji Cooper# $FreeBSD$
28*4436b51dSEnji Cooper
29*4436b51dSEnji CooperSRCDIR=$(atf_get_srcdir)
30*4436b51dSEnji Cooper
31*4436b51dSEnji Coopercheck()
32*4436b51dSEnji Cooper{
33*4436b51dSEnji Cooper	local tc=${1}; shift
34*4436b51dSEnji Cooper	local xo_fmt=${1}; shift
35*4436b51dSEnji Cooper
36*4436b51dSEnji Cooper	local err_file="${SRCDIR}/${tc}${xo_fmt:+.${xo_fmt}}.err"
37*4436b51dSEnji Cooper	[ -s "${err_file}" ] && err_flag="-e file:${err_file}"
38*4436b51dSEnji Cooper	local out_file="${SRCDIR}/${tc}${xo_fmt:+.${xo_fmt}}.out"
39*4436b51dSEnji Cooper	[ -s "${out_file}" ] && out_flag="-o file:${out_file}"
40*4436b51dSEnji Cooper
41*4436b51dSEnji Cooper	if [ "$xo_fmt" = "E" ]; then
42*4436b51dSEnji Cooper		LIBXO_OPTIONS="warn,encoder=test"
43*4436b51dSEnji Cooper	else
44*4436b51dSEnji Cooper		LIBXO_OPTIONS=":W${xo_fmt}"
45*4436b51dSEnji Cooper	fi
46*4436b51dSEnji Cooper
47*4436b51dSEnji Cooper	atf_check -s exit:0 -e file:${err_file} -o file:${out_file} \
48*4436b51dSEnji Cooper	    env LC_ALL=en_US.UTF-8 \
49*4436b51dSEnji Cooper	        LIBXO_OPTIONS="${LIBXO_OPTIONS}" TZ="EST" "${SRCDIR}/${tc}" \
50*4436b51dSEnji Cooper
51*4436b51dSEnji Cooper}
52*4436b51dSEnji Cooper
53*4436b51dSEnji Cooperadd_testcase()
54*4436b51dSEnji Cooper{
55*4436b51dSEnji Cooper	local tc=${1}
56*4436b51dSEnji Cooper	local tc_escaped
57*4436b51dSEnji Cooper
58*4436b51dSEnji Cooper	oldIFS=$IFS
59*4436b51dSEnji Cooper	IFS='.'
60*4436b51dSEnji Cooper	set -- $tc
61*4436b51dSEnji Cooper	tc_script=${1}
62*4436b51dSEnji Cooper	[ $# -eq 3 ] && xo_fmt=${2} # Don't set xo_fmt to `out'
63*4436b51dSEnji Cooper	IFS=$oldIFS
64*4436b51dSEnji Cooper	tc_escaped="${tc_script}${xo_fmt:+__${xo_fmt}}"
65*4436b51dSEnji Cooper
66*4436b51dSEnji Cooper	atf_test_case ${tc_escaped}
67*4436b51dSEnji Cooper	eval "${tc_escaped}_body() { check ${tc_script} ${xo_fmt}; }"
68*4436b51dSEnji Cooper	atf_add_test_case ${tc_escaped}
69*4436b51dSEnji Cooper}
70*4436b51dSEnji Cooper
71*4436b51dSEnji Cooperatf_init_test_cases()
72*4436b51dSEnji Cooper{
73*4436b51dSEnji Cooper	for path in $(find -Es "${SRCDIR}" -name '*.out'); do
74*4436b51dSEnji Cooper		add_testcase ${path##*/}
75*4436b51dSEnji Cooper	done
76*4436b51dSEnji Cooper}
77