git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH 2/6] t4041, t4060: modernize test style

From
Calvin Wan <calvinwan@google.com>
Date
Feb 14, 2023, 20:22 UTC
Message-ID
<CAFySSZAYNtatNKnRuG8ZNeSr+KAU04JRMUdLe+W+eeNtzW+r=Q@mail.gmail.com>
In-Reply-To
<xmqqedqtbbf4.fsf@gitster.g>
Show 11 quoted lines
> > -test_create_repo sm1 &&
> > -add_file . foo >/dev/null
> > -
> > -head1=$(add_file sm1 foo1 foo2)
> > -fullhead1=$(cd sm1; git rev-parse --verify HEAD)
> > +test_expect_success 'setup' '
> > +     test_create_repo sm1 &&
> > +     add_file . foo >/dev/null &&
>
> Now this is inside test_expect_success, redirection to /dev/null is
> unnecessary.
ack.
Show 11 quoted lines
>
> > +     head1=$(add_file sm1 foo1 foo2) &&
> > +     fullhead1=$(cd sm1 && git rev-parse --verify HEAD)
> > +'
>
> Or "fullhead1=$(git -C sm1 rev-parse ...)".
>
> Both of the above can be ignored if we are trying to be a strict
> rewrite of the original, but moving code inside test_expect_success
> block is a large enough change that there may not be much point in
> avoiding such an obvious modernization "while at it".
I agree, will fix.
Show 41 quoted lines
>
> > -rm sm2
> > -mv sm2-bak sm2
> > -
> >  test_expect_success 'setup nested submodule' '
> > +     rm sm2 &&
> > +     mv sm2-bak sm2 &&
>
> To me, this looks more like something test_when_finished in the test
> that wanted not to have sm2 (i.e. "deleted submodule with .git file")
> should have done as part of its own clean-up.
>
> There certainly can be two schools of thought when it comes to how to
> arrange the precondition of subsequent tests.  More modern tests tend
> to clean after themselves by reverting the damage they made to the
> environment inside test_when_finished in themselves.  This one, as
> the posted patch does, goes to the other extreme and forces the
> subsequent test to undo the damage done by the previous ones.
>
> The latter approach has two major downsides.  It would not work if
> the tester wants to skip an earlier step, or if an earlier step
> failed to cause the expected damage this step wants to undo.  The
> correctness of "what we should see as sm2 here must be in sm2-bak
> because we know an earlier step should have moved it there" can
> easily be broken.  It also makes it harder to update the earlier
> step to cause different damage to the environment---the "undoing the
> damage done by the previous step(s)" done as early parts of this
> step also needs to be updated.
>
> Whichever approach we pick to use in each script, it would be better
> to stick to one philosophy, and if we can make each step revert the
> damage it caused when it is done, that would be nice.
>
> > -mv sm2-bak sm2
> > +test_expect_success 'submodule cleanup' '
> > +     mv sm2-bak sm2
> > +'
> >
> >  test_done
>
> Likewise.
ack. Swapping to test_when_finished
Previous: Junio C HamanoNext: Calvin Wan
Message 21 of 40 in “add: block invalid submodules”
  1. 0/6 add: block invalid submodulesCalvin Wan, Feb 13, 2023
  2. 1/6 leak fix: cache_put_pathCalvin Wan, Feb 13, 2023
  3. Junio C HamanoFeb 13, 2023
  4. Calvin WanFeb 14, 2023
  5. Junio C HamanoFeb 14, 2023
  6. Calvin WanFeb 14, 2023
  7. Junio C HamanoFeb 14, 2023
  8. 3/6 tests: Use `git submodule add` instead of `git add`Calvin Wan, Feb 13, 2023
  9. 4/6 tests: use `git submodule add` and fix expected diffsCalvin Wan, Feb 13, 2023
  10. Junio C HamanoFeb 13, 2023
  11. Junio C HamanoFeb 13, 2023
  12. 5/6 tests: use `git submodule add` and fix expected statusCalvin Wan, Feb 13, 2023
  13. 6/6 add: reject nested repositoriesCalvin Wan, Feb 13, 2023
  14. Jeff KingFeb 13, 2023
  15. Junio C HamanoFeb 14, 2023
  16. Jeff KingFeb 14, 2023
  17. Junio C HamanoFeb 14, 2023
  18. Calvin WanFeb 14, 2023
  19. 2/6 t4041, t4060: modernize test styleCalvin Wan, Feb 13, 2023
  20. Junio C HamanoFeb 13, 2023
  21. Calvin WanFeb 14, 2023
  22. 0/6 add: block invalid submodulesCalvin Wan, Feb 28, 2023
  23. 1/6 t4041, t4060: modernize test styleCalvin Wan, Feb 28, 2023
  24. Glen ChooMar 6, 2023
  25. Calvin WanMar 6, 2023
  26. 2/6 tests: Use `git submodule add` instead of `git add`Calvin Wan, Feb 28, 2023
  27. Junio C HamanoFeb 28, 2023
  28. Calvin WanMar 3, 2023
  29. Glen ChooMar 6, 2023
  30. 3/6 tests: use `git submodule add` and fix expected diffsCalvin Wan, Feb 28, 2023
  31. Glen ChooMar 6, 2023
  32. Junio C HamanoMar 6, 2023
  33. 4/6 tests: use `git submodule add` and fix expected statusCalvin Wan, Feb 28, 2023
  34. Glen ChooMar 7, 2023
  35. 5/6 tests: remove duplicate .gitmodules pathCalvin Wan, Feb 28, 2023
  36. Junio C HamanoFeb 28, 2023
  37. Calvin WanMar 2, 2023
  38. Glen ChooMar 7, 2023
  39. 6/6 add: reject nested repositoriesCalvin Wan, Feb 28, 2023
  40. Glen ChooMar 7, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.