From d1f6125ecf06dde18eda6ee775e2f11881ff618e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 29 Oct 2026 23:27:49 +0100 Subject: [PATCH] tests: chmod: ensure --reference processes operands in order Reported at https://github.com/uutils/coreutils/issues/15666 * tests/chmod/reference-order.sh: New test. * tests/local.mk: Reference the new test. Link: https://github.com/coreutils/coreutils/pull/410 --- tests/chmod/reference-order.sh | 41 ++++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 2 files changed, 42 insertions(+) create mode 100755 tests/chmod/reference-order.sh diff --git a/tests/chmod/reference-order.sh b/tests/chmod/reference-order.sh new file mode 100755 index 000000000..7085df595 --- /dev/null +++ b/tests/chmod/reference-order.sh @@ -0,0 +1,41 @@ +# Ensure chmod --reference processes operands in command-line order + +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chmod + + +touch ref c a b || framework_failure_ +chmod 644 ref && chmod 600 c a b || framework_failure_ + +chmod -v --reference=ref c a b > out || fail=1 +cat <<\EOF > exp || framework_failure_ +mode of 'c' changed from 0600 (rw-------) to 0644 (rw-r--r--) +mode of 'a' changed from 0600 (rw-------) to 0644 (rw-r--r--) +mode of 'b' changed from 0600 (rw-------) to 0644 (rw-r--r--) +EOF +compare exp out || fail=1 + +# The reference mode removes the search bit from dir, so dir/file +# must be handled before dir. +mkdir dir && touch dir/file || framework_failure_ +chmod 600 dir/file || framework_failure_ +chmod --reference=ref dir/file dir || fail=1 +chmod 755 dir || framework_failure_ +test "$(stat -c %a dir/file)" = 644 || fail=1 + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 33d830cd6..6f1be0822 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -574,6 +574,7 @@ all_tests = \ tests/chmod/octal.sh \ tests/chmod/only-op.sh \ tests/chmod/partial-fail.sh \ + tests/chmod/reference-order.sh \ tests/chmod/setgid.sh \ tests/chmod/silent.sh \ tests/chmod/thru-dangling.sh \