t: add a function to check executable bit

In line with our other helper functions for paths, let's add a function to check whether a path is executable, and if not, print a suitable error message. Document this function, and note that it must only be used under the POSIXPERM prerequisite, since it doesn't otherwise work on Windows. Signed-off-by: brian m. carlson <bk2204@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jun 27, 2023 at 16:18 UTC d6546af75c3cda2815f2e4d5322dd7a41cc0963b
2 files changed +15
t/README
+6
@@ -1098,6 +1098,12 @@ see test-lib-functions.sh for the full list and their options.
1098 the symbolic link in the file system and a part that does; then only
1099 the latter part need be protected by a SYMLINKS prerequisite (see below).
1100
1101 + - test_path_is_executable
1102 +
1103 + This tests whether a file is executable and prints an error message
1104 + if not. This must be used only under the POSIXPERM prerequisite
1105 + (see below).
1106 +
1107 - test_oid_init
1108
1109 This function loads facts and useful object IDs related to the hash
t/test-lib-functions.sh
+9
@@ -901,6 +901,15 @@ test_path_is_symlink () {
901 fi
902 }
903
904 +test_path_is_executable () {
905 + test "$#" -ne 1 && BUG "1 param"
906 + if ! test -x "$1"
907 + then
908 + echo "$1 is not executable"
909 + false
910 + fi
911 +}
912 +
913 # Check if the directory exists and is empty as expected, barf otherwise.
914 test_dir_is_empty () {
915 test "$#" -ne 1 && BUG "1 param"