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

[PATCH 2/2] t0028: add more tests

From
AGAlexandr Miloslavskiy via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 23, 2019, 08:33 UTC
Message-ID
<d5f6f00a516180d9ae4a0ed1cceecec8ef1b6b88.1569227601.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.347.git.gitgitgadget@gmail.com>
From: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>

After I discovered that UTF-16-LE-BOM test was bugged and still succeeded, I decided that better tests are required. Possibly the best option here is to compare git results against hardcoded ground truth.

The new tests also cover more interesting chars where (ANSI != UTF-8).
Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
---
 t/t0028-working-tree-encoding.sh | 39 ++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff --git a/t/t0028-working-tree-encoding.sh b/t/t0028-working-tree-encoding.sh
index 5493cf3ca9..d0dd5dd0ea 100755
--- a/t/t0028-working-tree-encoding.sh
+++ b/t/t0028-working-tree-encoding.sh
@@ -280,4 +280,43 @@ test_expect_success ICONV_SHIFT_JIS 'check roundtrip encoding' '
 	git reset
 '
 
+# $1: checkout encoding
+# $2: test string
+# $3: binary test string in checkout encoding
+test_commit_utf8_checkout_other () {
+	encoding="$1"
+	orig_string="$2"
+	expect_bytes="$3"
+	
+	test_expect_success "Commit utf-8, checkout ${encoding}" '
+		test_when_finished "git checkout HEAD -- .gitattributes" &&
+		
+		test_ext="commit_utf8_checkout_${encoding}" &&
+		test_file="test.${test_ext}" &&
+		
+		# Commit as utf-8
+		echo "*.${test_ext} text working-tree-encoding=utf-8" >.gitattributes &&
+		printf "${orig_string}" >"${test_file}" &&
+		git add "${test_file}" &&
+		git commit -m "Test data" &&
+
+		# Checkout in tested encoding
+		rm "${test_file}" &&
+		echo "*.${test_ext} text working-tree-encoding=${encoding}" >.gitattributes &&
+		git checkout HEAD -- "${test_file}" &&
+		
+		# Test
+		printf "${expect_bytes}" > "${test_file}.raw" &&
+		test_cmp_bin "${test_file}.raw" "${test_file}"
+	'
+}
+
+test_commit_utf8_checkout_other "UTF-8"        "Test Тест" "\124\145\163\164\040\320\242\320\265\321\201\321\202"
+test_commit_utf8_checkout_other "UTF-16LE"     "Test Тест" "\124\000\145\000\163\000\164\000\040\000\042\004\065\004\101\004\102\004"
+test_commit_utf8_checkout_other "UTF-16BE"     "Test Тест" "\000\124\000\145\000\163\000\164\000\040\004\042\004\065\004\101\004\102"
+test_commit_utf8_checkout_other "UTF-16LE-BOM" "Test Тест" "\377\376\124\000\145\000\163\000\164\000\040\000\042\004\065\004\101\004\102\004"
+test_commit_utf8_checkout_other "UTF-16BE-BOM" "Test Тест" "\376\377\000\124\000\145\000\163\000\164\000\040\004\042\004\065\004\101\004\102"
+test_commit_utf8_checkout_other "UTF-32LE"     "Test Тест" "\124\000\000\000\145\000\000\000\163\000\000\000\164\000\000\000\040\000\000\000\042\004\000\000\065\004\000\000\101\004\000\000\102\004\000\000"
+test_commit_utf8_checkout_other "UTF-32BE"     "Test Тест" "\000\000\000\124\000\000\000\145\000\000\000\163\000\000\000\164\000\000\000\040\000\000\004\042\000\000\004\065\000\000\004\101\000\000\004\102"
+
 test_done
-- 
gitgitgadget
Previous: Alexandr Miloslavskiy via GitGitGadgetNext: Alexandr Miloslavskiy via GitGitGadget
Message 3 of 18 in “t0028 fix test + more tests”
  1. 0/2 t0028 fix test + more testsAlexandr Miloslavskiy via GitGitGadget, Sep 23, 2019
  2. 1/2 t0028: fix test for UTF-16-LE-BOMAlexandr Miloslavskiy via GitGitGadget, Sep 23, 2019
  3. 2/2 t0028: add more testsAlexandr Miloslavskiy via GitGitGadget, Sep 23, 2019
  4. 0/2 Update: fixed typos in commit messageAlexandr Miloslavskiy via GitGitGadget, Sep 23, 2019
  5. 1/2 t0028: fix test for UTF-16-LE-BOMAlexandr Miloslavskiy via GitGitGadget, Sep 23, 2019
  6. Torsten BögershausenSep 24, 2019
  7. Alexandr MiloslavskiySep 24, 2019
  8. 2/2 t0028: add more testsAlexandr Miloslavskiy via GitGitGadget, Sep 23, 2019
  9. Torsten BögershausenSep 24, 2019
  10. Alexandr MiloslavskiySep 24, 2019
  11. Johannes SixtSep 24, 2019
  12. Alexandr MiloslavskiySep 24, 2019
  13. 0/2 Update: fixed typos in commit messageAlexandr Miloslavskiy via GitGitGadget, Sep 24, 2019
  14. 2/2 t0028: add more testsAlexandr Miloslavskiy via GitGitGadget, Sep 24, 2019
  15. Junio C HamanoSep 28, 2019
  16. Alexandr MiloslavskiySep 30, 2019
  17. 1/2 t0028: fix test for UTF-16-LE-BOMAlexandr Miloslavskiy via GitGitGadget, Sep 24, 2019
  18. Torsten BögershausenSep 26, 2019

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.