t1006: split test utility functions into new 'lib-cat-file.sh'
This refactor extracts utility functions from the cat-file's test script 't1006-cat-file.sh' into a new 'lib-cat-file.sh' dedicated library file. A subsequent commit will need this functions, the goal is to improve code reuse and readability,enabling future tests to leverage these utilities without duplicating code. Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Ju committed
Jul 10, 2026 at 18:41 UTC
84cef6dfa0ee24d090b0bccefa67953ad4440fcb
2 files changed
+17
-12
t/lib-cat-file.sh
new
+16
@@ -0,0 +1,16 @@
1
+# Library of git-cat-file related test functions.
2
+
3
+# Print a string without a trailing newline.
4
+echo_without_newline () {
5
+ printf '%s' "$*"
6
+}
7
+
8
+# Print a string without newlines and replace them with a NULL character (\0).
9
+echo_without_newline_nul () {
10
+ echo_without_newline "$@" | tr '\n' '\0'
11
+}
12
+
13
+# Calculate the length of a string.
14
+strlen () {
15
+ echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
16
+}
t/t1006-cat-file.sh
+1
-12
@@ -4,6 +4,7 @@ test_description='git cat-file'
4
5
. ./test-lib.sh
6
. "$TEST_DIRECTORY/lib-loose.sh"
7
+. "$TEST_DIRECTORY"/lib-cat-file.sh
8
9
test_cmdmode_usage () {
10
test_expect_code 129 "$@" 2>err &&
@@ -99,18 +100,6 @@ do
100
'
101
done
102
102
-echo_without_newline () {
103
- printf '%s' "$*"
104
-}
105
-
106
-echo_without_newline_nul () {
107
- echo_without_newline "$@" | tr '\n' '\0'
108
-}
109
-
110
-strlen () {
111
- echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
112
-}
113
-
103
run_tests () {
104
type=$1
105
object_name="$2"