1269902Sngie# 2288929Sngie# Copyright 2015 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: stable/11/usr.bin/xo/tests/functional_test.sh 322172 2017-08-07 17:23:44Z phil $ 28269902Sngie 29269902SngieSRCDIR=$(atf_get_srcdir) 30269902Sngie 31269902Sngiecheck() 32269902Sngie{ 33269902Sngie local tc=${1}; shift 34288929Sngie local xo_fmt=${1}; shift 35269902Sngie 36288929Sngie XO=$(atf_config_get usr.bin.xo.test_xo /usr/bin/xo) 37269902Sngie 38288929Sngie local err_file="${SRCDIR}/${tc}${xo_fmt:+.${xo_fmt}}.err" 39288929Sngie [ -s "${err_file}" ] && err_flag="-e file:${err_file}" 40288929Sngie local out_file="${SRCDIR}/${tc}${xo_fmt:+.${xo_fmt}}.out" 41288929Sngie [ -s "${out_file}" ] && out_flag="-o file:${out_file}" 42269902Sngie 43288929Sngie atf_check -s exit:0 -e file:${err_file} -o file:${out_file} \ 44288929Sngie env LC_ALL=en_US.UTF-8 \ 45322172Sphil TZ="EST" "${SRCDIR}/${tc}" \ 46322172Sphil "${XO} --libxo:W${xo_fmt}" 47269902Sngie} 48269902Sngie 49269902Sngieadd_testcase() 50269902Sngie{ 51269902Sngie local tc=${1} 52288929Sngie local tc_escaped 53269902Sngie 54288929Sngie oldIFS=$IFS 55288929Sngie IFS='.' 56288929Sngie set -- $tc 57288929Sngie tc_script=${1} 58288929Sngie [ $# -eq 3 ] && xo_fmt=${2} # Don't set xo_fmt to `out' 59288929Sngie IFS=$oldIFS 60288929Sngie tc_escaped="${tc_script}${xo_fmt:+__${xo_fmt}}" 61269902Sngie 62269902Sngie atf_test_case ${tc_escaped} 63288929Sngie eval "${tc_escaped}_body() { check ${tc_script} ${xo_fmt}; }" 64269902Sngie atf_add_test_case ${tc_escaped} 65269902Sngie} 66269902Sngie 67269902Sngieatf_init_test_cases() 68269902Sngie{ 69288929Sngie for path in $(find -Es "${SRCDIR}" -name '*.out'); do 70269902Sngie add_testcase ${path##*/} 71269902Sngie done 72269902Sngie} 73