Re: [PATCH 12/20] t: refactor tests depending on Perl to print data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 20, 2025 at 5:36 AM Patrick Steinhardt <ps@xxxxxx> wrote:
> A bunch of tests rely on Perl to print data in various different ways.
> These usages fall into the following categories:
>
>   - Print data conditionally by matching patterns. These usecases can be
>     converted to use awk(1) rather easily.
>
>   - Print data repeatedly. These usecases can typically be converted to
>     use a combination of `test-tool genzeros` and sed(1).
>
>   - Print data in reverse. These usecases can be converted to use
>     awk(1).
>
> Refactor the tests accordingly so that we can drop a couple of
> PERL_TEST_HELPERS prerequisites.
>
> Signed-off-by: Patrick Steinhardt <ps@xxxxxx>
> ---
> diff --git a/t/t0610-reftable-basics.sh b/t/t0610-reftable-basics.sh
> @@ -643,12 +643,11 @@ test_expect_success 'basic: commit and list refs' '
> -test_expect_success PERL_TEST_HELPERS 'basic: can write large commit message' '
> +test_expect_success 'basic: can write large commit message' '
>         test_when_finished "rm -rf repo" &&
>         git init repo &&
> -       perl -e "
> -               print \"this is a long commit message\" x 50000
> -       " >commit-msg &&
> +
> +       awk "BEGIN { for (i = 0; i < 50000; i++) print \"this is a long commit message\" }" >commit-msg &&
>         git -C repo commit --allow-empty --file=../commit-msg
>  '

The original Perl version emitted the entire message as a single-line,
whereas the awk replacement emits 50,000 lines. Was the intent of the
original specifically to check whether it handled an extremely long
line correctly, or was it merely checking whether an overall very
lengthy content was handled correctly? If the former, then this
semantic change is inconsistent with what this test wants to be
checking; if the latter, then this semantic change is harmless.

Also, it is possible to do this entirely in shell without running an
external program (assuming `test` and `printf` are builtins):

  i=0 &&
  while test $i -lt 50000
  do
    echo "this is a long commit message" &&
    i=$(($i+1)) ||
    return 1
  done &&

> diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh
> @@ -228,7 +228,10 @@ test_expect_success PERL_TEST_HELPERS 'ignore very large set of prefixes' '
>                 echo object-format=$(test_oid algo) &&
>                 echo 0001 &&
> -               perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
> +               awk "{
> +                       for (i = 1; i <= 65536; i++)
> +                               print \"ref-prefix refs/heads/\", \$i
> +               }" &&
>                 echo 0000

In this one, the Perl version emitted 65,536 lines, so the awk version
is consistent with that. Okay.

This could also be done purely in shell without using awk.





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux