Re: [PATCH GSoC RFC v12 04/12] t1006: split test utility functions into new "lib-cat-file.sh"
- From
- Chandra Pratap <chandrapratap3519@gmail.com>
- Date
- Jun 9, 2026, 06:28 UTC
- Message-ID
- <CA+J6zkQe=K80QUOH8LwXCRw9nxv3tHBg+FtfDsYedY5xdHW79A@mail.gmail.com>
- In-Reply-To
- <20260608-ps-eric-work-rebase-v12-4-5338b766e658@gmail.com>
On Mon, 8 Jun 2026 at 15:44, Pablo Sabater <pabloosabaterr@gmail.com> wrote:
Show 8 quoted lines
> > From: Eric Ju <eric.peijian@gmail.com> > > 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.
Hmm, seems like a premature change to me. Do any of the subsequent commits require this refactor? Maybe the follow-up series that enables %objecttype support needs it? Did someone request this change in v11's feedback?
If any of those are true, I think it's worthwhile mentioning it here. That will make it easier to determine whether this change is truly necessary.
Show 62 quoted lines
> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
> ---
> t/lib-cat-file.sh | 16 ++++++++++++++++
> t/t1006-cat-file.sh | 13 +------------
> 2 files changed, 17 insertions(+), 12 deletions(-)
>
> diff --git a/t/lib-cat-file.sh b/t/lib-cat-file.sh
> new file mode 100644
> index 0000000000..44af232d74
> --- /dev/null
> +++ b/t/lib-cat-file.sh
> @@ -0,0 +1,16 @@
> +# Library of git-cat-file related test functions.
> +
> +# Print a string without a trailing newline.
> +echo_without_newline () {
> + printf '%s' "$*"
> +}
> +
> +# Print a string without newlines and replace them with a NULL character (\0).
> +echo_without_newline_nul () {
> + echo_without_newline "$@" | tr '\n' '\0'
> +}
> +
> +# Calculate the length of a string.
> +strlen () {
> + echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
> +}
> diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
> index 8e2c52652c..8360f3bbd9 100755
> --- a/t/t1006-cat-file.sh
> +++ b/t/t1006-cat-file.sh
> @@ -4,6 +4,7 @@ test_description='git cat-file'
>
> . ./test-lib.sh
> . "$TEST_DIRECTORY/lib-loose.sh"
> +. "$TEST_DIRECTORY"/lib-cat-file.sh
>
> test_cmdmode_usage () {
> test_expect_code 129 "$@" 2>err &&
> @@ -99,18 +100,6 @@ do
> '
> done
>
> -echo_without_newline () {
> - printf '%s' "$*"
> -}
> -
> -echo_without_newline_nul () {
> - echo_without_newline "$@" | tr '\n' '\0'
> -}
> -
> -strlen () {
> - echo_without_newline "$1" | wc -c | sed -e 's/^ *//'
> -}
> -
> run_tests () {
> type=$1
> object_name="$2"
>
> --
> 2.54.0