]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: chmod: test that chmod(2) is always called
authorCollin Funk <collin.funk1@gmail.com>
Fri, 20 Feb 2026 03:13:34 +0000 (19:13 -0800)
committerCollin Funk <collin.funk1@gmail.com>
Sat, 21 Feb 2026 05:37:42 +0000 (21:37 -0800)
* tests/chmod/only-op.sh: New file.
* tests/local.mk (all_test): Add the new test.

tests/chmod/only-op.sh [new file with mode: 0755]
tests/local.mk

diff --git a/tests/chmod/only-op.sh b/tests/chmod/only-op.sh
new file mode 100755 (executable)
index 0000000..a2fd254
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Test that 'chmod' does not skip calling chmod(2) even when the file mode bits
+# are unchanged.
+
+# 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ chmod stat
+skip_if_root_
+
+test "$(stat --format=%U /)" = 'root' || skip_ 'root does not own /'
+
+for op in '+' '-' '='; do
+  returns_ 1 chmod "$op" / 2>err || fail=1
+  grep -F "chmod: changing permissions of '/'" err || { fail=1; cat err; }
+done
+
+Exit $fail
index 5f9f3d19b640e376dba0d6215314a8904d5528f9..aa71951f86a254eee7ca38ed33d6246b2afd7adb 100644 (file)
@@ -517,6 +517,7 @@ all_tests =                                 \
   tests/chmod/ignore-symlink.sh                        \
   tests/chmod/inaccessible.sh                  \
   tests/chmod/octal.sh                         \
+  tests/chmod/only-op.sh                       \
   tests/chmod/partial-fail.sh                  \
   tests/chmod/setgid.sh                                \
   tests/chmod/silent.sh                                \