From 910fecf695e76c7b45a69cb3630ca2d2a3b86121 Mon Sep 17 00:00:00 2001 From: Andreas Gruenbacher Date: Mon, 11 Nov 2024 21:07:33 +0100 Subject: [PATCH] Add missing feature tests to the test suite Check for chmod, hardlink, symlink, and special character support to prevent test suite failures in feature constrained environments. Thanks to Bruno Haible and Nelson H. F. Beebe for their testing and analysis. * tests/test-lib.sh: Add new feature tests. * tests/hardlinks: Split this hardlinks related test off from tests/remember-backup-files. * tests/Makefile.am (TESTS): Add new hardlinks test here. * tests/file-create-modes, tests/file-modes, tests/read-only-files, tests/preserve-mode-and-timestamp, tests/no-mode-change-git-diff: These tests require chmod support. * tests/hardlinks, tests/unmodified-files: These tests require hardlink support. * tests/symlinks: This test requires symlink support. * tests/quoted-filenames: This test requires special character support in filenames. --- tests/Makefile.am | 1 + tests/file-create-modes | 1 + tests/file-modes | 1 + tests/hardlinks | 50 ++++++++++++++++++++++++++++++ tests/no-mode-change-git-diff | 1 + tests/preserve-mode-and-timestamp | 1 + tests/quoted-filenames | 4 ++- tests/read-only-files | 1 + tests/remember-backup-files | 35 --------------------- tests/symlinks | 1 + tests/test-lib.sh | 51 +++++++++++++++++++++++++++++-- tests/unmodified-files | 1 + 12 files changed, 109 insertions(+), 39 deletions(-) create mode 100644 tests/hardlinks diff --git a/tests/Makefile.am b/tests/Makefile.am index fdc1639..bd3e330 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -42,6 +42,7 @@ TESTS = \ git-cleanup \ garbage \ global-reject-files \ + hardlinks \ inname \ line-numbers \ merge \ diff --git a/tests/file-create-modes b/tests/file-create-modes index 2ea44ec..e80a79a 100644 --- a/tests/file-create-modes +++ b/tests/file-create-modes @@ -10,6 +10,7 @@ require cat require sed +require chmod use_local_patch use_tmpdir diff --git a/tests/file-modes b/tests/file-modes index 8475182..9c28dd8 100644 --- a/tests/file-modes +++ b/tests/file-modes @@ -10,6 +10,7 @@ require cat require sed +require chmod use_local_patch use_tmpdir diff --git a/tests/hardlinks b/tests/hardlinks new file mode 100644 index 0000000..7eb3a28 --- /dev/null +++ b/tests/hardlinks @@ -0,0 +1,50 @@ +# Copyright 2009-2024 Free Software Foundation, Inc. +# +# Copying and distribution of this file, with or without modification, +# in any medium, are permitted without royalty provided the copyright +# notice and this notice are preserved. + +# Patch must not overwrite backup files it has created itself. +# (Backup file tests for symlinks are in tests/symlinks.) + +. $srcdir/test-lib.sh + +require cat +require hardlinks +use_local_patch +use_tmpdir + +# ============================================================== + +# Hardlinks between source files + +echo one > f +ln f g + +cat > fg.diff < | +# \ / : * ? " < > | TAB +# Filenames with trailing space characters cat > d.diff < f -ln f g - -cat > fg.diff < f cat > f.diff < /dev/null`" in *GNU*) ;; @@ -17,10 +17,55 @@ require_gnu_diff() { esac } +_try_chmod() { + chmod "$1" "$2" && test "`ls -l "$2" | cut -b2-10`" = "$3" +} + +_require_chmod() { + tmp=`mktemp working-chmod.XXXXXXXX` + if ! _try_chmod 644 "$tmp" "rw-r--r--" || \ + ! _try_chmod 600 "$tmp" "rw-------"; then + rm -f "$tmp" + echo "This test requires chmod support" >&2 + exit 77 + fi + rm -f "$tmp" +} + +_require_hardlinks() { + tmpdir=`mktemp -d hardlinks.XXXXXXXX` + if ! touch "$tmpdir/f" || + ! ln "$tmpdir/f" "$tmpdir/g"; then + rm -rf "$tmpdir" + echo "This test requires hardlink support" >&2 + exit 77 + fi + rm -rf "$tmpdir" +} + +_require_symlinks() { + tmpdir=`mktemp -d hardlinks.XXXXXXXX` + if ! touch "$tmpdir/f" || + ! ln -s "f" "$tmpdir/g"; then + rm -rf "$tmpdir" + echo "This test requires symlink support" >&2 + exit 77 + fi + rm -rf "$tmpdir" +} + +_require_special_characters() { + if ! tmp=`mktemp ' '.XXXXXXXX`; then + echo "This test requires special character support in filenames" >&2 + exit 77 + fi + rm -f "$tmp" +} + require() { utility="$1" - if type require_${utility} > /dev/null 2> /dev/null; then - require_${utility} + if type _require_${utility} > /dev/null 2> /dev/null; then + _require_${utility} elif ! type "${utility}" > /dev/null 2> /dev/null; then echo "This test requires the ${utility} utility" >&2 exit 77 diff --git a/tests/unmodified-files b/tests/unmodified-files index 93d078a..77cb8bc 100644 --- a/tests/unmodified-files +++ b/tests/unmodified-files @@ -7,6 +7,7 @@ . $srcdir/test-lib.sh require cat +require hardlinks use_local_patch use_tmpdir