Re: [PATCH 2/2] t6402: check exit status of ls-files

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

 



On Thu, Apr 22, 2021 at 11:04 AM Ævar Arnfjörð Bjarmason
<avarab@xxxxxxxxx> wrote:
> On Thu, Apr 22 2021, Đoàn Trần Công Danh wrote:
> > Hm, I'm not sure how would we implement such mode:
> >
> > * Will we run such command in a subprocess and and pipe to "wc -l"
> >   directly to avoid a temporary file, but we will lose the exit code
> >   of running command in process?
>
> Just use a tempfile.

That's what I had in mind when I suggested the function. The function
would remove the tempfile if the check succeeded.

> Here's an implementation that works, sans the fancy opts parsing etc. I
> just use -1 for "don't care". You can see "test_commit" etc. for how to
> do that.
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -817,6 +817,24 @@ test_line_count () {
> +test_line_count_command () {
> +       local op=$1
> +       local ocnt=$2
> +       local ecnt=$3
> +       shift 3
> +       "$@" 2>cnt.err >cnt.out
> +       local exit_code=$?
> +       if test "$ocnt" -gt -1
> +       then
> +               test_line_count "$op" "$ocnt" cnt.out
> +       fi &&
> +       if test "$ecnt" -gt -1
> +       then
> +               test_line_count "$op" "$ecnt" cnt.err
> +       fi &&
> +       return "$exit_code"
> +}

It's not clear why you manually catch the exit code of the command
being run but then use &&-chain for the other parts.

An important reason I suggested creating a function was because the
function could clean up after itself thus freeing the test author from
worrying about adjusting counts in later tests (or later in the same
test). So, just before this function returns, I'd expect to see:

    rm -f cnt.out cnt.err &&



[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