Message ID | cd392a74acb1bc7f3b09f167278afd5959a21fca.1576583819.git.liu.denton@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | t: replace incorrect test_must_fail usage (part 1) | expand |
On Tue, Dec 17, 2019 at 7:02 AM Denton Liu <liu.denton@gmail.com> wrote: > Before, we were running `test_must_fail full_name`. However, > `test_must_fail` should only be used on git commands. Teach full_name() > to accept `!` as a potential first argument which will prepend > `test_must_fail` to the enclosed git command. This increases the > granularity of test_must_fail since it no longer runs on the `cd` as > well. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh > @@ -29,8 +29,14 @@ test_expect_success 'setup' ' > full_name () { > + fail= && > + if test "x$1" = 'x!' > + then > + fail=test_must_fail && > + shift > + fi && > (cd clone && > - git rev-parse --symbolic-full-name "$@") > + $fail git rev-parse --symbolic-full-name "$@") > } Yuck. These days this is entirely unnecessary. My suggestion is to drop the full_name() function altogether and just invoke git-rev-parse directly at the (few) call sites, taking advantage of the fact that we now have -C. So... > @@ -79,7 +85,7 @@ test_expect_success 'upstream of branch with @ at end' ' > test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' > - test_must_fail full_name refs/heads/my-side@{upstream} > + full_name ! refs/heads/my-side@{upstream} > ' This just becomes: test_must_fail git -C clone rev-parse --symbolic-full-name refs/heads/my-side@{upstream} Similarly for the other call sites. > @@ -91,9 +97,9 @@ test_expect_success 'my-side@{u} resolves to correct commit' ' > test_expect_success 'not-tracking@{u} fails' ' > - test_must_fail full_name non-tracking@{u} && > + full_name ! non-tracking@{u} && > (cd clone && git checkout --no-track -b non-tracking) && > - test_must_fail full_name non-tracking@{u} > + full_name ! non-tracking@{u} > '
diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 8b4cf8a6e3..9a941d68d8 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -29,8 +29,14 @@ test_expect_success 'setup' ' ' full_name () { + fail= && + if test "x$1" = 'x!' + then + fail=test_must_fail && + shift + fi && (cd clone && - git rev-parse --symbolic-full-name "$@") + $fail git rev-parse --symbolic-full-name "$@") } commit_subject () { @@ -79,7 +85,7 @@ test_expect_success 'upstream of branch with @ at end' ' ' test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' - test_must_fail full_name refs/heads/my-side@{upstream} + full_name ! refs/heads/my-side@{upstream} ' test_expect_success 'my-side@{u} resolves to correct commit' ' @@ -91,9 +97,9 @@ test_expect_success 'my-side@{u} resolves to correct commit' ' ' test_expect_success 'not-tracking@{u} fails' ' - test_must_fail full_name non-tracking@{u} && + full_name ! non-tracking@{u} && (cd clone && git checkout --no-track -b non-tracking) && - test_must_fail full_name non-tracking@{u} + full_name ! non-tracking@{u} ' test_expect_success '<branch>@{u}@{1} resolves correctly' '
Before, we were running `test_must_fail full_name`. However, `test_must_fail` should only be used on git commands. Teach full_name() to accept `!` as a potential first argument which will prepend `test_must_fail` to the enclosed git command. This increases the granularity of test_must_fail since it no longer runs on the `cd` as well. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t1507-rev-parse-upstream.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)