mbox series

[v3,00/12] test-lib.sh: new test_commit args, simplification & fixes

Message ID cover-00.12-0000000000-20210420T121833Z-avarab@gmail.com (mailing list archive)
Headers show
Series test-lib.sh: new test_commit args, simplification & fixes | expand

Message

Ævar Arnfjörð Bjarmason April 20, 2021, 12:21 p.m. UTC
This is a "various small fixes" series to test-lib.sh,
test-lib-functions.sh.

Since v2 the only changes are to 12/12, per SZEDER's comments we can
count on $PATH this late in test-lib.sh, so do that, and clarify the
commit message for that change per the discussion on v2.

Ævar Arnfjörð Bjarmason (12):
  check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  test-lib: bring $remove_trash out of retirement
  test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  test-lib-functions: reword "test_commit --append" docs
  test-lib-functions: document test_commit --no-tag
  test-lib functions: add an --annotated option to "test_commit"
  describe tests: convert setup to use test_commit
  test-lib functions: add --printf option to test_commit
  submodule tests: use symbolic-ref --short to discover branch name
  test-lib: reformat argument list in test_create_repo()
  test-lib: do not show advice about init.defaultBranch under --verbose
  test-lib: split up and deprecate test_create_repo()

 t/check-non-portable-shell.pl       |  2 +
 t/lib-submodule-update.sh           |  3 +-
 t/t0000-basic.sh                    |  4 --
 t/t1307-config-blob.sh              |  4 +-
 t/t1403-show-ref.sh                 |  6 +--
 t/t2030-unresolve-info.sh           |  3 +-
 t/t4006-diff-mode.sh                |  6 +--
 t/t4030-diff-textconv.sh            |  8 +---
 t/t5406-remote-rejects.sh           |  1 -
 t/t5407-post-rewrite-hook.sh        |  2 -
 t/t5409-colorize-remote-messages.sh |  1 -
 t/t5520-pull.sh                     | 10 +----
 t/t6120-describe.sh                 | 58 +++++++---------------------
 t/test-lib-functions.sh             | 60 ++++++++++++++++++-----------
 t/test-lib.sh                       | 39 +++++++++++--------
 15 files changed, 88 insertions(+), 119 deletions(-)

Range-diff against v2:
 -:  ---------- >  1:  a8b483bc77 check-non-portable-shell: check for "test <cond> -a/-o <cond>"
 -:  ---------- >  2:  39759d00ad test-lib: bring $remove_trash out of retirement
 -:  ---------- >  3:  d669ce3196 test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
 -:  ---------- >  4:  9313d35bf8 test-lib-functions: reword "test_commit --append" docs
 -:  ---------- >  5:  c916d648e4 test-lib-functions: document test_commit --no-tag
 -:  ---------- >  6:  9b6bf65ce1 test-lib functions: add an --annotated option to "test_commit"
 -:  ---------- >  7:  683b3ba3dd describe tests: convert setup to use test_commit
 -:  ---------- >  8:  dc0a863db7 test-lib functions: add --printf option to test_commit
 -:  ---------- >  9:  90bf55d2d4 submodule tests: use symbolic-ref --short to discover branch name
 -:  ---------- > 10:  e0a1e2fd52 test-lib: reformat argument list in test_create_repo()
 -:  ---------- > 11:  cedf5d383b test-lib: do not show advice about init.defaultBranch under --verbose
 1:  a3e20ef18f ! 12:  0dc0da9490 test-lib: split up and deprecate test_create_repo()
    @@ Commit message
     
         Remove various redundant or obsolete code from the test_create_repo()
         function, and split up its use in test-lib.sh from what tests need
    -    from it, leaving us with a pass-through wrapper for "git init" in
    -    test-lib-functions.sh
    +    from it.
     
    -    Reasons for why we can remove various code from test_create_repo():
    +    This leave us with a pass-through wrapper for "git init" in
    +    test-lib-functions.sh, in test-lib.sh we have the same, except for
    +    needing to redirect stdout/stderr, and emitting an error ourselves if
    +    it fails. We don't need to error() ourselves when test_create_repo()
    +    is invoked, as the invocation will be a part of a test's "&&"-chain.
    +
    +    Everything below this paragraph is a detailed summary of the history
    +    of test_create_repo() explaining why it's safe to remove the various
    +    things it was doing:
     
          1. "mkdir -p" isn't needed because "git init" itself will create
             leading directories if needed.
    @@ Commit message
          5. Since we don't need to move the .git/hooks directory we don't need
             the subshell here either.
     
    -        That wasn't really needed for the .git/hooks either, but was being
    -        done for the convenience of not having to quote the path to the
    -        repository as we moved the hooks.
    +        See 0d314ce834 for when the subshell use got introduced for the
    +        convenience of not having to "cd" back and forth while setting up
    +        the hooks.
     
          6. We can drop the --template argument and instead rely on the
             GIT_TEMPLATE_DIR set to the same path earlier in test-lib.sh. See
             8683a45d669 (Introduce GIT_TEMPLATE_DIR, 2006-12-19)
     
          7. We only needed that ">&3 2>&4" redirection when invoked from
    -        test-lib.sh, and the same goes for needing the full path to "git".
    +        test-lib.sh.
    +
    +        We could still invoke test_create_repo() there, but as the
    +        invocation is now trivial and we don't have a good reason to use
    +        test_create_repo() elsewhere let's call "git init" there
    +        ourselves.
     
    -        Let's move that special behavior into test-lib.sh itself.
    +     8. We didn't need to resolve "git" as
    +        "${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" in test_create_repo(),
    +        even for the use of test-lib.sh
     
    -    In the end it turns out that all we needed was a plain "git init"
    -    invocation.
    +        PATH is already set up in test-lib.sh to start with
    +        GIT_TEST_INSTALLED and/or GIT_EXEC_PATH before
    +        test_create_repo() (now "git init") is called.. So we can simply
    +        run "git" and rely on the PATH lookup choosing the right
    +        executable.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    @@ t/test-lib.sh: rm -fr "$TRASH_DIRECTORY" || {
      if test -z "$TEST_NO_CREATE_REPO"
      then
     -	test_create_repo "$TRASH_DIRECTORY"
    -+	"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" \
    -+		init \
    -+		"$TRASH_DIRECTORY" >&3 2>&4 ||
    ++	git init "$TRASH_DIRECTORY" >&3 2>&4 ||
     +	error "cannot run git init"
      else
      	mkdir -p "$TRASH_DIRECTORY"