t1006: extract helper functions into new 'lib-cat-file.sh'
Extract 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 these functions. This improves the code reuse and readability, enabling future cat-file tests to share these helpers without duplicating code. While at it update the style of this line to follow coding guidelines: . "$TEST_DIRECTORY/lib-loose.sh" to . "$TEST_DIRECTORY"/lib-loose.sh Signed-off-by: Eric Ju <eric.peijian@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Ju committed
Jul 24, 2026 at 12:54 UTC
fb60c49d18d1d52b6b81680586754168bc3ebc2c
2 files changed
+18
-13
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 NUL 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
+2
-13
@@ -3,7 +3,8 @@
3
test_description='git cat-file'
4
5
. ./test-lib.sh
6
-. "$TEST_DIRECTORY/lib-loose.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"