git: ebd127c3e36c - stable/13 - file: Support testing multiple magic files.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 31 Mar 2025 21:35:12 UTC
The branch stable/13 has been updated by ngie:
URL: https://cgit.FreeBSD.org/src/commit/?id=ebd127c3e36c1f02a7a9b2d63621040e7d1a00d4
commit ebd127c3e36c1f02a7a9b2d63621040e7d1a00d4
Author: Xin LI <delphij@FreeBSD.org>
AuthorDate: 2023-10-09 06:06:20 +0000
Commit: Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2025-03-31 21:34:46 +0000
file: Support testing multiple magic files.
This is based on upstream b74150490be904801378b2712fe0d532e1700124
but adapted to ATF.
Reviewed by: jlduran@gmail.com, markj, vangyzen
Differential Revision: https://reviews.freebsd.org/D42129
(cherry picked from commit 8f75390c66bdcde95e1b383aecaa27b4adf88279)
---
usr.bin/file/tests/Makefile | 2 +-
usr.bin/file/tests/file_test.sh | 22 +++++++++++++++++-----
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/usr.bin/file/tests/Makefile b/usr.bin/file/tests/Makefile
index ea0ebaa12ce2..cd3d00ae742c 100644
--- a/usr.bin/file/tests/Makefile
+++ b/usr.bin/file/tests/Makefile
@@ -2,7 +2,7 @@ PACKAGE= tests
ATF_TESTS_SH= file_test
SRCDIR= ${SRCTOP}/contrib/file/tests
-_files!= echo ${SRCDIR}/*.testfile ${SRCDIR}/*.result ${SRCDIR}/*.magic
+_files!= echo ${SRCDIR}/*.testfile ${SRCDIR}/*.flags ${SRCDIR}/*.result ${SRCDIR}/*.magic
${PACKAGE}FILES+=${_files}
.include <bsd.test.mk>
diff --git a/usr.bin/file/tests/file_test.sh b/usr.bin/file/tests/file_test.sh
index 02d494b0f643..490274c05892 100644
--- a/usr.bin/file/tests/file_test.sh
+++ b/usr.bin/file/tests/file_test.sh
@@ -32,14 +32,26 @@ contrib_file_tests_body() {
for testfile in "${srcdir}"/*.testfile; do
test_name="${testfile%.testfile}"
result_file="${test_name}.result"
- magic_file="${test_name}.magic"
file_args=
- if [ -e "${magic_file}" ]; then
- file_args="${file_args} --magic-file ${magic_file}"
+ magic_files=
+ for magic_file in ${test_name}*.magic; do
+ if [ -f "${magic_file}" ]; then
+ if [ -z "${magic_files}" ]; then
+ magic_files="${magic_file}"
+ else
+ magic_files="${magic_files}:${magic_file}"
+ fi
+ fi
+ done
+ if [ -z "${magic_files}" ]; then
+ magic_files=/usr/share/misc/magic
+ fi
+ if [ -f "${test_name}.flags" ]; then
+ file_args="${file_args} -$(cat "${test_name}.flags")"
fi
# The result files were created in UTC.
- TZ=Z atf_check -o save:actual_output file ${file_args} \
- --brief "$testfile"
+ atf_check -o save:actual_output -e ignore env TZ=Z MAGIC="${magic_files}" \
+ file ${file_args} --brief "$testfile"
atf_check cmp actual_output "$result_file"
done
}