indent: Simplify test script

Much of the test script was concerned with working around RCS tags and
dealing with cases which don't apply to indent.

MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D51795
This commit is contained in:
Dag-Erling Smørgrav
2025-08-08 01:33:56 +02:00
parent 7d955e02b1
commit 0ecc679fd3
+15 -40
View File
@@ -1,3 +1,5 @@
#-
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright 2016 Dell EMC
# All rights reserved.
@@ -29,61 +31,34 @@ SRCDIR=$(atf_get_srcdir)
check()
{
local tc=${1}; shift
local tc=${1}
local profile_flag
local indent=$(atf_config_get usr.bin.indent.test_indent /usr/bin/indent)
cp "${SRCDIR}/${tc%.[0-9]}".* .
# All of the files need to be in the ATF sandbox in order for the tests
# to pass.
atf_check cp ${SRCDIR}/${tc}* .
# Remove $FreeBSD$ RCS expansions because they get re-indented, which
# changes the output
local out_file="${tc}.stdout"
if [ -f "${out_file}" ]; then
parsed_file=output_file.parsed
atf_check -o save:$parsed_file sed -e '/\$FreeBSD.*\$/d' \
${tc}.stdout
out_flag="-o file:$parsed_file"
fi
local profile_file="${tc}.pro"
if [ -f "${profile_file}" ]; then
profile_flag="-P${profile_file}"
if [ -f "${tc}.pro" ]; then
profile_flag="-P${tc}.pro"
else
# Make sure we don't implicitly use ~/.indent.pro from the test
# host, for determinism purposes.
profile_flag="-npro"
fi
sed -e '/\$FreeBSD.*\$/d' ${tc} > input_file.parsed
atf_check -s exit:${tc##*.} ${out_flag} ${indent} ${profile_flag} < input_file.parsed
atf_check -s exit:${tc##*.} -o file:"${tc}.stdout" \
indent ${profile_flag} < "${tc}"
}
add_testcase()
add_legacy_testcase()
{
local tc=${1}
local tc_escaped word
case "${tc%.*}" in
*-*)
local IFS="-"
for word in ${tc%.*}; do
tc_escaped="${tc_escaped:+${tc_escaped}_}${word}"
done
;;
*)
tc_escaped=${tc%.*}
;;
esac
atf_test_case ${tc_escaped}
eval "${tc_escaped}_body() { check ${tc}; }"
atf_add_test_case ${tc_escaped}
atf_test_case ${tc%.[0-9]}
eval "${tc%.[0-9]}_body() { check ${tc}; }"
atf_add_test_case ${tc%.[0-9]}
}
atf_init_test_cases()
{
for path in $(find -Es "${SRCDIR}" -regex '.*\.[0-9]+$'); do
add_testcase ${path##*/}
for tc in $(find -s "${SRCDIR}" -name '*.[0-9]'); do
add_legacy_testcase "${tc##*/}"
done
}