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.
This commit is contained in:
Andreas Gruenbacher 2024-11-11 21:07:33 +01:00
parent be8b3c68b0
commit 910fecf695
12 changed files with 109 additions and 39 deletions

View File

@ -42,6 +42,7 @@ TESTS = \
git-cleanup \
garbage \
global-reject-files \
hardlinks \
inname \
line-numbers \
merge \

View File

@ -10,6 +10,7 @@
require cat
require sed
require chmod
use_local_patch
use_tmpdir

View File

@ -10,6 +10,7 @@
require cat
require sed
require chmod
use_local_patch
use_tmpdir

50
tests/hardlinks Normal file
View File

@ -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 <<EOF
--- f.orig
+++ f
@@ -2 +2 @@
-one
+two
--- g.orig
+++ g
@@ -2 +2 @@
-one
+two
EOF
check 'patch -p0 < fg.diff' <<EOF
patching file f
Hunk #1 succeeded at 1 (offset -1 lines).
patching file g
Hunk #1 succeeded at 1 (offset -1 lines).
EOF
check 'cat f.orig' <<EOF
one
EOF
check 'cat g.orig' <<EOF
one
EOF

View File

@ -9,6 +9,7 @@
require cat
require chmod
require stat
require chmod
use_local_patch
use_tmpdir

View File

@ -8,6 +8,7 @@
require cat
require sed
require chmod
use_local_patch
use_tmpdir

View File

@ -9,13 +9,15 @@
. $srcdir/test-lib.sh
require cat
require special_characters
use_local_patch
use_tmpdir
# ==============================================================
# Forbidden characters in Windows filenames:
# \ / : * ? " < > |
# \ / : * ? " < > | TAB
# Filenames with trailing space characters
cat > d.diff <<EOF
--- "\\t \\040"

View File

@ -9,6 +9,7 @@
. $srcdir/test-lib.sh
require cat
require chmod
use_local_patch
use_tmpdir

View File

@ -50,41 +50,6 @@ EOF
# ==============================================================
# Hardlinks between source files
echo one > f
ln f g
cat > fg.diff <<EOF
--- f.orig
+++ f
@@ -2 +2 @@
-one
+two
--- g.orig
+++ g
@@ -2 +2 @@
-one
+two
EOF
check 'patch -p0 < fg.diff' <<EOF
patching file f
Hunk #1 succeeded at 1 (offset -1 lines).
patching file g
Hunk #1 succeeded at 1 (offset -1 lines).
EOF
check 'cat f.orig' <<EOF
one
EOF
check 'cat g.orig' <<EOF
one
EOF
# ==============================================================
echo one > f
cat > f.diff <<EOF

View File

@ -9,6 +9,7 @@
. $srcdir/test-lib.sh
require cat
require symlinks
use_local_patch
use_tmpdir

View File

@ -7,7 +7,7 @@
# FIXME: Requires a version of diff that understands "-u".
require_gnu_diff() {
_require_gnu_diff() {
case "`diff --version 2> /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

View File

@ -7,6 +7,7 @@
. $srcdir/test-lib.sh
require cat
require hardlinks
use_local_patch
use_tmpdir