git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] t1300: add more tests for whitespace and inline comments

From
DSDragan Simic <dsimic@manjaro.org>
Date
Mar 15, 2024, 13:22 UTC
Message-ID
<590731e15a01558d1bbcdfc01df4f78573138742.1710508691.git.dsimic@manjaro.org>
In-Reply-To
<cover.1710508691.git.dsimic@manjaro.org>

Add a handful of additional automated tests, to improve the coverage of configuration file entries whose values contain internal whitespace, leading and/or trailing whitespace, or which contain an additional inline comment.

Signed-off-by: Dragan Simic <dsimic@manjaro.org>
---
 t/t1300-config.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 101 insertions(+), 1 deletion(-)
diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index 31c387868708..6eef8a48098c 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -11,6 +11,96 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
+cat > .git/config << EOF
+[section]
+	solid = rock
+	sparse = big 		 blue
+	sparseAndTail = big 		 blue 
+	sparseAndTailQuoted = "big 		 blue "
+	sparseAndBiggerTail = big 		 blue 	 	
+	sparseAndBiggerTailQuoted = "big 		 blue 	 	"
+	sparseAndBiggerTailQuotedPlus =  "big 		 blue 	 	"	 
+	headAndTail = 	big blue 
+	headAndTailQuoted = "	big blue "
+	headAndTailQuotedPlus =  "	big blue " 
+	annotated = big blue	# to be discarded
+	annotatedQuoted = "big blue"	# to be discarded
+EOF
+
+echo 'rock' > expect
+
+test_expect_success 'no internal whitespace' '
+	git config --get section.solid > output &&
+	test_cmp expect output
+'
+
+echo 'big 		 blue' > expect
+
+test_expect_success 'internal whitespace' '
+	git config --get section.sparse > output &&
+	test_cmp expect output
+'
+
+test_expect_success 'internal and trailing whitespace' '
+	git config --get section.sparseAndTail > output &&
+	test_cmp expect output
+'
+
+test_expect_success 'internal and more trailing whitespace' '
+	git config --get section.sparseAndBiggerTail > output &&
+	test_cmp expect output
+'
+
+echo 'big 		 blue ' > expect
+
+test_expect_success 'internal and trailing whitespace, all quoted' '
+	git config --get section.sparseAndTailQuoted > output &&
+	test_cmp expect output
+'
+
+echo 'big 		 blue 	 	' > expect
+
+test_expect_success 'internal and more trailing whitespace, all quoted' '
+	git config --get section.sparseAndBiggerTailQuoted > output &&
+	test_cmp expect output
+'
+
+test_expect_success 'internal and more trailing whitespace, not all quoted' '
+	git config --get section.sparseAndBiggerTailQuotedPlus > output &&
+	test_cmp expect output
+'
+
+echo 'big blue' > expect
+
+test_expect_success 'leading and trailing whitespace' '
+	git config --get section.headAndTail > output &&
+	test_cmp expect output
+'
+
+echo '	big blue ' > expect
+
+test_expect_success 'leading and trailing whitespace, all quoted' '
+	git config --get section.headAndTailQuoted > output &&
+	test_cmp expect output
+'
+
+test_expect_success 'leading and trailing whitespace, not all quoted' '
+	git config --get section.headAndTailQuotedPlus > output &&
+	test_cmp expect output
+'
+
+echo 'big blue' > expect
+
+test_expect_success 'inline comment' '
+	git config --get section.annotated > output &&
+	test_cmp expect output
+'
+
+test_expect_success 'inline comment, quoted' '
+	git config --get section.annotatedQuoted > output &&
+	test_cmp expect output
+'
+
 test_expect_success 'clear default config' '
 	rm -f .git/config
 '
@@ -1066,7 +1156,17 @@ test_expect_success '--null --get-regexp' '
 	test_cmp expect result
 '
 
-test_expect_success 'inner whitespace kept verbatim' '
+test_expect_success 'inner whitespace kept verbatim, spaces only' '
+	git config section.val "foo   bar" &&
+	test_cmp_config "foo   bar" section.val
+'
+
+test_expect_success 'inner whitespace kept verbatim, horizontal tabs only' '
+	git config section.val "foo		bar" &&
+	test_cmp_config "foo		bar" section.val
+'
+
+test_expect_success 'inner whitespace kept verbatim, horizontal tabs and spaces' '
 	git config section.val "foo 	  bar" &&
 	test_cmp_config "foo 	  bar" section.val
 '
Previous: Dragan SimicNext: Eric Sunshine
Message 3 of 11 in “Fix a bug in configuration parsing, and improve tests and documentation”
  1. 0/4 Fix a bug in configuration parsing, and improve tests and documentationDragan Simic, Mar 15, 2024
  2. 1/4 config: minor addition of whitespaceDragan Simic, Mar 15, 2024
  3. 3/4 t1300: add more tests for whitespace and inline commentsDragan Simic, Mar 15, 2024
  4. Eric SunshineMar 15, 2024
  5. Dragan SimicMar 15, 2024
  6. Eric SunshineMar 15, 2024
  7. Dragan SimicMar 15, 2024
  8. 2/4 config: really keep value-internal whitespace verbatimDragan Simic, Mar 15, 2024
  9. Junio C HamanoMar 15, 2024
  10. Dragan SimicMar 15, 2024
  11. 4/4 config.txt: describe handling of whitespace furtherDragan Simic, Mar 15, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.