Re: [PATCH 1/3] t2018: cleanup in current test
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Apr 25, 2019, 22:34 UTC
- Message-ID
- <CAPig+cTdJv9-M+zmp+Jo2bjOrkO3NgsguJ2xM+aXhf38OjjEEw@mail.gmail.com>
- In-Reply-To
- <c0c7171e3d523e5d4a0ac01810378447a38854da.1556226502.git.liu.denton@gmail.com>
On Thu, Apr 25, 2019 at 5:10 PM Denton Liu <liu.denton@gmail.com> wrote:
Show 15 quoted lines
> Before, in t2018, if do_checkout failed to create `branch2`, the next > test-case would run `git branch -D branch2` but then fail because it was > expecting `branch2` to exist, even though it doesn't. As a result, an > early failure could cause a cascading failure of tests. > > Make test-case responsible for cleaning up their own branches so that > future tests can start with a sane environment. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh > @@ -60,38 +60,36 @@ test_expect_success 'setup' ' > test_expect_success 'checkout -b to a new branch, set to HEAD' ' > + test_when_finished test_might_fail git branch -D branch2 && > + test_when_finished git checkout branch1 &&
I'm aware that when-finished actions fire in reverse order but the inherent subtlety of ordering of these two invocations still caught me off-guard for a moment since they are reverse the order in which one logically thinks about the actions which need to be performed. I wonder if it would be easier to digest if written like this:
test_when_finished '
git checkout branch1 &&
test_might_fail git branch -D branch2
' &&(Probably not worth a re-roll.)