Subject: [PATCH v2 0/8] fix test failure with busybox

From: Đoàn Trần Công Danh <[email-masked]>
Date: Sun, 22 Mar 2020 07:55:09 +0700

Despite non-compiance from busybox's sh(1), grep(1), diff(1), find(1)
Alpine Linux is still a popular choice for container these days.

Fix false-positive failure in testsuite when run in Alpine Linux.

Đoàn Trần Công Danh (8):
  t4061: use POSIX compliant regex(7)
  test-lib-functions: test_cmp: eval $GIT_TEST_CMP
  t5003: drop the subshell in test_lazy_prereq
  t5003: skip conversion test if unzip -a is unavailable
  t5616: use rev-parse instead to get HEAD's object_id
  t7063: drop non-POSIX argument "-ls" from find(1)
  t4124: fix test for non-compliant diff(1)
  t5703: feed raw data into test-tool unpack-sideband

 t/helper/test-pkt-line.c           |  2 +-
 t/t4061-diff-indent.sh             |  2 +-
 t/t4124-apply-ws-rule.sh           |  6 ++++++
 t/t5003-archive-zip.sh             | 24 ++++++++++++------------
 t/t5616-partial-clone.sh           |  2 +-
 t/t5703-upload-pack-ref-in-want.sh |  5 +----
 t/t7063-status-untracked-cache.sh  |  2 +-
 t/test-lib-functions.sh            |  2 +-
 8 files changed, 24 insertions(+), 21 deletions(-)

Range-diff against v1:
1:  4830bd3aaf ! 1:  288e343d09 t4061: use POSIX compliance regex(7)
    @@ Metadata
     Author: Đoàn Trần Công Danh <[email-masked]>
     
      ## Commit message ##
    -    t4061: use POSIX compliance regex(7)
    +    t4061: use POSIX compliant regex(7)
     
         BRE interprets `+` literally, and
         `\+` is undefined for POSIX BRE, from:
    @@ Commit message
     
         This test is failing with busybox sed, the default sed of Alpine Linux
     
    -    Fix it by using literal `+` instead.
    +    We have 2 options here:
    +
    +    - Using literal `+` because BRE will interpret it as-is, or
    +    - Using character class `[+]` to defend against a sed that expects ERE
    +
    +    ERE-expected sed is theoretical at this point,
    +    but we haven't found it, yet.
    +    And, we may run into other problems with that sed.
    +    Let's go with first option and fix it later if that sed could be found.
     
         Signed-off-by: Đoàn Trần Công Danh <[email-masked]>
     
2:  d3fafd61ec ! 2:  9d3823e849 test-lib-functions: test_cmp: eval $GIT_TEST_CMP
    @@ Commit message
         test-lib-functions: test_cmp: eval $GIT_TEST_CMP
     
         Shell recognises first non-assignment token as command name.
    -    Thus, ` cd t/perf; ./p0000-perf-lib-sanity.sh -d -i -v` reports:
    +    With /bin/sh linked to either /bin/bash or /bin/dash,
    +    `cd t/perf && ./p0000-perf-lib-sanity.sh -d -i -v` reports:
     
         > test_cmp:1: command not found: diff -u
     
-:  ---------- > 3:  8e85b5c15c t5003: drop the subshell in test_lazy_prereq
3:  ddeeefeae2 ! 4:  4f0ac0867c t5003: skip conversion test if unzip -a is unavailable
    @@ Commit message
     
      ## t/t5003-archive-zip.sh ##
     @@ t/t5003-archive-zip.sh: test_lazy_prereq UNZIP_SYMLINKS '
    - 	)
    + 	test -h symlink
      '
      
     +test_lazy_prereq UNZIP_CONVERT '
    -+	(
    -+		mkdir unzip-convert &&
    -+		cd unzip-convert &&
    -+		"$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
    -+	)
    ++	"$GIT_UNZIP" -a "$TEST_DIRECTORY"/t5003/infozip-symlinks.zip
     +'
     +
      check_zip() {
4:  ce976e850c ! 5:  ee7ef352a7 t5616: use rev-parse instead to get HEAD's object_id
    @@ t/t5616-partial-clone.sh: test_expect_success 'do partial clone 1' '
      	ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
      	test_line_count = 1 promisorlist &&
     -	git -C srv.bare rev-list HEAD >headhash &&
    -+	git -C srv.bare rev-parse HEAD >headhash &&
    ++	git -C srv.bare rev-parse --verify HEAD >headhash &&
      	grep "$(cat headhash) HEAD" $(cat promisorlist) &&
      	grep "$(cat headhash) refs/heads/master" $(cat promisorlist)
      '
5:  1993b28a12 ! 6:  59e3f73784 t7063: use POSIX find(1) syntax
    @@ Metadata
     Author: Đoàn Trần Công Danh <[email-masked]>
     
      ## Commit message ##
    -    t7063: use POSIX find(1) syntax
    +    t7063: drop non-POSIX argument "-ls" from find(1)
     
         Since commit 6b7728db81, (t7063: work around FreeBSD's lazy mtime
         update feature, 2016-08-03), we started to use ls as a trick to update
    @@ Commit message
         However, `-ls` flag isn't required by POSIX's find(1), and
         busybox(1) doesn't implement it.
     
    -    Use an equivalence `-exec ls -dils {} +` instead.
    +    From the original conversation, it seems like find(1) with "-type d"
    +    could trigger enough "lstat(2)" to ask FreeBSD update mtime.
    +
    +    Use only filter "-type d" for now.
     
         Signed-off-by: Đoàn Trần Công Danh <[email-masked]>
     
    @@ t/t7063-status-untracked-cache.sh: GIT_FORCE_UNTRACKED_CACHE=true
      
      sync_mtime () {
     -	find . -type d -ls >/dev/null
    -+	find . -type d -exec ls -dils {} + >/dev/null
    ++	find . -type d >/dev/null
      }
      
      avoid_racy() {
6:  cd86febed9 ! 7:  10f39c3d30 t4124: fix test for non-compliance diff
    @@ Metadata
     Author: Đoàn Trần Công Danh <[email-masked]>
     
      ## Commit message ##
    -    t4124: fix test for non-compliance diff
    +    t4124: fix test for non-compliant diff(1)
     
         POSIX's diff(1) requires output in normal diff format.
         However, busybox's diff's output is written in unified format.
    @@ t/t4124-apply-ws-rule.sh: test_fix () {
      
      	# find touched lines
      	$DIFF file target | sed -n -e "s/^> //p" >fixed
    ++	# busybox's diff(1) output unified format
     +	if ! test -s fixed; then
     +		$DIFF file target |
    -+		grep '^+' |
    -+		grep -v '^+++' |
    -+		sed -e "s/+//" >fixed
    ++		grep -v '^+++ target' |
    ++		sed -e "/^+/s/+//" >fixed
     +	fi
      
      	# the changed lines are all expected to change
-:  ---------- > 8:  d4507d381e t5703: feed raw data into test-tool unpack-sideband
-- 
2.26.0.rc2.310.g2932bb562d