You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lib-submodule-update: use callbacks in test_submodule_switch_common()
When we run a test helper function in test_submodule_switch_common(), we
sometimes specify a whole helper function as the $command. When we do
this, in some test cases, we just mark the whole function with
`test_must_fail`. However, it's possible that the helper function might
fail earlier or later than expected due to an introduced bug. If this
happens, then the test case will still report as passing but it should
really be marked as failing since it didn't actually display the
intended behaviour.
Instead of invoking $command as one monolithic helper function, break it
up into three parts:
1. $command which is always a git command.
2. $before which is a callback function that runs just prior to
$command.
3. $after which is a callback function that runs just after
$command.
If the command requires a filename argument, specify it as `\$arg` since
that variable will be set and the whole $command string will be eval'd.
Unfortunately, there is no way to get rid of the eval as some of the
commands are passed (such as the `git pull` tests) require that no
additional arguments are passed so we must have some mechanism for the
caller to specify whether or not it wants the filename argument.
The $before and $after callback functions will be passed the filename as
the first arg. These callback functions are optional and, if missing,
will be replaced with `true`. Also, in the case where we have a
`test_must_fail` test, $after will not be executed, similar to how the
helper functions currently behave when the git command fails and exits
the &&-chain.
Finally, as an added bonus, `test_must_fail` will only run on $command
which is guaranteed to be a git command.
An alternate design was considered where the $OVERWRITING_FAIL is set
from the test_submodule_switch_common() function and passed to the
helper function. This approach was considered too difficult to
understand due to the fact that using a signalling magic environment
variable might be too indirect.
Signed-off-by: Denton Liu <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
0 commit comments