Skip to content

Commit d138188

Browse files
peijianjugitster
authored andcommitted
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. The goal is to improve code reuse and readability, enabling future tests to leverage these utilities without duplicating code. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 219877e commit d138188

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

t/lib-cat-file.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
test_description='git cat-file'
44

55
. ./test-lib.sh
6+
. "$TEST_DIRECTORY"/lib-cat-file.sh
67

78
test_cmdmode_usage () {
89
test_expect_code 129 "$@" 2>err &&
@@ -98,18 +99,6 @@ do
9899
'
99100
done
100101

101-
echo_without_newline () {
102-
printf '%s' "$*"
103-
}
104-
105-
echo_without_newline_nul () {
106-
echo_without_newline "$@" | tr '\n' '\0'
107-
}
108-
109-
strlen () {
110-
echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
111-
}
112-
113102
run_tests () {
114103
type=$1
115104
oid=$2

0 commit comments

Comments
 (0)