1*1581ec9aSEric van Gyzen#!/usr/libexec/atf-sh 2*1581ec9aSEric van Gyzen# 3*1581ec9aSEric van Gyzen# SPDX-License-Identifier: BSD-2-Clause 4*1581ec9aSEric van Gyzen# 5*1581ec9aSEric van Gyzen# Copyright (c) 2022 Eric van Gyzen 6*1581ec9aSEric van Gyzen# 7*1581ec9aSEric van Gyzen# Redistribution and use in source and binary forms, with or without 8*1581ec9aSEric van Gyzen# modification, are permitted provided that the following conditions 9*1581ec9aSEric van Gyzen# are met: 10*1581ec9aSEric van Gyzen# 1. Redistributions of source code must retain the above copyright 11*1581ec9aSEric van Gyzen# notice, this list of conditions and the following disclaimer. 12*1581ec9aSEric van Gyzen# 2. Redistributions in binary form must reproduce the above copyright 13*1581ec9aSEric van Gyzen# notice, this list of conditions and the following disclaimer in the 14*1581ec9aSEric van Gyzen# documentation and/or other materials provided with the distribution. 15*1581ec9aSEric van Gyzen# 16*1581ec9aSEric van Gyzen# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*1581ec9aSEric van Gyzen# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*1581ec9aSEric van Gyzen# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*1581ec9aSEric van Gyzen# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*1581ec9aSEric van Gyzen# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*1581ec9aSEric van Gyzen# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*1581ec9aSEric van Gyzen# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*1581ec9aSEric van Gyzen# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*1581ec9aSEric van Gyzen# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*1581ec9aSEric van Gyzen# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*1581ec9aSEric van Gyzen# SUCH DAMAGE. 27*1581ec9aSEric van Gyzen 28*1581ec9aSEric van Gyzenatf_test_case contrib_file_tests cleanup 29*1581ec9aSEric van Gyzencontrib_file_tests_body() { 30*1581ec9aSEric van Gyzen srcdir="$(atf_get_srcdir)" 31*1581ec9aSEric van Gyzen 32*1581ec9aSEric van Gyzen for testfile in "${srcdir}"/*.testfile; do 33*1581ec9aSEric van Gyzen test_name="${testfile%.testfile}" 34*1581ec9aSEric van Gyzen result_file="${test_name}.result" 35*1581ec9aSEric van Gyzen magic_file="${test_name}.magic" 36*1581ec9aSEric van Gyzen file_args= 37*1581ec9aSEric van Gyzen if [ -e "${magic_file}" ]; then 38*1581ec9aSEric van Gyzen file_args="${file_args} --magic-file ${magic_file}" 39*1581ec9aSEric van Gyzen fi 40*1581ec9aSEric van Gyzen # The result files were created in UTC. 41*1581ec9aSEric van Gyzen TZ=Z atf_check -o save:actual_output file ${file_args} \ 42*1581ec9aSEric van Gyzen --brief "$testfile" 43*1581ec9aSEric van Gyzen atf_check -o save:trimmed_output tr -d '\012' < actual_output 44*1581ec9aSEric van Gyzen atf_check cmp trimmed_output "$result_file" 45*1581ec9aSEric van Gyzen done 46*1581ec9aSEric van Gyzen} 47*1581ec9aSEric van Gyzen 48*1581ec9aSEric van Gyzencontrib_file_tests_cleanup() { 49*1581ec9aSEric van Gyzen rm -f actual_output trimmed_output 50*1581ec9aSEric van Gyzen} 51*1581ec9aSEric van Gyzen 52*1581ec9aSEric van Gyzenatf_init_test_cases() { 53*1581ec9aSEric van Gyzen atf_add_test_case contrib_file_tests 54*1581ec9aSEric van Gyzen} 55