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
}