[PATCH 1/2] advice: allow advice type to be provided in tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



advise_if_enabled() has a special branch to handle
backwards-compatibility with the `pushUpdateRejected` and
`pushNonFastForward` advice types, which went untested.

Modify the `test-tool advise` command so the advice type can be changed
between nestedTag (the previous behaviour) and pushUpdateRejected.

Signed-off-by: James Liu <james@xxxxxxxxxxx>
---
 t/helper/test-advise.c | 20 ++++++++++++++------
 t/t0018-advice.sh      | 30 +++++++++++++++++++++++++++---
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/t/helper/test-advise.c b/t/helper/test-advise.c
index 8a3fd0009a..c18b18e059 100644
--- a/t/helper/test-advise.c
+++ b/t/helper/test-advise.c
@@ -5,18 +5,26 @@
 
 int cmd__advise_if_enabled(int argc, const char **argv)
 {
-	if (argc != 2)
-		die("usage: %s <advice>", argv[0]);
+	if (argc != 3)
+		die("usage: %s nestedTag|pushUpdateRejected <advice>", argv[0]);
 
 	setup_git_directory();
 	git_config(git_default_config, NULL);
 
 	/*
-	 * Any advice type can be used for testing, but NESTED_TAG was
-	 * selected here and in t0018 where this command is being
-	 * executed.
+	 * Any advice type can be used for testing, but ADVICE_NESTED_TAG and
+	 * ADVICE_PUSH_UPDATE_REJECTED were selected here and used in t0018
+	 * where this command is being executed.
+	 *
+	 * This allows test cases to exercise the normal and special branch
+	 * within advice_enabled().
 	 */
-	advise_if_enabled(ADVICE_NESTED_TAG, "%s", argv[1]);
+	if (!strcmp(argv[1], "nestedTag"))
+		advise_if_enabled(ADVICE_NESTED_TAG, "%s", argv[2]);
+	else if (!strcmp(argv[1], "pushUpdateRejected"))
+		advise_if_enabled(ADVICE_PUSH_UPDATE_REJECTED, "%s", argv[2]);
+	else
+		die("advice type should be nestedTag|pushUpdateRejected");
 
 	return 0;
 }
diff --git a/t/t0018-advice.sh b/t/t0018-advice.sh
index 0dcfb760a2..8010796e1f 100755
--- a/t/t0018-advice.sh
+++ b/t/t0018-advice.sh
@@ -10,7 +10,16 @@ test_expect_success 'advice should be printed when config variable is unset' '
 	hint: This is a piece of advice
 	hint: Disable this message with "git config advice.nestedTag false"
 	EOF
-	test-tool advise "This is a piece of advice" 2>actual &&
+	test-tool advise nestedTag "This is a piece of advice" 2>actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'advice should be printed when advice.pushUpdateRejected and its alias are unset' '
+	cat >expect <<-\EOF &&
+	hint: This is a piece of advice
+	hint: Disable this message with "git config advice.pushUpdateRejected false"
+	EOF
+	test-tool advise pushUpdateRejected "This is a piece of advice" 2>actual &&
 	test_cmp expect actual
 '
 
@@ -19,14 +28,29 @@ test_expect_success 'advice should be printed when config variable is set to tru
 	hint: This is a piece of advice
 	EOF
 	test_config advice.nestedTag true &&
-	test-tool advise "This is a piece of advice" 2>actual &&
+	test-tool advise nestedTag "This is a piece of advice" 2>actual &&
 	test_cmp expect actual
 '
 
 test_expect_success 'advice should not be printed when config variable is set to false' '
 	test_config advice.nestedTag false &&
-	test-tool advise "This is a piece of advice" 2>actual &&
+	test-tool advise nestedTag "This is a piece of advice" 2>actual &&
 	test_must_be_empty actual
 '
 
+test_expect_success 'advice should not be printed when advice.pushUpdateRejected is unset but its alias is set to false' '
+	test_config advice.pushNonFastForward false &&
+	test-tool advise pushUpdateRejected "This is a piece of advice" 2>actual &&
+	test_must_be_empty actual
+'
+
+test_expect_success 'advice should be printed when advice.pushUpdateRejected is set to true and its alias is unset' '
+	cat >expect <<-\EOF &&
+	hint: This is a piece of advice
+	EOF
+	test_config advice.pushUpdateRejected true &&
+	test-tool advise pushUpdateRejected "This is a piece of advice" 2>actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.44.0





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux