Skip to contentSkip to conversation

Make test t3700-add.sh more robust

PATCH In review Ingo Brückl 2 participants 2 messages Jul 29, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/3 Make test t3700-add.sh more robust

Don't rely on chmod to work on the underlying platform (although it wouldn't harm the result of the '--chmod=-x' test). Directly check the result of the --chmod option.

Add a test_mode_in_index helper function in order to check for success.

---
 t/t3700-add.sh          | 20 ++++----------------
 t/test-lib-functions.sh | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 16 deletions(-)
t/t3700-add.sh +4 -16
index 494f5b8..c08ec9e 100755
@@ -332,25 +332,13 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
 	test_i18ncmp expect.err actual.err
 '
 
-test_expect_success 'git add --chmod=+x stages a non-executable file with +x' '
+test_expect_success 'git add --chmod=[+-]x stages correctly' '
 	rm -f foo1 &&
 	echo foo >foo1 &&
 	git add --chmod=+x foo1 &&
-	case "$(git ls-files --stage foo1)" in
-	100755" "*foo1) echo pass;;
-	*) echo fail; git ls-files --stage foo1; (exit 1);;
-	esac
-'
-
-test_expect_success 'git add --chmod=-x stages an executable file with -x' '
-	rm -f xfoo1 &&
-	echo foo >xfoo1 &&
-	chmod 755 xfoo1 &&
-	git add --chmod=-x xfoo1 &&
-	case "$(git ls-files --stage xfoo1)" in
-	100644" "*xfoo1) echo pass;;
-	*) echo fail; git ls-files --stage xfoo1; (exit 1);;
-	esac
+	test_mode_in_index 100755 foo1 &&
+	git add --chmod=-x foo1 &&
+	test_mode_in_index 100644 foo1
 '
 
 test_expect_success POSIXPERM,SYMLINKS 'git add --chmod=+x with symlinks' '
t/test-lib-functions.sh +14 -0
index 4f7eadb..0e6652b 100644
@@ -990,3 +990,17 @@ test_copy_bytes () {
 		}
 	' - "$1"
 }
+
+# Test the file mode "$1" of the file "$2" in the index.
+test_mode_in_index () {
+	case "$(git ls-files --stage "$2")" in
+		$1\ *"$2")
+			echo pass
+			;;
+		*)
+			echo fail
+			git ls-files --stage "$2"
+			return 1
+			;;
+	esac
+}

--
2.9.2

#1 lore raw
Quoted 1 line · Ingo Brückl

Subject: Re: [PATCH v2 2/3] Make test t3700-add.sh more robust

Please check output from "git shortlog --no-merges -100" to see how your titles play well with others. We typically prefix the title with a specific area, a colon, and a sentence that does not begin in a capital letter and does not end with a full-stop.

Quoted 5 lines

Don't rely on chmod to work on the underlying platform (although it wouldn't harm the result of the '--chmod=-x' test). Directly check the result of the --chmod option.

Add a test_mode_in_index helper function in order to check for success.

Hmph, I do not immediately see the point of having the helper in test-lib-functions.sh, though. This helper looks more or less specific to this test script.

In any case, I think addition of the "test_mode_in_index" helper and conversion from case/esac to the helper should be a separate patch from what this patch wants to do, which is to merge two more-or-less redundant tests into one.

Thanks.