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

[PATCH v2 1/7] t: move 'hex2oct' into test-lib-functions.sh

From
Taylor Blau <me@ttaylorr.com>
Date
Apr 10, 2019, 02:13 UTC
Message-ID
<f09c374557070b286391f1f69c4288d7d0769851.1554861974.git.me@ttaylorr.com>
In-Reply-To
<cover.1554861974.git.me@ttaylorr.com>

The helper 'hex2oct' is used to convert base-16 encoded data into a base-8 binary form, and is useful for preparing data for commands that accept input in a binary format, such as 'git hash-object', via 'printf'.

This helper is defined identically in three separate places throughout 't'. Move the definition to test-lib-function.sh, so that it can be used in new test suites, and its definition is not redundant.

This will likewise make our job easier in the subsequent commit, which also uses 'hex2oct'.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 t/t1007-hash-object.sh  | 4 ----
 t/t1450-fsck.sh         | 4 ----
 t/t5601-clone.sh        | 4 ----
 t/test-lib-functions.sh | 6 ++++++
 4 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
index a37753047e..7099d33508 100755
--- a/t/t1007-hash-object.sh
+++ b/t/t1007-hash-object.sh
@@ -199,10 +199,6 @@ test_expect_success 'too-short tree' '
 	test_i18ngrep "too-short tree object" err
 '
 
-hex2oct() {
-    perl -ne 'printf "\\%03o", hex for /../g'
-}
-
 test_expect_success 'malformed mode in tree' '
 	hex_sha1=$(echo foo | git hash-object --stdin -w) &&
 	bin_sha1=$(echo $hex_sha1 | hex2oct) &&
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 49f08d5b9c..0f268a3664 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -256,10 +256,6 @@ test_expect_success 'unparseable tree object' '
 	test_i18ngrep ! "fatal: empty filename in tree entry" out
 '
 
-hex2oct() {
-	perl -ne 'printf "\\%03o", hex for /../g'
-}
-
 test_expect_success 'tree entry with type mismatch' '
 	test_when_finished "remove_object \$blob" &&
 	test_when_finished "remove_object \$tree" &&
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index d6948cbdab..3f49943010 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -611,10 +611,6 @@ test_expect_success 'GIT_TRACE_PACKFILE produces a usable pack' '
 	git -C replay.git index-pack -v --stdin <tmp.pack
 '
 
-hex2oct () {
-	perl -ne 'printf "\\%03o", hex for /../g'
-}
-
 test_expect_success 'clone on case-insensitive fs' '
 	git init icasefs &&
 	(
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 80402a428f..349eabe851 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1202,6 +1202,12 @@ depacketize () {
 	'
 }
 
+# Converts base-16 data into base-8. The output is given as a sequence of
+# escaped octals, suitable for consumption by 'printf'.
+hex2oct () {
+	perl -ne 'printf "\\%03o", hex for /../g'
+}
+
 # Set the hash algorithm in use to $1.  Only useful when testing the testsuite.
 test_set_hash () {
 	test_hash_algo="$1"
-- 
2.21.0.203.g358da99528
Previous: Taylor BlauNext: Taylor Blau
Message 35 of 41 in “harden unexpected object types checks”
  1. 0/7 harden unexpected object types checksTaylor Blau, Apr 5, 2019
  2. 1/7 t: move 'hex2oct' into test-lib-functions.shTaylor Blau, Apr 5, 2019
  3. 2/7 t: introduce tests for unexpected object typesTaylor Blau, Apr 5, 2019
  4. SZEDER GáborApr 5, 2019
  5. Jeff KingApr 5, 2019
  6. SZEDER GáborApr 5, 2019
  7. Jeff KingApr 5, 2019
  8. Ævar Arnfjörð BjarmasonApr 7, 2019
  9. Taylor BlauApr 9, 2019
  10. Ævar Arnfjörð BjarmasonApr 9, 2019
  11. Taylor BlauApr 10, 2019
  12. Junio C HamanoApr 8, 2019
  13. Eric SunshineApr 5, 2019
  14. Jeff KingApr 5, 2019
  15. Taylor BlauApr 6, 2019
  16. Junio C HamanoApr 8, 2019
  17. Taylor BlauApr 9, 2019
  18. Eric SunshineApr 9, 2019
  19. Taylor BlauApr 9, 2019
  20. Eric SunshineApr 9, 2019
  21. Taylor BlauApr 10, 2019
  22. Taylor BlauApr 6, 2019
  23. Jeff KingApr 5, 2019
  24. Taylor BlauApr 6, 2019
  25. 3/7 list-objects.c: handle unexpected non-blob entriesTaylor Blau, Apr 5, 2019
  26. 4/7 list-objects.c: handle unexpected non-tree entriesTaylor Blau, Apr 5, 2019
  27. 5/7 get_commit_tree(): return NULL for broken treeTaylor Blau, Apr 5, 2019
  28. 6/7 rev-list: let traversal die when --missing is not in useTaylor Blau, Apr 5, 2019
  29. Jeff KingApr 5, 2019
  30. Taylor BlauApr 6, 2019
  31. Jeff KingApr 7, 2019
  32. Taylor BlauApr 9, 2019
  33. 7/7 rev-list: detect broken root treesTaylor Blau, Apr 5, 2019
  34. 0/7 harden unexpected object types checksTaylor Blau, Apr 10, 2019
  35. 1/7 t: move 'hex2oct' into test-lib-functions.shTaylor Blau, Apr 10, 2019
  36. 2/7 t: introduce tests for unexpected object typesTaylor Blau, Apr 10, 2019
  37. 3/7 list-objects.c: handle unexpected non-blob entriesTaylor Blau, Apr 10, 2019
  38. 4/7 list-objects.c: handle unexpected non-tree entriesTaylor Blau, Apr 10, 2019
  39. 5/7 get_commit_tree(): return NULL for broken treeTaylor Blau, Apr 10, 2019
  40. 6/7 rev-list: let traversal die when --missing is not in useTaylor Blau, Apr 10, 2019
  41. 7/7 rev-list: detect broken root treesTaylor Blau, Apr 10, 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.