Re: [PATCH v2 01/18] maintenance: create basic maintenance runner
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Aug 4, 2020, 17:51 UTC
- Message-ID
- <dd6a6434-d1cb-f933-3a3e-0f8c09a46ffb@gmail.com>
- In-Reply-To
- <20200804170220.GB227292@google.com>
On 8/4/2020 1:02 PM, Jonathan Nieder wrote:
Show 48 quoted lines
> Derrick Stolee wrote:
>
>> Here is my attempt so far:
> [...]
>> test_subcommand_called "gc" run-no-auto.txt &&
>> test_subcommand_not_called "gc --auto" run-auto.txt &&
>> test_subcommand_called "gc --quiet" run-quiet.txt
>
> I like it. Some tweaks:
> - can simplify by using 'printf' instead of sed
> - passing the trace in stdin
> - following the convention that helpers like test_i18ngrep use of
> accepting ! as a parameter to negate the exit code
>
> That would make (untested)
>
> # Check that the given command was invoked as part of the
> # trace2-format trace on stdin.
> #
> # test_subcommand_called [!] <command> <args>... < <trace>
> #
> # For example, to look for an invocation of "git upload-pack
> # /path/to/repo"
> #
> # GIT_TRACE2_EVENT=event.log git fetch ... &&
> # test_subcommand_called git upload-pack "$PATH" <event.log
> #
> # If the first parameter passed is !, this instead checks that
> # the given command was not called.
> #
> test_subcommand_called () {
> local negate=
> if test "$1" = "!"
> then
> negate=t
> shift
> fi
>
> local expr=$(printf '"%s",' "$@")
> expr="${expr%,}"
>
> if test -n "$negate"
> then
> ! grep "\[$expr\]"
> else
> grep "\[$expr\]"
> fi
> }This works! Thanks. With the ! usage, I think a rename to 'test_subcommand' makes sense. Further, I was somehow wrong about not including "git" in the beginning, so here is my example use of this method;
test_subcommand git gc <run-no-auto.txt && test_subcommand ! git gc --auto <run-auto.txt && test_subcommand git gc --quiet <run-quiet.txt
Thanks, -Stolee