All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes
@ 2021-04-12 11:08 Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/|| Ævar Arnfjörð Bjarmason
                   ` (18 more replies)
  0 siblings, 19 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

This is a "various small fixes" series to test-lib.sh,
test-lib-functions.sh.

I have a couple of outstanding patch serieses that I've pulled this
from (ab/describe-tests-fix, ab/pickaxe-pcre2), as well as some other
local work I've been having a chicken and egg problem with.

I think the approach of pulling out these various miscellaneous test
fixes into their own topic makes the most sense, I'll then submit
re-rolled versions of other topics that e.g. need these new
test_commit arguments on top of this.

Ævar Arnfjörð Bjarmason (16):
  check-non-portable-shell: complain about "test" a/-o instead of &&/||
  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-tag 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: modernize test_create_repo() function
  test-lib-functions: normalize test_path_is_missing() debugging
  test-lib-functions: use "return 1" instead of "false"
  Revert and amend "test-lib-functions: assert correct parameter count"
  test-lib-functions: remove last two parameter count assertions

 t/check-non-portable-shell.pl       |   4 +
 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             | 125 ++++++++++++++--------------
 t/test-lib.sh                       |  36 ++++----
 15 files changed, 113 insertions(+), 158 deletions(-)

-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 17:00   ` Eric Sunshine
  2021-04-12 11:08 ` [PATCH 02/16] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Expand the t/check-non-portable-shell.pl checks to complain about the
use of "-a" and "-o" to the "test" shell built-in to to mean "and" and
"or", as opposed to using two "test" invocations with "&&" or "||".

There aren't any portability issues with using that construct that I
know of, but since Junio expressed a dislike of it in [1] and we've
currently got no such constructs let's add it to the lint checking. I
had various in-flight and WIP patches that used this construct.

1. https://lore.kernel.org/git/xmqqa6qkb5fi.fsf@gitster.g/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/check-non-portable-shell.pl | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl
index fd3303552be..a5367346255 100755
--- a/t/check-non-portable-shell.pl
+++ b/t/check-non-portable-shell.pl
@@ -35,6 +35,7 @@ sub err {
 	next if $line =~ s/\\$//;
 
 	$_ = $line;
+	# Portability issues
 	/\bcp\s+-a/ and err 'cp -a is not portable';
 	/\bsed\s+-[^efn]\s+/ and err 'sed option not portable (use only -n, -e, -f)';
 	/\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)';
@@ -48,6 +49,9 @@ sub err {
 	/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
 	/^\s*([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
 		err '"FOO=bar shell_func" assignment extends beyond "shell_func"';
+	# Coding style preferences
+	/\btest\s+-[a-z]\s+.*?\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
+	/\btest\s+-[a-z]\s+.*?\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
 	$line = '';
 	# this resets our $. for each file
 	close ARGV if eof;
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 02/16] test-lib: bring $remove_trash out of retirement
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/|| Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 19:06   ` Junio C Hamano
  2021-04-12 11:08 ` [PATCH 03/16] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

There's no point in creating a repository or directory only to decide
right afterwards that we're skipping all the tests.

So let's partially revert 06478dab4c (test-lib: retire $remove_trash
variable, 2017-04-23) and move the decision about whether to skip all
tests earlier.

I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
under --debug at the end of the test, 2017-04-24) for a bug we don't
want to re-introduce.

While I'm at it let's move the HOME assignment to just before
test_create_repo, it could be lower, but it seems better to set it
before calling anything in test-lib-functions.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib.sh | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index d3f6af6a654..a8869eee58f 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1167,7 +1167,7 @@ test_done () {
 			esac
 		fi
 
-		if test -z "$debug"
+		if test -z "$debug" && test -n "$remove_trash"
 		then
 			test -d "$TRASH_DIRECTORY" ||
 			error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1332,6 +1332,21 @@ then
 	exit 1
 fi
 
+# Are we running this test at all?
+this_test=${0##*/}
+this_test=${this_test%%-*}
+if match_pattern_list "$this_test" $GIT_SKIP_TESTS
+then
+	say_color info >&3 "skipping test $this_test altogether"
+	skip_all="skip all tests in $this_test"
+	test_done
+fi
+
+# Last-minute variable setup
+HOME="$TRASH_DIRECTORY"
+GNUPGHOME="$HOME/gnupg-home-not-used"
+export HOME GNUPGHOME
+
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {
 	GIT_EXIT_OK=t
@@ -1339,10 +1354,7 @@ rm -fr "$TRASH_DIRECTORY" || {
 	exit 1
 }
 
-HOME="$TRASH_DIRECTORY"
-GNUPGHOME="$HOME/gnupg-home-not-used"
-export HOME GNUPGHOME
-
+remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
 	test_create_repo "$TRASH_DIRECTORY"
@@ -1354,15 +1366,6 @@ fi
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
 
-this_test=${0##*/}
-this_test=${this_test%%-*}
-if match_pattern_list "$this_test" $GIT_SKIP_TESTS
-then
-	say_color info >&3 "skipping test $this_test altogether"
-	skip_all="skip all tests in $this_test"
-	test_done
-fi
-
 if test -n "$write_junit_xml"
 then
 	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 03/16] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/|| Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 02/16] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 04/16] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
                   ` (15 subsequent siblings)
  18 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Stop setting the GIT_TEST_FRAMEWORK_SELFTEST variable. This was originally needed
back in 4231d1ba99 (t0000: do not get self-test disrupted by
environment warnings, 2018-09-20).

It hasn't been needed since I deleted the relevant code in test-lib.sh
in c0eedbc009 (test-lib: remove check_var_migration, 2021-02-09), I
just didn't notice that it was set here.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0000-basic.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 705d62cc27a..2c6e34b9478 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
 		passing metrics
 		'
 
-		# Tell the framework that we are self-testing to make sure
-		# it yields a stable result.
-		GIT_TEST_FRAMEWORK_SELFTEST=t &&
-
 		# Point to the t/test-lib.sh, which isn't in ../ as usual
 		. "\$TEST_DIRECTORY"/test-lib.sh
 		EOF
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 04/16] test-lib-functions: reword "test_commit --append" docs
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (2 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 03/16] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 05/16] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Reword the documentation for "test_commit --append" added in my
3373518cc8 (test-lib functions: add an --append option to test_commit,
2021-01-12).

A follow-up commit will make the "echo" part of this configurable, and
in any case saying "echo >>" rather than ">>" was redundant.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6348e8d7339..d169fb2f597 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -172,8 +172,7 @@ debug () {
 #   --notick
 #	Do not call test_tick before making a commit
 #   --append
-#	Use "echo >>" instead of "echo >" when writing "<contents>" to
-#	"<file>"
+#	Use ">>" instead of ">" when writing "<contents>" to "<file>"
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 05/16] test-lib-functions: document test_commit --no-tag
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (3 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 04/16] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 17:07   ` Eric Sunshine
  2021-04-12 11:08 ` [PATCH 06/16] test-lib functions: add an --annotated-tag option to "test_commit" Ævar Arnfjörð Bjarmason
                   ` (13 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

In 76b8b8d05c (test-lib functions: document arguments to test_commit,
2021-01-12) I added missing documentation to test_commit, but in less
than a month later in 3803a3a099 (t: add --no-tag option to
test_commit, 2021-02-09) we got another undocumented option. Let's fix
that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d169fb2f597..fa3e3e975fd 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -177,6 +177,9 @@ debug () {
 #	Invoke "git commit" with --signoff
 #   --author <author>
 #	Invoke "git commit" with --author <author>
+#   --no-tag
+#	Do not tag the resulting commit, if supplied giving the
+#	optional "<tag>" argument is an error.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 06/16] test-lib functions: add an --annotated-tag option to "test_commit"
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (4 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 05/16] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-15 15:33   ` Đoàn Trần Công Danh
  2021-04-12 11:08 ` [PATCH 07/16] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
                   ` (12 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Add an --annotated-tag option to test_commit. The tag will share the
same message as the commit, and we'll call test_tick before creating
it (unless --notick) is provided.

There's quite a few tests that could be simplified with this
construct. I've picked one to convert in this change as a
demonstration.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1403-show-ref.sh     |  6 ++----
 t/test-lib-functions.sh | 27 ++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 6ce62f878c3..17d3cc14050 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
-	git tag -f -a -m "annotated A" A &&
+	test_commit --annotate A &&
 	git checkout -b side &&
-	test_commit B &&
-	git tag -f -a -m "annotated B" B &&
+	test_commit --annotate B &&
 	git checkout main &&
 	test_commit C &&
 	git branch B A^0
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index fa3e3e975fd..a0fcc383d0b 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -180,6 +180,10 @@ debug () {
 #   --no-tag
 #	Do not tag the resulting commit, if supplied giving the
 #	optional "<tag>" argument is an error.
+#   --annotate
+#	Create an annotated tag with "--annotate -m <message>". Calls
+#	test_tick between making the commit and tag unless --notick is
+#	given.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -192,7 +196,7 @@ test_commit () {
 	author= &&
 	signoff= &&
 	indir= &&
-	no_tag= &&
+	tag=light &&
 	while test $# != 0
 	do
 		case "$1" in
@@ -220,7 +224,10 @@ test_commit () {
 			shift
 			;;
 		--no-tag)
-			no_tag=yes
+			tag=none
+			;;
+		--annotate)
+			tag=annotate
 			;;
 		*)
 			break
@@ -244,10 +251,20 @@ test_commit () {
 	git ${indir:+ -C "$indir"} commit \
 	    ${author:+ --author "$author"} \
 	    $signoff -m "$1" &&
-	if test -z "$no_tag"
-	then
+	case "$tag" in
+	none)
+		;;
+	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
-	fi
+		;;
+	annotate)
+		if test "$tag$notick" = "annotate"
+		then
+			test_tick
+		fi &&
+		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
+		;;
+	esac
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 07/16] describe tests: convert setup to use test_commit
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (5 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 06/16] test-lib functions: add an --annotated-tag option to "test_commit" Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 08/16] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Convert the setup of the describe tests to use test_commit when
possible. This makes use of the new --annotated-tag option to
test_commit.

Some of the setup here could simply be removed since the data being
created wasn't important to any of the subsequent tests, so I've done
so. E.g. assigning to the "one" variable was always useless, and just
checking that we can describe HEAD after the first commit wasn't
useful.

In the case of the "two" variable we could instead use the tag we just
created. See 5312ab11fbf (Add describe test., 2007-01-13) for the
initial version of this code. There's other cases here like redundant
"test_tick" invocations, or the simplification of not echoing "X" to a
file we're about to tag as "x", now we just use "x" in both cases.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6120-describe.sh | 58 ++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 45 deletions(-)

diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index e89b6747bee..88fddc91424 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -31,64 +31,32 @@ check_describe () {
 }
 
 test_expect_success setup '
+	test_commit initial file one &&
+	test_commit second file two &&
+	test_commit third file three &&
+	test_commit --annotate A file A &&
+	test_commit c file c &&
 
-	test_tick &&
-	echo one >file && git add file && git commit -m initial &&
-	one=$(git rev-parse HEAD) &&
-
-	git describe --always HEAD &&
-
-	test_tick &&
-	echo two >file && git add file && git commit -m second &&
-	two=$(git rev-parse HEAD) &&
-
-	test_tick &&
-	echo three >file && git add file && git commit -m third &&
-
-	test_tick &&
-	echo A >file && git add file && git commit -m A &&
-	test_tick &&
-	git tag -a -m A A &&
-
-	test_tick &&
-	echo c >file && git add file && git commit -m c &&
-	test_tick &&
-	git tag c &&
-
-	git reset --hard $two &&
-	test_tick &&
-	echo B >side && git add side && git commit -m B &&
-	test_tick &&
-	git tag -a -m B B &&
+	git reset --hard second &&
+	test_commit --annotate B side B &&
 
 	test_tick &&
 	git merge -m Merged c &&
 	merged=$(git rev-parse HEAD) &&
 
-	git reset --hard $two &&
-	test_tick &&
-	echo D >another && git add another && git commit -m D &&
-	test_tick &&
-	git tag -a -m D D &&
-	test_tick &&
-	git tag -a -m R R &&
-
-	test_tick &&
-	echo DD >another && git commit -a -m another &&
+	git reset --hard second &&
+	test_commit --no-tag D another D &&
 
 	test_tick &&
-	git tag e &&
+	git tag -a -m R R &&
 
-	test_tick &&
-	echo DDD >another && git commit -a -m "yet another" &&
+	test_commit e another DD &&
+	test_commit --no-tag "yet another" another DDD &&
 
 	test_tick &&
 	git merge -m Merged $merged &&
 
-	test_tick &&
-	echo X >file && echo X >side && git add file side &&
-	git commit -m x
-
+	test_commit --no-tag x file
 '
 
 check_describe A-* HEAD
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (6 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 07/16] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 19:05   ` Eric Sunshine
  2021-04-12 11:08 ` [PATCH 09/16] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Add a --printf option to test_commit to allow writing to the file with
"printf" instead of "echo".

This is useful for writing "\n", "\0" etc., in particular in
combination with the --append option added in 3373518cc8 (test-lib
functions: add an --append option to test_commit, 2021-01-12).

I'm converting a few tests to use the new option rather than a manual
printf/add/commit combination to demonstrate its usefulness. While I'm
at it use "test_create_repo" where appropriate, and give the
first/second commit a meaningful/more conventional log message in
cases where no test cared about that message.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1307-config-blob.sh    |  4 +---
 t/t2030-unresolve-info.sh |  3 +--
 t/t4006-diff-mode.sh      |  6 ++----
 t/t4030-diff-textconv.sh  |  8 ++------
 t/t5520-pull.sh           | 10 ++--------
 t/test-lib-functions.sh   | 12 ++++++++++--
 6 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 002e6d3388e..930dce06f0f 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
 '
 
 test_expect_success 'can parse blob ending with CR' '
-	printf "[some]key = value\\r" >config &&
-	git add config &&
-	git commit -m CR &&
+	test_commit --printf CR config "[some]key = value\\r" &&
 	echo value >expect &&
 	git config --blob=HEAD:config some.key >actual &&
 	test_cmp expect actual
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index be6c84c52a2..f691e6d9032 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
 
 test_expect_success 'rerere forget (binary)' '
 	git checkout -f side &&
-	printf "a\0c" >binary &&
-	git commit -a -m binary &&
+	test_commit --printf binary binary "a\0c" &&
 	test_must_fail git merge second &&
 	git rerere forget binary
 '
diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh
index 275ce5fa15b..6cdee2a2164 100755
--- a/t/t4006-diff-mode.sh
+++ b/t/t4006-diff-mode.sh
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
 '
 
 test_expect_success 'prepare binary file' '
-	git commit -m rezrov &&
-	printf "\00\01\02\03\04\05\06" >binbin &&
-	git add binbin &&
-	git commit -m binbin
+	git commit -m one &&
+	test_commit --printf two binbin "\00\01\02\03\04\05\06"
 '
 
 test_expect_success '--stat output after text chmod' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index c906320b60d..a39a626664d 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -26,12 +26,8 @@ EOF
 chmod +x hexdump
 
 test_expect_success 'setup binary file with history' '
-	printf "\\0\\n" >file &&
-	git add file &&
-	git commit -m one &&
-	printf "\\01\\n" >>file &&
-	git add file &&
-	git commit -m two
+	test_commit --printf one file "\\0\\n" &&
+	test_commit --printf --append two file "\\01\\n"
 '
 
 test_expect_success 'file is considered binary by porcelain' '
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a09411327f9..e2c0c510222 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 '
 
 test_expect_success 'setup for detecting upstreamed changes' '
-	mkdir src &&
-	(
-		cd src &&
-		git init &&
-		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-		git add stuff &&
-		git commit -m "Initial revision"
-	) &&
+	test_create_repo src &&
+	test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
 	git clone src dst &&
 	(
 		cd src &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index a0fcc383d0b..a90a6b2cc27 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -173,6 +173,10 @@ debug () {
 #	Do not call test_tick before making a commit
 #   --append
 #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
+#   --printf
+#       Use "printf" instead of "echo" when writing "<contents>" to
+#       "<file>". You will need to provide your own trailing "\n". You
+#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
@@ -192,6 +196,7 @@ debug () {
 
 test_commit () {
 	notick= &&
+	echo=echo &&
 	append= &&
 	author= &&
 	signoff= &&
@@ -203,6 +208,9 @@ test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--printf)
+			echo=printf
+			;;
 		--append)
 			append=yes
 			;;
@@ -239,9 +247,9 @@ test_commit () {
 	file=${2:-"$1.t"} &&
 	if test -n "$append"
 	then
-		echo "${3-$1}" >>"$indir$file"
+		$echo "${3-$1}" >>"$indir$file"
 	else
-		echo "${3-$1}" >"$indir$file"
+		$echo "${3-$1}" >"$indir$file"
 	fi &&
 	git ${indir:+ -C "$indir"} add "$file" &&
 	if test -z "$notick"
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 09/16] submodule tests: use symbolic-ref --short to discover branch name
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (7 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 08/16] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 11:08 ` [PATCH 10/16] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Change a use of $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME added in
704fed9ea22 (tests: start moving to a different default main branch
name, 2020-10-23) to simply discover the initial branch name of a
repository set up in this function with "symbolic-ref --short".

That's something done in another test in 704fed9ea22, so doing it like
this seems like an omission, or rather an overly eager
search/replacement instead of fixing the test logic.

There are only three uses of the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
variable in the test suite, this gets rid of one of those.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-submodule-update.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 4b714e93083..f7c7df0ca42 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
 	git init submodule_update_repo &&
 	(
 		cd submodule_update_repo &&
+		branch=$(git symbolic-ref --short HEAD) &&
 		echo "expect" >>.gitignore &&
 		echo "actual" >>.gitignore &&
 		echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
 		git checkout -b valid_sub1 &&
 		git revert HEAD &&
 
-		git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
+		git checkout "$branch"
 	)
 }
 
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 10/16] test-lib: reformat argument list in test_create_repo()
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (8 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 09/16] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:08 ` Ævar Arnfjörð Bjarmason
  2021-04-12 11:09 ` [PATCH 11/16] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:08 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Reformat an argument list changed in 675704c74dd (init: provide useful
advice about init.defaultBranch, 2020-12-11) to have the "-c" on the
same line as the argument it sets. This whitespace-only change makes
it easier to review a subsequent commit.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index a90a6b2cc27..674b865a20d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1258,8 +1258,8 @@ test_create_repo () {
 	mkdir -p "$repo"
 	(
 		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
-			init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
+		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
+			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 11/16] test-lib: do not show advice about init.defaultBranch under --verbose
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (9 preceding siblings ...)
  2021-04-12 11:08 ` [PATCH 10/16] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:09 ` Ævar Arnfjörð Bjarmason
  2021-04-15 19:07   ` SZEDER Gábor
  2021-04-12 11:09 ` [PATCH 12/16] test-lib: modernize test_create_repo() function Ævar Arnfjörð Bjarmason
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:09 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Arrange for the advice about naming the initial branch not to be shown
in the --verbose output of the test suite.

Since 675704c74dd (init: provide useful advice about
init.defaultBranch, 2020-12-11) some tests have been very chatty with
repeated occurrences of this multi-line advice. Having it be this
verbose isn't helpful for anyone in the context of git's own test
suite, and it makes debugging tests that use their own "git init"
invocations needlessly distracting.

By setting the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME variable early in
test-lib.sh itself we'll squash the warning not only for
test_create_repo(), as 675704c74dd explicitly intended, but also for
other "git init" invocations.

And once we'd like to have this configuration set for all "git init"
invocations in the test suite we can get rid of the init.defaultBranch
configuration setting in test_create_repo(), as
repo_default_branch_name() in refs.c will take the GIT_TEST_* variable
over it being set.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 1 -
 t/test-lib.sh           | 5 +++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 674b865a20d..c81726acb9e 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1259,7 +1259,6 @@ test_create_repo () {
 	(
 		cd "$repo" || error "Cannot setup test environment"
 		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index a8869eee58f..0057dfa69d0 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -64,6 +64,11 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 fi
 
+# Explicitly set the default branch name for testing, to avoid the
+# transitory "git init" warning under --verbose.
+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
 ################################################################
 # It appears that people try to run tests without building...
 "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 12/16] test-lib: modernize test_create_repo() function
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (10 preceding siblings ...)
  2021-04-12 11:09 ` [PATCH 11/16] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:09 ` Ævar Arnfjörð Bjarmason
  2021-04-12 19:27   ` Junio C Hamano
  2021-04-15 21:10   ` SZEDER Gábor
  2021-04-12 11:09 ` [PATCH 13/16] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
                   ` (6 subsequent siblings)
  18 siblings, 2 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:09 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Remove redundant "mkdir -p", argument number checking', test
environment sanity checking, and disabling of hooks from
test_create_repo(). As we'll see below these were all either redundant
to other test other framework code, or to changes in git itself.

Respectively:

 1. "mkdir -p" isn't needed because "git init" itself will create
    leading directories if needed.

 2. We don't need to check the number of arguments anymore, instead
    we'll feed "git init" with "$@". It will die if given too many
    arguments.

 3. We won't ever hit that "Cannot setup test environment"
    error.

    Checking the test environment sanity when doing "git init" dates
    back to eea420693be (t0000: catch trivial pilot errors.,
    2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
    was successfully created, 2006-01-05).

    We can also see it in another form a bit later in my own
    0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
    $old, 2010-08-30).

    But since 2006f0adaee (t/test-lib: make sure Git has already been
    built, 2012-09-17) we already check if we have a built git
    earlier.

    The one thing this was testing after that 2012 change was that
    we'd just built "git", but not "git-init", but since
    3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
    repositories, 2018-11-12) we invoke "git", not "git-init".

    So all of that's been checked already, and we don't need to
    re-check it here.

 4. We don't need to move .git/hooks out of the way.

    That dates back to c09a69a83e3 (Disable hooks during tests.,
    2005-10-16), since then hooks became disabled by default in
    f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).

    So the hooks were already disabled by default, but as can be seen
    from "mkdir .git/hooks" changes various tests needed to re-setup
    that directory. Now they no longer do.

 5. Since we don't need to move the .git/hooks directory we don't need
    the subshell here either.

In the end it turns out that all we needed was a plain "git init"
invocation with a custom --template directory.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5406-remote-rejects.sh           |  1 -
 t/t5407-post-rewrite-hook.sh        |  2 --
 t/t5409-colorize-remote-messages.sh |  1 -
 t/test-lib-functions.sh             | 15 +++------------
 4 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh
index ff06f99649e..5c509db6fc3 100755
--- a/t/t5406-remote-rejects.sh
+++ b/t/t5406-remote-rejects.sh
@@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	exit 1
 	EOF
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 5bb23cc3a4e..6da8d760e28 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -20,8 +20,6 @@ test_expect_success 'setup' '
 	git checkout main
 '
 
-mkdir .git/hooks
-
 cat >.git/hooks/post-rewrite <<EOF
 #!/bin/sh
 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index 5d8f401d8ec..9f1a483f426 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	echo error: error
 	echo ERROR: also highlighted
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index c81726acb9e..1258329fdd8 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1252,18 +1252,9 @@ test_atexit () {
 # Most tests can use the created repository, but some may need to create more.
 # Usage: test_create_repo <directory>
 test_create_repo () {
-	test "$#" = 1 ||
-	BUG "not 1 parameter to test-create-repo"
-	repo="$1"
-	mkdir -p "$repo"
-	(
-		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			init \
-			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
-		error "cannot run git init -- have you built things yet?"
-		mv .git/hooks .git/hooks-disabled
-	) || exit
+	"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
+		init \
+		"--template=$GIT_BUILD_DIR/templates/blt/" "$@" >&3 2>&4
 }
 
 # This function helps on symlink challenged file systems when it is not
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 13/16] test-lib-functions: normalize test_path_is_missing() debugging
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (11 preceding siblings ...)
  2021-04-12 11:09 ` [PATCH 12/16] test-lib: modernize test_create_repo() function Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:09 ` Ævar Arnfjörð Bjarmason
  2021-04-12 11:09 ` [PATCH 14/16] test-lib-functions: use "return 1" instead of "false" Ævar Arnfjörð Bjarmason
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:09 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Change the test_path_is_missing() to be consistent with related
functions. Since 2caf20c52b7 (test-lib: user-friendly alternatives to
test [-d|-f|-e], 2010-08-10) we've been ls -ld-ing the bad path and
echo-ing $* if it exists. Let's just say that it exists instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 1258329fdd8..2518a9b8274 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -811,12 +811,7 @@ test_path_is_missing () {
 	test "$#" -ne 1 && BUG "1 param"
 	if test -e "$1"
 	then
-		echo "Path exists:"
-		ls -ld "$1"
-		if test $# -ge 1
-		then
-			echo "$*"
-		fi
+		echo "Path $1 exists!"
 		false
 	fi
 }
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 14/16] test-lib-functions: use "return 1" instead of "false"
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (12 preceding siblings ...)
  2021-04-12 11:09 ` [PATCH 13/16] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:09 ` Ævar Arnfjörð Bjarmason
  2021-04-12 19:31   ` Junio C Hamano
  2021-04-12 11:09 ` [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
                   ` (4 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:09 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Change a few functions that relied on a "false" being the last
statement in the function to use an explicit "return 1" like the other
functions in this file.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 2518a9b8274..c46bf0ff09c 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -763,7 +763,7 @@ test_path_is_file () {
 	if ! test -f "$1"
 	then
 		echo "File $1 doesn't exist"
-		false
+		return 1
 	fi
 }
 
@@ -772,7 +772,7 @@ test_path_is_dir () {
 	if ! test -d "$1"
 	then
 		echo "Directory $1 doesn't exist"
-		false
+		return 1
 	fi
 }
 
@@ -781,7 +781,7 @@ test_path_exists () {
 	if ! test -e "$1"
 	then
 		echo "Path $1 doesn't exist"
-		false
+		return 1
 	fi
 }
 
@@ -803,7 +803,7 @@ test_file_not_empty () {
 	if ! test -s "$1"
 	then
 		echo "'$1' is not a non-empty file."
-		false
+		return 1
 	fi
 }
 
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (13 preceding siblings ...)
  2021-04-12 11:09 ` [PATCH 14/16] test-lib-functions: use "return 1" instead of "false" Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:09 ` Ævar Arnfjörð Bjarmason
  2021-04-12 19:37   ` Junio C Hamano
  2021-04-15 22:05   ` SZEDER Gábor
  2021-04-12 11:09 ` [PATCH 16/16] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
                   ` (3 subsequent siblings)
  18 siblings, 2 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:09 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

This reverts and amends my my own e7884b353b7 (test-lib-functions:
assert correct parameter count, 2021-02-12) in order to improve the -x
output.

When I added these BUG assertions in e7884b353b7 I missed that this
made the -x output much more verbose.

E.g. for each test_cmp invocation we'd now emit:

    + test_cmp expect actual
    + test 2 -ne 2
    + eval diff -u "$@"
    + diff -u expect actual

That "test 2 -ne 2" line is new in e7884b353b7. As noted in
45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
helper param, 2021-02-12) we had buggy invocations of some of these
functions with too many parameters.

Let's instead use "$@" instead of "$1" to achieve the same ends with
no extra -x output verbosity. The "test" operator will die with an
error if given more than one argument in these contexts, so using "$@"
achieves the same goal.

The same goes for "cmp" and "diff -u" (which we typically use for
test_cmp).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 41 ++++++++++++++++-------------------------
 1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index c46bf0ff09c..2cf72b56851 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -759,39 +759,35 @@ test_external_without_stderr () {
 # debugging-friendly alternatives to "test [-f|-d|-e]"
 # The commands test the existence or non-existence of $1
 test_path_is_file () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -f "$1"
+	if ! test -f "$@"
 	then
-		echo "File $1 doesn't exist"
+		echo "File $@ doesn't exist"
 		return 1
 	fi
 }
 
 test_path_is_dir () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -d "$1"
+	if ! test -d "$@"
 	then
-		echo "Directory $1 doesn't exist"
+		echo "Directory $@ doesn't exist"
 		return 1
 	fi
 }
 
 test_path_exists () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -e "$1"
+	if ! test -e "$@"
 	then
-		echo "Path $1 doesn't exist"
+		echo "Path $@ doesn't exist"
 		return 1
 	fi
 }
 
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_dir "$1" &&
-	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+	test_path_is_dir "$@" &&
+	if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')"
 	then
-		echo "Directory '$1' is not empty, it contains:"
+		echo "Directory '$@' is not empty, it contains:"
 		ls -la "$1"
 		return 1
 	fi
@@ -799,17 +795,15 @@ test_dir_is_empty () {
 
 # Check if the file exists and has a size greater than zero
 test_file_not_empty () {
-	test "$#" = 2 && BUG "2 param"
-	if ! test -s "$1"
+	if ! test -s "$@"
 	then
-		echo "'$1' is not a non-empty file."
+		echo "'$@' is not a non-empty file."
 		return 1
 	fi
 }
 
 test_path_is_missing () {
-	test "$#" -ne 1 && BUG "1 param"
-	if test -e "$1"
+	if test -e "$@"
 	then
 		echo "Path $1 exists!"
 		false
@@ -1013,7 +1007,6 @@ test_expect_code () {
 # - not all diff versions understand "-u"
 
 test_cmp () {
-	test "$#" -ne 2 && BUG "2 param"
 	eval "$GIT_TEST_CMP" '"$@"'
 }
 
@@ -1043,7 +1036,6 @@ test_cmp_config () {
 # test_cmp_bin - helper to compare binary files
 
 test_cmp_bin () {
-	test "$#" -ne 2 && BUG "2 param"
 	cmp "$@"
 }
 
@@ -1104,12 +1096,11 @@ verbose () {
 # otherwise.
 
 test_must_be_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_file "$1" &&
-	if test -s "$1"
+	test_path_is_file "$@" &&
+	if test -s "$@"
 	then
-		echo "'$1' is not empty, it contains:"
-		cat "$1"
+		echo "'$@' is not empty, it contains:"
+		cat "$@"
 		return 1
 	fi
 }
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 16/16] test-lib-functions: remove last two parameter count assertions
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (14 preceding siblings ...)
  2021-04-12 11:09 ` [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-12 11:09 ` Ævar Arnfjörð Bjarmason
  2021-04-12 19:40   ` Junio C Hamano
  2021-04-12 18:18 ` [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Junio C Hamano
                   ` (2 subsequent siblings)
  18 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-12 11:09 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Ævar Arnfjörð Bjarmason

Remove a couple of parameter count assertions where we'll now silently
do the wrong thing if given too many parameters, unlike the "$@" cases
in the preceding commit where "test" etc. handle the check for usi.

In the case of "test_file_size", the "test-tool" we're invoking is
happy to accept N parameters (it'll print out all N sizes). Let's just
use "$@" in that case anyway, there's only a few callers, and
eventually those should probably be moved to use the test-tool
directly.

That only leaves test_line_count, I suppose I could leave that one
alone, but since it's the only common function left that does this
assertion let's remove it for the brevity of the -x output and
consistency with other functions.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 2cf72b56851..32d6b98b972 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -822,10 +822,7 @@ test_path_is_missing () {
 # output through when the number of lines is wrong.
 
 test_line_count () {
-	if test $# != 3
-	then
-		BUG "not 3 parameters to test_line_count"
-	elif ! test $(wc -l <"$3") "$1" "$2"
+	if ! test $(wc -l <"$3") "$1" "$2"
 	then
 		echo "test_line_count: line count for $3 !$1 $2"
 		cat "$3"
@@ -834,8 +831,7 @@ test_line_count () {
 }
 
 test_file_size () {
-	test "$#" -ne 1 && BUG "1 param"
-	test-tool path-utils file-size "$1"
+	test-tool path-utils file-size "$@"
 }
 
 # Returns success if a comma separated string of keywords ($1) contains a
-- 
2.31.1.634.gb41287a30b0


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||
  2021-04-12 11:08 ` [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/|| Ævar Arnfjörð Bjarmason
@ 2021-04-12 17:00   ` Eric Sunshine
  2021-04-12 17:13     ` Matthieu Moy
  2021-04-12 18:38     ` Junio C Hamano
  0 siblings, 2 replies; 175+ messages in thread
From: Eric Sunshine @ 2021-04-12 17:00 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Git List, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 7:09 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> Expand the t/check-non-portable-shell.pl checks to complain about the
> use of "-a" and "-o" to the "test" shell built-in to to mean "and" and
> "or", as opposed to using two "test" invocations with "&&" or "||".
>
> There aren't any portability issues with using that construct that I
> know of, but since Junio expressed a dislike of it in [1] and we've
> currently got no such constructs let's add it to the lint checking. I
> had various in-flight and WIP patches that used this construct.

It's not only Junio's dislike of `-a` and `-o` but also that they have
long been considered obsolescent by POSIX[1]. GNU has likewise warned
against it[2] for a few decades.

[1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_16
[2]: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Limitations-of-Builtins.html

> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl
> @@ -35,6 +35,7 @@ sub err {
> +       # Portability issues
> @@ -48,6 +49,9 @@ sub err {
> +       # Coding style preferences

Given that these flags are considered obsolescent, thus may someday be
dropped from some implementations, these seem a better fit for the
"portability issues" section than the "coding style preferences"
section. (I'd probably just drop those section titles, though.)

> +       /\btest\s+-[a-z]\s+.*?\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
> +       /\btest\s+-[a-z]\s+.*?\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';

These will only match the simplistic forms of `test -X blah` (where
"-X" is some single letter option), but will miss expressions such as
`test "$foo" = bar`. Crafting a regex to match more generally would be
non-trivial, so this simpler match is a reasonable start. Okay.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 05/16] test-lib-functions: document test_commit --no-tag
  2021-04-12 11:08 ` [PATCH 05/16] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
@ 2021-04-12 17:07   ` Eric Sunshine
  0 siblings, 0 replies; 175+ messages in thread
From: Eric Sunshine @ 2021-04-12 17:07 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Git List, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 7:09 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> In 76b8b8d05c (test-lib functions: document arguments to test_commit,
> 2021-01-12) I added missing documentation to test_commit, but in less
> than a month later in 3803a3a099 (t: add --no-tag option to
> test_commit, 2021-02-09) we got another undocumented option. Let's fix
> that.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -177,6 +177,9 @@ debug () {
> +#   --no-tag
> +#      Do not tag the resulting commit, if supplied giving the
> +#      optional "<tag>" argument is an error.

This is difficult to understand for a native English speaker/reader
due to the comma-splice[1]. A period or semicolon in place of the
comma would fix it.

[1]: https://lore.kernel.org/git/CAPx1GvfFPWvJsj+uJV7RZrv1rgEpio=pk6rKF2UrjHebVY=LPA@mail.gmail.com/

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||
  2021-04-12 17:00   ` Eric Sunshine
@ 2021-04-12 17:13     ` Matthieu Moy
  2021-04-12 18:36       ` Junio C Hamano
  2021-04-12 18:38     ` Junio C Hamano
  1 sibling, 1 reply; 175+ messages in thread
From: Matthieu Moy @ 2021-04-12 17:13 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Ævar Arnfjörð Bjarmason, Git Mailing List,
	Junio C Hamano, Jeff King, Johannes Schindelin

"Eric Sunshine" <sunshine@sunshineco.com> wrote:

> On Mon, Apr 12, 2021 at 7:09 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
> > Expand the t/check-non-portable-shell.pl checks to complain about the
> > use of "-a" and "-o" to the "test" shell built-in to to mean "and" and
> > "or", as opposed to using two "test" invocations with "&&" or "||".

> > There aren't any portability issues with using that construct that I
> > know of, but since Junio expressed a dislike of it in [1] and we've
> > currently got no such constructs let's add it to the lint checking. I
> > had various in-flight and WIP patches that used this construct.

> It's not only Junio's dislike of `-a` and `-o` but also that they have
> long been considered obsolescent by POSIX[1]. GNU has likewise warned
> against it[2] for a few decades.

> [1]:
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_16
> [2]:
> https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Limitations-of-Builtins.html

And also in Git's Documentation/CodingGuidelines, which motivates the advice with an example:

     test -n "$x" -a "$a" = "$b"

   is buggy and breaks when $x is "=", but

     test -n "$x" && test "$a" = "$b"

   does not have such a problem.

-- 
Matthieu Moy
https://matthieu-moy.fr/

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (15 preceding siblings ...)
  2021-04-12 11:09 ` [PATCH 16/16] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
@ 2021-04-12 18:18 ` Junio C Hamano
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
  2021-04-20 12:29 ` [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  18 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 18:18 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> This is a "various small fixes" series to test-lib.sh,
> test-lib-functions.sh.
>
> I have a couple of outstanding patch serieses that I've pulled this
> from (ab/describe-tests-fix, ab/pickaxe-pcre2), as well as some other
> local work I've been having a chicken and egg problem with.
>
> I think the approach of pulling out these various miscellaneous test
> fixes into their own topic makes the most sense,...

I guess I'm expected to discard the other topics that have been
expecting rerolls from my tree to make room for this, queue this
topic and wait it to stabilize, before taking the rerools of these
other topics.

I find it a bit distracting to retract multiple topics that have
been already reviewed and reorganizing them in a new topic.  The
reviewer resource spent for the last round might not be completely
lost, but for reviewers it makes it unnecessarily harder to verify
which review comments have been addressed and which parts haven't
changed, so the net effect is to require them a fresh review anyway.
If you can entice reviewers to review this new series and making
them giving it priority over other topics in flight, that is.

> Ævar Arnfjörð Bjarmason (16):
>   check-non-portable-shell: complain about "test" a/-o instead of &&/||
>   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-tag 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: modernize test_create_repo() function
>   test-lib-functions: normalize test_path_is_missing() debugging
>   test-lib-functions: use "return 1" instead of "false"
>   Revert and amend "test-lib-functions: assert correct parameter count"
>   test-lib-functions: remove last two parameter count assertions

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||
  2021-04-12 17:13     ` Matthieu Moy
@ 2021-04-12 18:36       ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 18:36 UTC (permalink / raw)
  To: Matthieu Moy
  Cc: Eric Sunshine, Ævar Arnfjörð Bjarmason,
	Git Mailing List, Jeff King, Johannes Schindelin

Matthieu Moy <git@matthieu-moy.fr> writes:

> And also in Git's Documentation/CodingGuidelines, which motivates the advice with an example:
>
>      test -n "$x" -a "$a" = "$b"
>
>    is buggy and breaks when $x is "=", but
>
>      test -n "$x" && test "$a" = "$b"
>
>    does not have such a problem.

Good advice to cite Documentation/CodingGuidelines in the log
message.

Thanks (and nice to hear from you again ;-).


^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||
  2021-04-12 17:00   ` Eric Sunshine
  2021-04-12 17:13     ` Matthieu Moy
@ 2021-04-12 18:38     ` Junio C Hamano
  2021-04-12 18:48       ` Eric Sunshine
  1 sibling, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 18:38 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Ævar Arnfjörð Bjarmason, Git List, Jeff King,
	Matthieu Moy, Johannes Schindelin

Eric Sunshine <sunshine@sunshineco.com> writes:

> Given that these flags are considered obsolescent, thus may someday be
> dropped from some implementations, these seem a better fit for the
> "portability issues" section than the "coding style preferences"
> section. (I'd probably just drop those section titles, though.)
>
>> +       /\btest\s+-[a-z]\s+.*?\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
>> +       /\btest\s+-[a-z]\s+.*?\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
>
> These will only match the simplistic forms of `test -X blah` (where
> "-X" is some single letter option), but will miss expressions such as
> `test "$foo" = bar`. Crafting a regex to match more generally would be
> non-trivial, so this simpler match is a reasonable start. Okay.

Would it be a trivial improvement to do

    'test', followed by anything other than '&' or '|', and then
    followed by '-a' or '-o'

instead?

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/||
  2021-04-12 18:38     ` Junio C Hamano
@ 2021-04-12 18:48       ` Eric Sunshine
  0 siblings, 0 replies; 175+ messages in thread
From: Eric Sunshine @ 2021-04-12 18:48 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Ævar Arnfjörð Bjarmason, Git List, Jeff King,
	Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 2:38 PM Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> >> +       /\btest\s+-[a-z]\s+.*?\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
> >> +       /\btest\s+-[a-z]\s+.*?\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
> >
> > These will only match the simplistic forms of `test -X blah` (where
> > "-X" is some single letter option), but will miss expressions such as
> > `test "$foo" = bar`. Crafting a regex to match more generally would be
> > non-trivial, so this simpler match is a reasonable start. Okay.
>
> Would it be a trivial improvement to do
>
>     'test', followed by anything other than '&' or '|', and then
>     followed by '-a' or '-o'
>
> instead?

That seems plausible and trivial enough. In fact, I think it
eliminates a source of false-positives that Ævar's pattern can report,
such as:

    test whatever && ls -a foo

and

    test whatever && foo -o outfile

among others.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-12 11:08 ` [PATCH 08/16] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-12 19:05   ` Eric Sunshine
  2021-04-12 21:27     ` Junio C Hamano
  0 siblings, 1 reply; 175+ messages in thread
From: Eric Sunshine @ 2021-04-12 19:05 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Git List, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 7:09 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> Add a --printf option to test_commit to allow writing to the file with
> "printf" instead of "echo".
>
> This is useful for writing "\n", "\0" etc., in particular in
> combination with the --append option added in 3373518cc8 (test-lib
> functions: add an --append option to test_commit, 2021-01-12).
> [...]
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---

Just a bit of pure bikeshedding...

> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -173,6 +173,10 @@ debug () {
> +#   --printf
> +#       Use "printf" instead of "echo" when writing "<contents>" to
> +#       "<file>". You will need to provide your own trailing "\n". You
> +#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).

The name "printf" has such strong association in programmer's minds
with "%" and argument consumption that the name of this option alone
almost begs people to take advantage of argument interpolation even
though it's documented here as not allowing it. Taking into
consideration that people often do not read documentation, `--printf`
as the name of the option may be an unfortunate one. Perhaps it could
be called `--raw` or something less likely to suggest argument
interpolation.

> @@ -192,6 +196,7 @@ debug () {
>
>  test_commit () {
>         notick= &&
> +       echo=echo &&

This could be slightly confusing. I wonder if naming this variable
`emit` would be clearer.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 02/16] test-lib: bring $remove_trash out of retirement
  2021-04-12 11:08 ` [PATCH 02/16] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-04-12 19:06   ` Junio C Hamano
  2021-04-12 21:22     ` Junio C Hamano
  0 siblings, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 19:06 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> There's no point in creating a repository or directory only to decide
> right afterwards that we're skipping all the tests.
>
> So let's partially revert 06478dab4c (test-lib: retire $remove_trash
> variable, 2017-04-23) and move the decision about whether to skip all
> tests earlier.
>
> I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
> under --debug at the end of the test, 2017-04-24) for a bug we don't
> want to re-introduce.
>
> While I'm at it let's move the HOME assignment to just before
> test_create_repo, it could be lower, but it seems better to set it
> before calling anything in test-lib-functions.sh
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---

I am not clear what the reasoning behind this change is.  Is it
correct to say that the idea flows like the following?

 0. If we do the $GIT_SKIP_TESTS check early, specifically, before
    we create the trash directory to run the tests in, we do not
    have to create and then remove it.

 1. If we naïvely do the above, test_done called in the "ah, the
    entirety of test is skipped" case will try to see if the trash
    directory exists and complain, so we need to add more code in
    that test_done codepath to avoid complaints.

 2. As a part of that "more code", we mark the fact that we created
    a new repository with $remove_trash variable.

Assuming that the above flow of thought is what is behind this
patch, I think the patch is mostly sensible.

remove_trash needs to be cleared at the beginning, perhaps where
store_arg_to and opt_required_arg are cleared, though, to protect
us from a stray environment variable.

Thanks.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 12/16] test-lib: modernize test_create_repo() function
  2021-04-12 11:09 ` [PATCH 12/16] test-lib: modernize test_create_repo() function Ævar Arnfjörð Bjarmason
@ 2021-04-12 19:27   ` Junio C Hamano
  2021-04-15 11:40     ` Ævar Arnfjörð Bjarmason
  2021-04-15 21:10   ` SZEDER Gábor
  1 sibling, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 19:27 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

>  4. We don't need to move .git/hooks out of the way.

It might be unsafe to assume that we'd never have an
'enabled-by-default' hook in blt/ template directory forever,
though.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 14/16] test-lib-functions: use "return 1" instead of "false"
  2021-04-12 11:09 ` [PATCH 14/16] test-lib-functions: use "return 1" instead of "false" Ævar Arnfjörð Bjarmason
@ 2021-04-12 19:31   ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 19:31 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Change a few functions that relied on a "false" being the last
> statement in the function to use an explicit "return 1" like the other
> functions in this file.

While not wrong per-se, this and a few other changes in this series
are typical of your multi-patch series that unnecessarily consume
reviewer bandwidth that could be better spent on other more
important and correctness sensitive steps (like 07/16) in the same
series.

You should find a good balance to avoid wearing out and distracting
your reviewers---they are the most scarce resource around here that
must be shared by other people, not just with other topics of your
own.

Thanks.


^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-12 11:09 ` [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-12 19:37   ` Junio C Hamano
  2021-04-15 11:32     ` Ævar Arnfjörð Bjarmason
  2021-04-15 22:05   ` SZEDER Gábor
  1 sibling, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 19:37 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

>  test_path_is_file () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	if ! test -f "$1"
> +	if ! test -f "$@"
>  	then
> -		echo "File $1 doesn't exist"
> +		echo "File $@ doesn't exist"
>  		return 1

What does it even mean to call

	test_path_is_file Documentation/ Makefile

with this patch applied?

If there were three files "COPYING Makefile", "COPYING", and
"Makefile", what would happen when you did

	test_path_is_file COPYING Makefile

(without dq around them)?

I think this particular medicine is far worse than the symptom it
tries to cure.



^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 16/16] test-lib-functions: remove last two parameter count assertions
  2021-04-12 11:09 ` [PATCH 16/16] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
@ 2021-04-12 19:40   ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 19:40 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Remove a couple of parameter count assertions where we'll now silently
> do the wrong thing if given too many parameters, unlike the "$@" cases
> in the preceding commit where "test" etc. handle the check for usi.

What's "usi" (not a "cow", I presume)?

If test_line_count is given 2 or 4 parameters, we'd call BUG---does
that "silently do the wrong thing"?  Why?

> In the case of "test_file_size", the "test-tool" we're invoking is
> happy to accept N parameters (it'll print out all N sizes). Let's just
> use "$@" in that case anyway, there's only a few callers, and
> eventually those should probably be moved to use the test-tool
> directly.
>
> That only leaves test_line_count, I suppose I could leave that one
> alone, but since it's the only common function left that does this
> assertion let's remove it for the brevity of the -x output and
> consistency with other functions.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/test-lib-functions.sh | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 2cf72b56851..32d6b98b972 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -822,10 +822,7 @@ test_path_is_missing () {
>  # output through when the number of lines is wrong.
>  
>  test_line_count () {
> -	if test $# != 3
> -	then
> -		BUG "not 3 parameters to test_line_count"
> -	elif ! test $(wc -l <"$3") "$1" "$2"
> +	if ! test $(wc -l <"$3") "$1" "$2"
>  	then
>  		echo "test_line_count: line count for $3 !$1 $2"
>  		cat "$3"
> @@ -834,8 +831,7 @@ test_line_count () {
>  }
>  
>  test_file_size () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	test-tool path-utils file-size "$1"
> +	test-tool path-utils file-size "$@"
>  }
>  
>  # Returns success if a comma separated string of keywords ($1) contains a

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 02/16] test-lib: bring $remove_trash out of retirement
  2021-04-12 19:06   ` Junio C Hamano
@ 2021-04-12 21:22     ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 21:22 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Junio C Hamano <gitster@pobox.com> writes:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> There's no point in creating a repository or directory only to decide
>> right afterwards that we're skipping all the tests.
>>
>> So let's partially revert 06478dab4c (test-lib: retire $remove_trash
>> variable, 2017-04-23) and move the decision about whether to skip all
>> tests earlier.
>>
>> I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
>> under --debug at the end of the test, 2017-04-24) for a bug we don't
>> want to re-introduce.
>>
>> While I'm at it let's move the HOME assignment to just before
>> test_create_repo, it could be lower, but it seems better to set it
>> before calling anything in test-lib-functions.sh
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>
> I am not clear what the reasoning behind this change is.  Is it
> correct to say that the idea flows like the following?
>
>  0. If we do the $GIT_SKIP_TESTS check early, specifically, before
>     we create the trash directory to run the tests in, we do not
>     have to create and then remove it.
>
>  1. If we naïvely do the above, test_done called in the "ah, the
>     entirety of test is skipped" case will try to see if the trash
>     directory exists and complain, so we need to add more code in
>     that test_done codepath to avoid complaints.
>
>  2. As a part of that "more code", we mark the fact that we created
>     a new repository with $remove_trash variable.
>
> Assuming that the above flow of thought is what is behind this
> patch, I think the patch is mostly sensible.

By the way, I did wonder if the call to test_done is even needed, or
if it is even ready to be called (in other words, the machineries it
tries to finalize like junit and HARNESS_ACTIVE are even initialized
yet).  I verified that calling test_done this early is fine with
respect to the call it makes to finalize_junit_xml, though.

> remove_trash needs to be cleared at the beginning, perhaps where
> store_arg_to and opt_required_arg are cleared, though, to protect
> us from a stray environment variable.
>
> Thanks.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-12 19:05   ` Eric Sunshine
@ 2021-04-12 21:27     ` Junio C Hamano
  2021-04-12 23:04       ` Eric Sunshine
  0 siblings, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 21:27 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Ævar Arnfjörð Bjarmason, Git List, Jeff King,
	Matthieu Moy, Johannes Schindelin

Eric Sunshine <sunshine@sunshineco.com> writes:

> The name "printf" has such strong association in programmer's minds
> with "%" and argument consumption that the name of this option alone
> almost begs people to take advantage of argument interpolation even
> though it's documented here as not allowing it. Taking into
> consideration that people often do not read documentation, `--printf`
> as the name of the option may be an unfortunate one. Perhaps it could
> be called `--raw` or something less likely to suggest argument
> interpolation.

The reason we want to use 'printf' instead of 'echo' is because only
some implementations of 'echo' honors '\t\n\r' etc., and 'echo' by
others show these literally.  Using printf(1) allows us to write
these backslashed special characters universally.

So, I find 'raw' equally confusing, if not more.

>> @@ -192,6 +196,7 @@ debug () {
>>
>>  test_commit () {
>>         notick= &&
>> +       echo=echo &&
>
> This could be slightly confusing. I wonder if naming this variable
> `emit` would be clearer.

Perhaps.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-12 21:27     ` Junio C Hamano
@ 2021-04-12 23:04       ` Eric Sunshine
  2021-04-12 23:12         ` Junio C Hamano
  0 siblings, 1 reply; 175+ messages in thread
From: Eric Sunshine @ 2021-04-12 23:04 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Ævar Arnfjörð Bjarmason, Git List, Jeff King,
	Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 5:27 PM Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > The name "printf" has such strong association in programmer's minds
> > with "%" and argument consumption that the name of this option alone
> > almost begs people to take advantage of argument interpolation even
> > though it's documented here as not allowing it. Taking into
> > consideration that people often do not read documentation, `--printf`
> > as the name of the option may be an unfortunate one. Perhaps it could
> > be called `--raw` or something less likely to suggest argument
> > interpolation.
>
> The reason we want to use 'printf' instead of 'echo' is because only
> some implementations of 'echo' honors '\t\n\r' etc., and 'echo' by
> others show these literally.  Using printf(1) allows us to write
> these backslashed special characters universally.
>
> So, I find 'raw' equally confusing, if not more.

I don't care for `--raw` either but couldn't think of anything better
at the time. But perhaps a name such as `--allow-escapes` would be
clearer, or perhaps not. `--c-style-escapes`?

Anyhow, it's pure bikeshedding as I mentioned in my original email, so
not a big deal. I brought it up only because the very first thought
that popped into my head when reading the commit message saying it was
adding `--printf` was "oh, interesting; how do I specify the arguments
to interpolate into the `printf` format string?".

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-12 23:04       ` Eric Sunshine
@ 2021-04-12 23:12         ` Junio C Hamano
  2021-04-15 11:33           ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-12 23:12 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Ævar Arnfjörð Bjarmason, Git List, Jeff King,
	Matthieu Moy, Johannes Schindelin

Eric Sunshine <sunshine@sunshineco.com> writes:

> I don't care for `--raw` either but couldn't think of anything better
> at the time. But perhaps a name such as `--allow-escapes` would be
> clearer, or perhaps not. `--c-style-escapes`?

It's printf(1) style escapes ;-)

> Anyhow, it's pure bikeshedding as I mentioned in my original email, so
> not a big deal. I brought it up only because the very first thought
> that popped into my head when reading the commit message saying it was
> adding `--printf` was "oh, interesting; how do I specify the arguments
> to interpolate into the `printf` format string?".

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-12 19:37   ` Junio C Hamano
@ 2021-04-15 11:32     ` Ævar Arnfjörð Bjarmason
  2021-04-15 12:31       ` Andreas Schwab
  2021-04-15 18:35       ` Junio C Hamano
  0 siblings, 2 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-15 11:32 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin


On Mon, Apr 12 2021, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>>  test_path_is_file () {
>> -	test "$#" -ne 1 && BUG "1 param"
>> -	if ! test -f "$1"
>> +	if ! test -f "$@"
>>  	then
>> -		echo "File $1 doesn't exist"
>> +		echo "File $@ doesn't exist"
>>  		return 1
>
> What does it even mean to call
>
> 	test_path_is_file Documentation/ Makefile
>
> with this patch applied?
>
> If there were three files "COPYING Makefile", "COPYING", and
> "Makefile", what would happen when you did
>
> 	test_path_is_file COPYING Makefile
>
> (without dq around them)?
>
> I think this particular medicine is far worse than the symptom it
> tries to cure.

We'll error with:

    test: foo: unexpected operator

And then say:

    File COPYING Makefile doesn't exist

I thought guarding just for the one-off development error of not using
the function correctly wasn't worth it, but I thought it made sense not
to litter all of this with:
	
	diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
	index 28b8826e565..0bd7367a07e 100644
	--- a/t/test-lib-functions.sh
	+++ b/t/test-lib-functions.sh
	@@ -690,6 +690,7 @@ test_expect_success () {
	 test_path_is_file () {
	 	if ! test -f "$@"
	 	then
	+		test $# -eq 1 || BUG "Do not call test_path_is_file() with more than one argument!"
	 		echo "File $@ doesn't exist"
	 		return 1
	 	fi

But I could do that if you think it's better.

We could also just emit $1 in the "echo". I don't feel strongly about
that, but think that's arguably worse, since having it be $@ means the
developer is more likely to notice the invalid usage right away.
	

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-12 23:12         ` Junio C Hamano
@ 2021-04-15 11:33           ` Ævar Arnfjörð Bjarmason
  2021-04-15 14:52             ` Eric Sunshine
  0 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-15 11:33 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Eric Sunshine, Git List, Jeff King, Matthieu Moy, Johannes Schindelin


On Tue, Apr 13 2021, Junio C Hamano wrote:

> Eric Sunshine <sunshine@sunshineco.com> writes:
>
>> I don't care for `--raw` either but couldn't think of anything better
>> at the time. But perhaps a name such as `--allow-escapes` would be
>> clearer, or perhaps not. `--c-style-escapes`?
>
> It's printf(1) style escapes ;-)
>
>> Anyhow, it's pure bikeshedding as I mentioned in my original email, so
>> not a big deal. I brought it up only because the very first thought
>> that popped into my head when reading the commit message saying it was
>> adding `--printf` was "oh, interesting; how do I specify the arguments
>> to interpolate into the `printf` format string?".

So, the conclusion of this thread is let's keep it as --printf?

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 12/16] test-lib: modernize test_create_repo() function
  2021-04-12 19:27   ` Junio C Hamano
@ 2021-04-15 11:40     ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-15 11:40 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin


On Mon, Apr 12 2021, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>>  4. We don't need to move .git/hooks out of the way.
>
> It might be unsafe to assume that we'd never have an
> 'enabled-by-default' hook in blt/ template directory forever,
> though.

I would think that if we injected run-by-default hooks into the
top-level repo creation any such breakage in the test suite would be a
feature, i.e. we'd want to see and adjust for the breakage, because
surely the same sort of breakage would occur in the wild.

FWIW I've got some WIP local patches for the "just ship a README in
hooks/":
https://lore.kernel.org/git/20180601070609.GC15578@sigill.intra.peff.net/

From memory the cumultive footprint of foot a -d run on the whole test
suite is on the order of ~1GB, and ~100MB is just the hooks over and
over again...

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-15 11:32     ` Ævar Arnfjörð Bjarmason
@ 2021-04-15 12:31       ` Andreas Schwab
  2021-04-15 18:35       ` Junio C Hamano
  1 sibling, 0 replies; 175+ messages in thread
From: Andreas Schwab @ 2021-04-15 12:31 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Junio C Hamano, git, Jeff King, Matthieu Moy, Johannes Schindelin

On Apr 15 2021, Ævar Arnfjörð Bjarmason wrote:

> On Mon, Apr 12 2021, Junio C Hamano wrote:
>
>> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>>
>>>  test_path_is_file () {
>>> -	test "$#" -ne 1 && BUG "1 param"
>>> -	if ! test -f "$1"
>>> +	if ! test -f "$@"
>>>  	then
>>> -		echo "File $1 doesn't exist"
>>> +		echo "File $@ doesn't exist"
>>>  		return 1
>>
>> What does it even mean to call
>>
>> 	test_path_is_file Documentation/ Makefile
>>
>> with this patch applied?
>>
>> If there were three files "COPYING Makefile", "COPYING", and
>> "Makefile", what would happen when you did
>>
>> 	test_path_is_file COPYING Makefile
>>
>> (without dq around them)?
>>
>> I think this particular medicine is far worse than the symptom it
>> tries to cure.
>
> We'll error with:
>
>     test: foo: unexpected operator

If you want a single argument you should use "$*", not "$@".

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-15 11:33           ` Ævar Arnfjörð Bjarmason
@ 2021-04-15 14:52             ` Eric Sunshine
  2021-04-15 18:37               ` Junio C Hamano
  0 siblings, 1 reply; 175+ messages in thread
From: Eric Sunshine @ 2021-04-15 14:52 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Junio C Hamano, Git List, Jeff King, Matthieu Moy, Johannes Schindelin

On Thu, Apr 15, 2021 at 7:33 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Tue, Apr 13 2021, Junio C Hamano wrote:
> > Eric Sunshine <sunshine@sunshineco.com> writes:
> >> I don't care for `--raw` either but couldn't think of anything better
> >> at the time. But perhaps a name such as `--allow-escapes` would be
> >> clearer, or perhaps not. `--c-style-escapes`?
> >
> > It's printf(1) style escapes ;-)
> >
> So, the conclusion of this thread is let's keep it as --printf?

It was bikeshedding on my part, so I don't feel strongly. As
mentioned, I only brought it up because my first thought was to wonder
how interpolation would work. One might suggest --printf-escapes or
--string-escapes but the audience for this is so narrow (Git
developers) that the short and concise --printf is probably
preferable.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 06/16] test-lib functions: add an --annotated-tag option to "test_commit"
  2021-04-12 11:08 ` [PATCH 06/16] test-lib functions: add an --annotated-tag option to "test_commit" Ævar Arnfjörð Bjarmason
@ 2021-04-15 15:33   ` Đoàn Trần Công Danh
  0 siblings, 0 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-04-15 15:33 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On 2021-04-12 13:08:55+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>  	git branch B A^0
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index fa3e3e975fd..a0fcc383d0b 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -180,6 +180,10 @@ debug () {
>  #   --no-tag
>  #	Do not tag the resulting commit, if supplied giving the
>  #	optional "<tag>" argument is an error.

This comment applied to previous patch, but I think we need this patch
to justify for optional "<tag>" argument is an error for "--no-tag"

----8<----
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index a0fcc383d0..ed0a4e5e5d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -253,6 +253,10 @@ test_commit () {
 	    $signoff -m "$1" &&
 	case "$tag" in
 	none)
+		if test -z "$4"
+		then
+			BUG "<tag> given to test_commit --no-tag"
+		fi
 		;;
 	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
----8<----
> +#   --annotate
> +#	Create an annotated tag with "--annotate -m <message>". Calls
> +#	test_tick between making the commit and tag unless --notick is
> +#	given.
>  #
>  # This will commit a file with the given contents and the given commit
>  # message, and tag the resulting commit with the given tag name.
> @@ -192,7 +196,7 @@ test_commit () {
>  	author= &&
>  	signoff= &&
>  	indir= &&
> -	no_tag= &&
> +	tag=light &&
>  	while test $# != 0
>  	do
>  		case "$1" in
> @@ -220,7 +224,10 @@ test_commit () {
>  			shift
>  			;;
>  		--no-tag)
> -			no_tag=yes
> +			tag=none
> +			;;
> +		--annotate)
> +			tag=annotate
>  			;;
>  		*)
>  			break
> @@ -244,10 +251,20 @@ test_commit () {
>  	git ${indir:+ -C "$indir"} commit \
>  	    ${author:+ --author "$author"} \
>  	    $signoff -m "$1" &&
> -	if test -z "$no_tag"
> -	then
> +	case "$tag" in
> +	none)
> +		;;
> +	light)
>  		git ${indir:+ -C "$indir"} tag "${4:-$1}"
> -	fi
> +		;;
> +	annotate)
> +		if test "$tag$notick" = "annotate"

Perhap I'm missing something, however, I couldn't get the reason for
inserting "$tag" here. I wonder what wrong with:

	if test -z "$notick"
	then
		test_tick
	fi &&

> +		then
> +			test_tick
> +		fi &&
> +		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
> +		;;
> +	esac
>  }
>  
>  # Call test_merge with the arguments "<message> <commit>", where <commit>
> -- 
> 2.31.1.634.gb41287a30b0
> 

-- 
Danh

^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-15 11:32     ` Ævar Arnfjörð Bjarmason
  2021-04-15 12:31       ` Andreas Schwab
@ 2021-04-15 18:35       ` Junio C Hamano
  2021-04-16 21:06         ` Ævar Arnfjörð Bjarmason
  1 sibling, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-15 18:35 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> On Mon, Apr 12 2021, Junio C Hamano wrote:
>
>> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>>
>>>  test_path_is_file () {
>>> -	test "$#" -ne 1 && BUG "1 param"
>>> -	if ! test -f "$1"
>>> +	if ! test -f "$@"
>>>  	then
>>> -		echo "File $1 doesn't exist"
>>> +		echo "File $@ doesn't exist"
>>>  		return 1
>>
>> What does it even mean to call
>>
>> 	test_path_is_file Documentation/ Makefile
>>
>> with this patch applied?
>>
>> If there were three files "COPYING Makefile", "COPYING", and
>> "Makefile", what would happen when you did
>>
>> 	test_path_is_file COPYING Makefile
>>
>> (without dq around them)?
>>
>> I think this particular medicine is far worse than the symptom it
>> tries to cure.
>
> We'll error with:
>
>     test: foo: unexpected operator

Ah, so use of "$@" was intentional.  That's clever (I thought it was
a common typo people make when they mean "$*").

Of course, it would not work if the caller did a nonsense like so:

	test_path_is_file foo -o ok

but as long as we trust that the callers would not make stupid
mistakes, this is OK.  Is that the reasoning behind this removal of
the BUG?

> I thought guarding just for the one-off development error of not using
> the function correctly wasn't worth it, but I thought it made sense not
> to litter all of this with:
> 	
> 	diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> 	index 28b8826e565..0bd7367a07e 100644
> 	--- a/t/test-lib-functions.sh
> 	+++ b/t/test-lib-functions.sh
> 	@@ -690,6 +690,7 @@ test_expect_success () {
> 	 test_path_is_file () {
> 	 	if ! test -f "$@"
> 	 	then
> 	+		test $# -eq 1 || BUG "Do not call test_path_is_file() with more than one argument!"

But this breaks our assumption that the caller would not be making
stupid mistakes, so I am not sure if it is worth it.  If we were to
have a sanity check, shouldn't we do the check upfront, like the
original?

Thanks.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 08/16] test-lib functions: add --printf option to test_commit
  2021-04-15 14:52             ` Eric Sunshine
@ 2021-04-15 18:37               ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-15 18:37 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Ævar Arnfjörð Bjarmason, Git List, Jeff King,
	Matthieu Moy, Johannes Schindelin

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Thu, Apr 15, 2021 at 7:33 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> On Tue, Apr 13 2021, Junio C Hamano wrote:
>> > Eric Sunshine <sunshine@sunshineco.com> writes:
>> >> I don't care for `--raw` either but couldn't think of anything better
>> >> at the time. But perhaps a name such as `--allow-escapes` would be
>> >> clearer, or perhaps not. `--c-style-escapes`?
>> >
>> > It's printf(1) style escapes ;-)
>> >
>> So, the conclusion of this thread is let's keep it as --printf?
>
> It was bikeshedding on my part, so I don't feel strongly. As
> mentioned, I only brought it up because my first thought was to wonder
> how interpolation would work. One might suggest --printf-escapes or
> --string-escapes but the audience for this is so narrow (Git
> developers) that the short and concise --printf is probably
> preferable.

After seeing you raised the issue, I wish we had a better option
name than --printf to be even more clear, but the wish is not strong
enough to make me say "let's stop until we come up with the perfect
name".  I am OK with --printf

Thanks.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 11/16] test-lib: do not show advice about init.defaultBranch under --verbose
  2021-04-12 11:09 ` [PATCH 11/16] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
@ 2021-04-15 19:07   ` SZEDER Gábor
  0 siblings, 0 replies; 175+ messages in thread
From: SZEDER Gábor @ 2021-04-15 19:07 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 01:09:00PM +0200, Ævar Arnfjörð Bjarmason wrote:
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 674b865a20d..c81726acb9e 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1259,7 +1259,6 @@ test_create_repo () {
>  	(
>  		cd "$repo" || error "Cannot setup test environment"
>  		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
> -			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
>  			init \

This change got my hopes up that

  GIT_TEST_INSTALLED=/.../v1.6.0/bin ./t9999-foo.sh

will work again (it didn't yet support 'git init -c <...>'), but,
alas, already the next patch will turn this into 'git init ...
<trash-dir>', and v1.6.0 didn't support that, either, so it will
remain broken...  Oh, well.

>  			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
>  		error "cannot run git init -- have you built things yet?"
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index a8869eee58f..0057dfa69d0 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -64,6 +64,11 @@ then
>  	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
>  fi
>  
> +# Explicitly set the default branch name for testing, to avoid the
> +# transitory "git init" warning under --verbose.
> +: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
> +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
> +
>  ################################################################
>  # It appears that people try to run tests without building...
>  "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
> -- 
> 2.31.1.634.gb41287a30b0
> 

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 12/16] test-lib: modernize test_create_repo() function
  2021-04-12 11:09 ` [PATCH 12/16] test-lib: modernize test_create_repo() function Ævar Arnfjörð Bjarmason
  2021-04-12 19:27   ` Junio C Hamano
@ 2021-04-15 21:10   ` SZEDER Gábor
  2021-04-16 21:22     ` SZEDER Gábor
  2021-04-16 23:38     ` Ævar Arnfjörð Bjarmason
  1 sibling, 2 replies; 175+ messages in thread
From: SZEDER Gábor @ 2021-04-15 21:10 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 01:09:01PM +0200, Ævar Arnfjörð Bjarmason wrote:
> Remove redundant "mkdir -p", argument number checking', test
> environment sanity checking, and disabling of hooks from
> test_create_repo(). As we'll see below these were all either redundant
> to other test other framework code, or to changes in git itself.
> 
> Respectively:
> 
>  1. "mkdir -p" isn't needed because "git init" itself will create
>     leading directories if needed.
> 
>  2. We don't need to check the number of arguments anymore, instead
>     we'll feed "git init" with "$@". It will die if given too many
>     arguments.

Or it will succeed if invoked as e.g. 'test_create_repo --bare repo'.

>  3. We won't ever hit that "Cannot setup test environment"
>     error.

ENOSPC?  Some rogue background process on Windows still desperately
clinging to an open file descriptor to some file in the same
directory, preventing 'rm -rf "$TRASH_DIRECTORY"' near the beginning
of 'test-lib.sh' and interfering with 'git init'?

>     Checking the test environment sanity when doing "git init" dates
>     back to eea420693be (t0000: catch trivial pilot errors.,
>     2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
>     was successfully created, 2006-01-05).
> 
>     We can also see it in another form a bit later in my own
>     0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
>     $old, 2010-08-30).
> 
>     But since 2006f0adaee (t/test-lib: make sure Git has already been
>     built, 2012-09-17) we already check if we have a built git
>     earlier.
> 
>     The one thing this was testing after that 2012 change was that
>     we'd just built "git", but not "git-init", but since
>     3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
>     repositories, 2018-11-12) we invoke "git", not "git-init".
> 
>     So all of that's been checked already, and we don't need to
>     re-check it here.

I agree that if we already have a 'git' binary that can run 'git
version', then we can safely assume that it will be able to run 'git
init' as well.  It might be that 'git init' is buggy and segfaults,
but that is not a "have you built things yet?" kind of error.

>  4. We don't need to move .git/hooks out of the way.
> 
>     That dates back to c09a69a83e3 (Disable hooks during tests.,
>     2005-10-16), since then hooks became disabled by default in
>     f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).
> 
>     So the hooks were already disabled by default, but as can be seen
>     from "mkdir .git/hooks" changes various tests needed to re-setup
>     that directory. Now they no longer do.
> 
>  5. Since we don't need to move the .git/hooks directory we don't need
>     the subshell here either.

We needed the subshell because we changed directory in
'test_create_repo' (even you referenced 0d314ce834d above), not
because we moved the hooks directory.

> In the end it turns out that all we needed was a plain "git init"
> invocation with a custom --template directory.

We don't need '--template', either; see below.

> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index c81726acb9e..1258329fdd8 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1252,18 +1252,9 @@ test_atexit () {
>  # Most tests can use the created repository, but some may need to create more.
>  # Usage: test_create_repo <directory>
>  test_create_repo () {
> -	test "$#" = 1 ||
> -	BUG "not 1 parameter to test-create-repo"
> -	repo="$1"
> -	mkdir -p "$repo"
> -	(
> -		cd "$repo" || error "Cannot setup test environment"
> -		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
> -			init \
> -			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
> -		error "cannot run git init -- have you built things yet?"
> -		mv .git/hooks .git/hooks-disabled
> -	) || exit

This patch removes this '|| exit', which is...

  - good: if 'test_create_repo' is invoked in a test case (and not in
    a subshell) and if it were to fail for some reason, then it won't
    abort the whole test script, but will fail only that test case.

  - bad: 'test_create_repo' is responsible for creating the repository
    in the trash directory as well; if that were to fail for any
    reason, then the test script will not be aborted early.

I think the 'exit' on error should be removed from 'test_create_repo',
but the callsite in 'test-lib.sh' should become 'test_create_repo ||
exit 1'.

In any case, removing this '|| exit' is not mentioned in the commit
message.

> +	"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \

PATH is already set up to start with GIT_TEST_INSTALLED and/or
GIT_EXEC_PATH before 'test_create_repo' is called to init the repo in
the trash directory, so we could simply run 'git' and rely on PATH
lookup choosing the right executable.

> +		init \
> +		"--template=$GIT_BUILD_DIR/templates/blt/" "$@" >&3 2>&4

Likewise, GIT_TEMPLATE_DIR is already set up to the same value as in
this '--template=...' option, so we could omit this option as well.

And after that all that would remain in this function is:

  git init "$1" >&3 2>&4

And those redirections are only needed when this function is called to
initialize the repo in the trash directory, but not when it creates a
repo in a test case.  This makes me question the value of having this
'test_create_repo' helper function at all; there are already over 800
cases where we run plain 'git init' outside of 't0001-init.sh' instead
of 'test_create_repo', though removing it would be definitely cause
some churn with over 300 callsites.



>  }
>  
>  # This function helps on symlink challenged file systems when it is not
> -- 
> 2.31.1.634.gb41287a30b0
> 

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-12 11:09 ` [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
  2021-04-12 19:37   ` Junio C Hamano
@ 2021-04-15 22:05   ` SZEDER Gábor
  2021-04-15 22:24     ` Junio C Hamano
  2021-04-16 23:48     ` Ævar Arnfjörð Bjarmason
  1 sibling, 2 replies; 175+ messages in thread
From: SZEDER Gábor @ 2021-04-15 22:05 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On Mon, Apr 12, 2021 at 01:09:04PM +0200, Ævar Arnfjörð Bjarmason wrote:
> This reverts and amends my my own e7884b353b7 (test-lib-functions:
> assert correct parameter count, 2021-02-12) in order to improve the -x
> output.
> 
> When I added these BUG assertions in e7884b353b7 I missed that this
> made the -x output much more verbose.
> 
> E.g. for each test_cmp invocation we'd now emit:
> 
>     + test_cmp expect actual
>     + test 2 -ne 2
>     + eval diff -u "$@"
>     + diff -u expect actual
> 
> That "test 2 -ne 2" line is new in e7884b353b7. As noted in
> 45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
> helper param, 2021-02-12) we had buggy invocations of some of these
> functions with too many parameters.
> 
> Let's instead use "$@" instead of "$1" to achieve the same ends with
> no extra -x output verbosity. The "test" operator will die with an
> error if given more than one argument in these contexts, so using "$@"
> achieves the same goal.

I prefer the current check for its explicitness over the implicit and
somewhat cryptic approach introduced in this patch.  I hope that
sooner or later I'll finish up my patch series to suppress '-x' output
from test helper functions, and then this issue will become moot
anyway.

> The same goes for "cmp" and "diff -u" (which we typically use for
> test_cmp).
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/test-lib-functions.sh | 41 ++++++++++++++++-------------------------
>  1 file changed, 16 insertions(+), 25 deletions(-)
> 
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index c46bf0ff09c..2cf72b56851 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -759,39 +759,35 @@ test_external_without_stderr () {
>  # debugging-friendly alternatives to "test [-f|-d|-e]"
>  # The commands test the existence or non-existence of $1
>  test_path_is_file () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	if ! test -f "$1"
> +	if ! test -f "$@"
>  	then
> -		echo "File $1 doesn't exist"
> +		echo "File $@ doesn't exist"
>  		return 1
>  	fi
>  }
>  
>  test_path_is_dir () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	if ! test -d "$1"
> +	if ! test -d "$@"
>  	then
> -		echo "Directory $1 doesn't exist"
> +		echo "Directory $@ doesn't exist"
>  		return 1
>  	fi
>  }
>  
>  test_path_exists () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	if ! test -e "$1"
> +	if ! test -e "$@"
>  	then
> -		echo "Path $1 doesn't exist"
> +		echo "Path $@ doesn't exist"
>  		return 1
>  	fi
>  }
>  
>  # Check if the directory exists and is empty as expected, barf otherwise.
>  test_dir_is_empty () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	test_path_is_dir "$1" &&
> -	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
> +	test_path_is_dir "$@" &&
> +	if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')"
>  	then
> -		echo "Directory '$1' is not empty, it contains:"
> +		echo "Directory '$@' is not empty, it contains:"
>  		ls -la "$1"
>  		return 1
>  	fi
> @@ -799,17 +795,15 @@ test_dir_is_empty () {
>  
>  # Check if the file exists and has a size greater than zero
>  test_file_not_empty () {
> -	test "$#" = 2 && BUG "2 param"
> -	if ! test -s "$1"
> +	if ! test -s "$@"
>  	then
> -		echo "'$1' is not a non-empty file."
> +		echo "'$@' is not a non-empty file."
>  		return 1
>  	fi
>  }
>  
>  test_path_is_missing () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	if test -e "$1"
> +	if test -e "$@"
>  	then
>  		echo "Path $1 exists!"
>  		false
> @@ -1013,7 +1007,6 @@ test_expect_code () {
>  # - not all diff versions understand "-u"
>  
>  test_cmp () {
> -	test "$#" -ne 2 && BUG "2 param"
>  	eval "$GIT_TEST_CMP" '"$@"'
>  }
>  
> @@ -1043,7 +1036,6 @@ test_cmp_config () {
>  # test_cmp_bin - helper to compare binary files
>  
>  test_cmp_bin () {
> -	test "$#" -ne 2 && BUG "2 param"
>  	cmp "$@"
>  }
>  
> @@ -1104,12 +1096,11 @@ verbose () {
>  # otherwise.
>  
>  test_must_be_empty () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	test_path_is_file "$1" &&
> -	if test -s "$1"
> +	test_path_is_file "$@" &&
> +	if test -s "$@"
>  	then
> -		echo "'$1' is not empty, it contains:"
> -		cat "$1"
> +		echo "'$@' is not empty, it contains:"
> +		cat "$@"
>  		return 1
>  	fi
>  }
> -- 
> 2.31.1.634.gb41287a30b0
> 

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-15 22:05   ` SZEDER Gábor
@ 2021-04-15 22:24     ` Junio C Hamano
  2021-04-16 23:48     ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-15 22:24 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: Ævar Arnfjörð Bjarmason, git, Jeff King,
	Matthieu Moy, Johannes Schindelin

SZEDER Gábor <szeder.dev@gmail.com> writes:

> ...  suppress '-x' output
> from test helper functions, and then this issue will become moot
> anyway.

That is certainly a better approach than tweaking each call site of
BUG.

The interface to BUG is "write a code to determine condition and
then die by calling BUG", which means under '-x' you are bound to
see the trace from "code to determine condition" part.

I wonder if introducing a BUG_ON helper function that

 - turns off '-x' trace upon entry;
 - takes a condition as one of its arguments and evals it;
 - issues a message and dies if needed;
 - otherwise arranges to turn '-x' trace on and return.

would solve it well?

Thanks.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-15 18:35       ` Junio C Hamano
@ 2021-04-16 21:06         ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-16 21:06 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin


On Thu, Apr 15 2021, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>
>> On Mon, Apr 12 2021, Junio C Hamano wrote:
>>
>>> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>>>
>>>>  test_path_is_file () {
>>>> -	test "$#" -ne 1 && BUG "1 param"
>>>> -	if ! test -f "$1"
>>>> +	if ! test -f "$@"
>>>>  	then
>>>> -		echo "File $1 doesn't exist"
>>>> +		echo "File $@ doesn't exist"
>>>>  		return 1
>>>
>>> What does it even mean to call
>>>
>>> 	test_path_is_file Documentation/ Makefile
>>>
>>> with this patch applied?
>>>
>>> If there were three files "COPYING Makefile", "COPYING", and
>>> "Makefile", what would happen when you did
>>>
>>> 	test_path_is_file COPYING Makefile
>>>
>>> (without dq around them)?
>>>
>>> I think this particular medicine is far worse than the symptom it
>>> tries to cure.
>>
>> We'll error with:
>>
>>     test: foo: unexpected operator
>
> Ah, so use of "$@" was intentional.  That's clever (I thought it was
> a common typo people make when they mean "$*").
>
> Of course, it would not work if the caller did a nonsense like so:
>
> 	test_path_is_file foo -o ok
>
> but as long as we trust that the callers would not make stupid
> mistakes, this is OK.  Is that the reasoning behind this removal of
> the BUG?

The reasoning is to get rid of verbosity in the trace output, while
still effectively retaining the error checking.

Yes you could do "foo -o ok", but as my already-on-master fixes to the
few misuses showed we only realistically have to worry about them being
used with many normal looking file names (if that).

>> I thought guarding just for the one-off development error of not using
>> the function correctly wasn't worth it, but I thought it made sense not
>> to litter all of this with:
>> 	
>> 	diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
>> 	index 28b8826e565..0bd7367a07e 100644
>> 	--- a/t/test-lib-functions.sh
>> 	+++ b/t/test-lib-functions.sh
>> 	@@ -690,6 +690,7 @@ test_expect_success () {
>> 	 test_path_is_file () {
>> 	 	if ! test -f "$@"
>> 	 	then
>> 	+		test $# -eq 1 || BUG "Do not call test_path_is_file() with more than one argument!"
>
> But this breaks our assumption that the caller would not be making
> stupid mistakes, so I am not sure if it is worth it.  If we were to
> have a sanity check, shouldn't we do the check upfront, like the
> original?

It's fine to do sanity checking if it's in the "else" branch where we're
already emitting an error, and we only do so in the BUG case.

I.e. if it's written like e.g. this:
	
	test_path_is_file () {
		if test $# -ne 1
		then
			BUG "Do not call test_path_is_file() with more than one argument!"
		elif ! test -f "$@"
		then
			echo "File $@ doesn't exist"

Then with e.g.:

    ./t3600-rm.sh  --run=1-3 -vx

We get:
	
	+ test_path_is_file foo
	+ test 1 -ne 1
	+ test -f foo
	+ git ls-files --error-unmatch foo

But if we, as my patch does, piggy-pack on the test-built in to panic on
too many arguments we get the much more succinct:
	
	+ test_path_is_file foo
	+ test -f foo
	+ git ls-files --error-unmatch foo

I think that's the only trace output that matters, having "test 2 -ne 1"
or whatever in the case where we're just about to invoke BUG anyway is
fine.



	

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 12/16] test-lib: modernize test_create_repo() function
  2021-04-15 21:10   ` SZEDER Gábor
@ 2021-04-16 21:22     ` SZEDER Gábor
  2021-04-16 23:38     ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 175+ messages in thread
From: SZEDER Gábor @ 2021-04-16 21:22 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin

On Thu, Apr 15, 2021 at 11:10:13PM +0200, SZEDER Gábor wrote:
> >  3. We won't ever hit that "Cannot setup test environment"
> >     error.
> 
> ENOSPC?  Some rogue background process on Windows still desperately
> clinging to an open file descriptor to some file in the same
> directory, preventing 'rm -rf "$TRASH_DIRECTORY"' near the beginning
> of 'test-lib.sh' and interfering with 'git init'?
> 
> >     Checking the test environment sanity when doing "git init" dates
> >     back to eea420693be (t0000: catch trivial pilot errors.,
> >     2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
> >     was successfully created, 2006-01-05).
> > 
> >     We can also see it in another form a bit later in my own
> >     0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
> >     $old, 2010-08-30).
> > 
> >     But since 2006f0adaee (t/test-lib: make sure Git has already been
> >     built, 2012-09-17) we already check if we have a built git
> >     earlier.
> > 
> >     The one thing this was testing after that 2012 change was that
> >     we'd just built "git", but not "git-init", but since
> >     3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
> >     repositories, 2018-11-12) we invoke "git", not "git-init".
> > 
> >     So all of that's been checked already, and we don't need to
> >     re-check it here.
> 
> I agree that if we already have a 'git' binary that can run 'git
> version', then we can safely assume that it will be able to run 'git
> init' as well.  It might be that 'git init' is buggy and segfaults,
> but that is not a "have you built things yet?" kind of error.

> > -	mkdir -p "$repo"
> > -	(
> > -		cd "$repo" || error "Cannot setup test environment"
> > -		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
> > -			init \
> > -			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
> > -		error "cannot run git init -- have you built things yet?"
> > -		mv .git/hooks .git/hooks-disabled
> > -	) || exit
> 
> This patch removes this '|| exit', which is...
> 
>   - good: if 'test_create_repo' is invoked in a test case (and not in
>     a subshell) and if it were to fail for some reason, then it won't
>     abort the whole test script, but will fail only that test case.
> 
>   - bad: 'test_create_repo' is responsible for creating the repository
>     in the trash directory as well; if that were to fail for any
>     reason, then the test script will not be aborted early.
> 
> I think the 'exit' on error should be removed from 'test_create_repo',
> but the callsite in 'test-lib.sh' should become 'test_create_repo ||
> exit 1'.

Case in point: the bug I just reported in

  https://public-inbox.org/git/20210416211451.GP2947267@szeder.dev/

does break Git in a way that in one of our CI jobs 'git init' is
unable to create the repository in the trash directory.


^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 12/16] test-lib: modernize test_create_repo() function
  2021-04-15 21:10   ` SZEDER Gábor
  2021-04-16 21:22     ` SZEDER Gábor
@ 2021-04-16 23:38     ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-16 23:38 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin


On Thu, Apr 15 2021, SZEDER Gábor wrote:

> On Mon, Apr 12, 2021 at 01:09:01PM +0200, Ævar Arnfjörð Bjarmason wrote:
>> Remove redundant "mkdir -p", argument number checking', test
>> environment sanity checking, and disabling of hooks from
>> test_create_repo(). As we'll see below these were all either redundant
>> to other test other framework code, or to changes in git itself.
>> 
>> Respectively:
>> 
>>  1. "mkdir -p" isn't needed because "git init" itself will create
>>     leading directories if needed.
>> 
>>  2. We don't need to check the number of arguments anymore, instead
>>     we'll feed "git init" with "$@". It will die if given too many
>>     arguments.
>
> Or it will succeed if invoked as e.g. 'test_create_repo --bare repo'.

Which is fine, no? I'll make it clearer in the commit message, but I'm
aiming to address plausible bugs due to these functions not erroring out
in one way or another, if you call it with "--bare repo" that's clearly
what you wanted, as opposed to "foo bar" and we don't create a repo
under "bar".

>>  3. We won't ever hit that "Cannot setup test environment"
>>     error.
>
> ENOSPC?  Some rogue background process on Windows still desperately
> clinging to an open file descriptor to some file in the same
> directory, preventing 'rm -rf "$TRASH_DIRECTORY"' near the beginning
> of 'test-lib.sh' and interfering with 'git init'?

I mean to say we won't hit it for the reasons we'd have that error there
in the first place.

Of course "git init" can still error, but we'll catch that in other
ways.

>>     Checking the test environment sanity when doing "git init" dates
>>     back to eea420693be (t0000: catch trivial pilot errors.,
>>     2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
>>     was successfully created, 2006-01-05).
>> 
>>     We can also see it in another form a bit later in my own
>>     0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
>>     $old, 2010-08-30).
>> 
>>     But since 2006f0adaee (t/test-lib: make sure Git has already been
>>     built, 2012-09-17) we already check if we have a built git
>>     earlier.
>> 
>>     The one thing this was testing after that 2012 change was that
>>     we'd just built "git", but not "git-init", but since
>>     3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
>>     repositories, 2018-11-12) we invoke "git", not "git-init".
>> 
>>     So all of that's been checked already, and we don't need to
>>     re-check it here.
>
> I agree that if we already have a 'git' binary that can run 'git
> version', then we can safely assume that it will be able to run 'git
> init' as well.  It might be that 'git init' is buggy and segfaults,
> but that is not a "have you built things yet?" kind of error.

*nod*

>>  4. We don't need to move .git/hooks out of the way.
>> 
>>     That dates back to c09a69a83e3 (Disable hooks during tests.,
>>     2005-10-16), since then hooks became disabled by default in
>>     f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).
>> 
>>     So the hooks were already disabled by default, but as can be seen
>>     from "mkdir .git/hooks" changes various tests needed to re-setup
>>     that directory. Now they no longer do.
>> 
>>  5. Since we don't need to move the .git/hooks directory we don't need
>>     the subshell here either.
>
> We needed the subshell because we changed directory in
> 'test_create_repo' (even you referenced 0d314ce834d above), not
> because we moved the hooks directory.

Well, yes and no, a minor point but we'd need to do some juggling with
saving the $PWD in a variable etc. if it wasn't for the subshell, I
think that's why it got added in the first place.

>> In the end it turns out that all we needed was a plain "git init"
>> invocation with a custom --template directory.
>
> We don't need '--template', either; see below.

Ah, interesting.

>> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
>> index c81726acb9e..1258329fdd8 100644
>> --- a/t/test-lib-functions.sh
>> +++ b/t/test-lib-functions.sh
>> @@ -1252,18 +1252,9 @@ test_atexit () {
>>  # Most tests can use the created repository, but some may need to create more.
>>  # Usage: test_create_repo <directory>
>>  test_create_repo () {
>> -	test "$#" = 1 ||
>> -	BUG "not 1 parameter to test-create-repo"
>> -	repo="$1"
>> -	mkdir -p "$repo"
>> -	(
>> -		cd "$repo" || error "Cannot setup test environment"
>> -		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
>> -			init \
>> -			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
>> -		error "cannot run git init -- have you built things yet?"
>> -		mv .git/hooks .git/hooks-disabled
>> -	) || exit
>
> This patch removes this '|| exit', which is...
>
>   - good: if 'test_create_repo' is invoked in a test case (and not in
>     a subshell) and if it were to fail for some reason, then it won't
>     abort the whole test script, but will fail only that test case.

*nod*

>   - bad: 'test_create_repo' is responsible for creating the repository
>     in the trash directory as well; if that were to fail for any
>     reason, then the test script will not be aborted early.
>
> I think the 'exit' on error should be removed from 'test_create_repo',
> but the callsite in 'test-lib.sh' should become 'test_create_repo ||
> exit 1'.
>
> In any case, removing this '|| exit' is not mentioned in the commit
> message.

I'll fix that code. FWIW I the "|| exit 1" is effectively not removed in
almost all cases where "git init" would error, because in test-lib.sh we
cd to the just-init-ed directory, and if we can't we'll fail.

But yes, it won't catch e.g. git-init dying midway through, us running
out of space while populating that directory etc.

>> +	"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
>
> PATH is already set up to start with GIT_TEST_INSTALLED and/or
> GIT_EXEC_PATH before 'test_create_repo' is called to init the repo in
> the trash directory, so we could simply run 'git' and rely on PATH
> lookup choosing the right executable.

>> +		init \
>> +		"--template=$GIT_BUILD_DIR/templates/blt/" "$@" >&3 2>&4
>
> Likewise, GIT_TEMPLATE_DIR is already set up to the same value as in
> this '--template=...' option, so we could omit this option as well.
>
> And after that all that would remain in this function is:
>
>   git init "$1" >&3 2>&4
>
> And those redirections are only needed when this function is called to
> initialize the repo in the trash directory, but not when it creates a
> repo in a test case.  This makes me question the value of having this
> 'test_create_repo' helper function at all; there are already over 800
> cases where we run plain 'git init' outside of 't0001-init.sh' instead
> of 'test_create_repo', though removing it would be definitely cause
> some churn with over 300 callsites.

I'd missed how GIT_TEMPLATE_DIR was being set, that allows us to make
this much simpler indeed!

>>  }
>>  
>>  # This function helps on symlink challenged file systems when it is not
>> -- 
>> 2.31.1.634.gb41287a30b0
>> 


^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-15 22:05   ` SZEDER Gábor
  2021-04-15 22:24     ` Junio C Hamano
@ 2021-04-16 23:48     ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-16 23:48 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin


On Fri, Apr 16 2021, SZEDER Gábor wrote:

> On Mon, Apr 12, 2021 at 01:09:04PM +0200, Ævar Arnfjörð Bjarmason wrote:
>> This reverts and amends my my own e7884b353b7 (test-lib-functions:
>> assert correct parameter count, 2021-02-12) in order to improve the -x
>> output.
>> 
>> When I added these BUG assertions in e7884b353b7 I missed that this
>> made the -x output much more verbose.
>> 
>> E.g. for each test_cmp invocation we'd now emit:
>> 
>>     + test_cmp expect actual
>>     + test 2 -ne 2
>>     + eval diff -u "$@"
>>     + diff -u expect actual
>> 
>> That "test 2 -ne 2" line is new in e7884b353b7. As noted in
>> 45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
>> helper param, 2021-02-12) we had buggy invocations of some of these
>> functions with too many parameters.
>> 
>> Let's instead use "$@" instead of "$1" to achieve the same ends with
>> no extra -x output verbosity. The "test" operator will die with an
>> error if given more than one argument in these contexts, so using "$@"
>> achieves the same goal.
>
> I prefer the current check for its explicitness over the implicit and
> somewhat cryptic approach introduced in this patch.

Fair enough, I think it's worth it to have a bit of a non-obvious pattern there for less trace verbosity across the board.

> I hope that sooner or later I'll finish up my patch series to suppress
> '-x' output from test helper functions, and then this issue will
> become moot anyway.

That sounds like an interesting feature for those who want it, but it's
entirely orthagonal to the direction this patch is taking.

I'd like to have trace output for when tests descend into
test-lib-functions.sh and friends, I'd just like the most frequently
used code there to not be needlessly verbose.

That's not the same as wanting to hide it entirely, i.e. treat
test_path_is_file et al as though they were shell built-ins.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v2 00/12] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (16 preceding siblings ...)
  2021-04-12 18:18 ` [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Junio C Hamano
@ 2021-04-17 12:52 ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
                     ` (13 more replies)
  2021-04-20 12:29 ` [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  18 siblings, 14 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

This is a "various small fixes" series to test-lib.sh,
test-lib-functions.sh.

I've addressed the feedback on v1, the "test_create_repo" function is
now purely a dumb "git init" wrapper without any arguments, thanks to
SZEDER's observation.

The trickery with "test" arguments and "$@" later in the series seemed
more controversial, so I've peeled those patches off. I'll submit them
as another series, I've got various other serieses waiting on the
"test_commit" functions here so I'd like to get this in sooner than
later, rather than having it hang on the discussion around that.

Æ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                       | 41 ++++++++++++--------
 15 files changed, 90 insertions(+), 119 deletions(-)

Range-diff against v1:
 1:  8e4b4a2a216 !  1:  a8b483bc771 check-non-portable-shell: complain about "test" a/-o instead of &&/||
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    check-non-portable-shell: complain about "test" a/-o instead of &&/||
    +    check-non-portable-shell: check for "test <cond> -a/-o <cond>"
     
    -    Expand the t/check-non-portable-shell.pl checks to complain about the
    -    use of "-a" and "-o" to the "test" shell built-in to to mean "and" and
    -    "or", as opposed to using two "test" invocations with "&&" or "||".
    +    Add a check for -a/-o in "test", as a follow-up to the
    +    CodingGuidelines having recommended against their use since
    +    897f964c0dc (CodingGuidelines: avoid "test <cond> -a/-o <cond>",
    +    2014-05-20).
     
    -    There aren't any portability issues with using that construct that I
    -    know of, but since Junio expressed a dislike of it in [1] and we've
    -    currently got no such constructs let's add it to the lint checking. I
    -    had various in-flight and WIP patches that used this construct.
    +    These constructs are considered obsolescent by POSIX[1]. GNU has
    +    likewise warned against them[2] for a few decades.
     
    -    1. https://lore.kernel.org/git/xmqqa6qkb5fi.fsf@gitster.g/
    +    These will only match the simplistic forms of `test -X blah` (where
    +    "-X" is some single letter option), but will miss expressions such as
    +    `test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
    +    things like:
    +
    +        test whatever && ls -a foo
    +        test whatever && foo -o outfile
    +
    +    1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_16
    +    2. https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Limitations-of-Builtins.html
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## t/check-non-portable-shell.pl ##
     @@ t/check-non-portable-shell.pl: sub err {
    - 	next if $line =~ s/\\$//;
    - 
    - 	$_ = $line;
    -+	# Portability issues
    - 	/\bcp\s+-a/ and err 'cp -a is not portable';
    - 	/\bsed\s+-[^efn]\s+/ and err 'sed option not portable (use only -n, -e, -f)';
    - 	/\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)';
    -@@ t/check-non-portable-shell.pl: sub err {
    - 	/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
    - 	/^\s*([A-Z0-9_]+=(\w*|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
    - 		err '"FOO=bar shell_func" assignment extends beyond "shell_func"';
    -+	# Coding style preferences
    -+	/\btest\s+-[a-z]\s+.*?\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
    -+	/\btest\s+-[a-z]\s+.*?\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
    - 	$line = '';
    - 	# this resets our $. for each file
    - 	close ARGV if eof;
    + 	/^\s*declare\s+/ and err 'arrays/declare not portable';
    + 	/^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
    + 	/\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)';
    ++	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
    ++	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
    + 	/\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)';
    + 	/\bhead\s+-c\b/ and err 'head -c is not portable (use test_copy_bytes BYTES <file >out)';
    + 	/(?:\$\(seq|^\s*seq\b)/ and err 'seq is not portable (use test_seq)';
 2:  44223ae777e !  2:  39759d00adf test-lib: bring $remove_trash out of retirement
    @@ Commit message
         test-lib: bring $remove_trash out of retirement
     
         There's no point in creating a repository or directory only to decide
    -    right afterwards that we're skipping all the tests.
    +    right afterwards that we're skipping all the tests. We can save
    +    ourselves the redundant "git init" or "mkdir" and "rm -rf" in this
    +    case.
    +
    +    We carry around the "$remove_trash" variable because if the directory
    +    is unexpectedly gone at test_done time we'll hit the error about it
    +    being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
    +    can't remove trash directory, 2017-04-20).
     
         So let's partially revert 06478dab4c (test-lib: retire $remove_trash
         variable, 2017-04-23) and move the decision about whether to skip all
 3:  3d04553d710 =  3:  d669ce31961 test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
 4:  4ecce153b99 =  4:  9313d35bf86 test-lib-functions: reword "test_commit --append" docs
 5:  6df03776940 !  5:  c916d648e49 test-lib-functions: document test_commit --no-tag
    @@ t/test-lib-functions.sh: debug () {
      #   --author <author>
      #	Invoke "git commit" with --author <author>
     +#   --no-tag
    -+#	Do not tag the resulting commit, if supplied giving the
    -+#	optional "<tag>" argument is an error.
    ++#	Do not tag the resulting commit
      #
      # This will commit a file with the given contents and the given commit
      # message, and tag the resulting commit with the given tag name.
 6:  8d43fdd5865 !  6:  9b6bf65ce1c test-lib functions: add an --annotated-tag option to "test_commit"
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    test-lib functions: add an --annotated-tag option to "test_commit"
    +    test-lib functions: add an --annotated option to "test_commit"
     
    -    Add an --annotated-tag option to test_commit. The tag will share the
    -    same message as the commit, and we'll call test_tick before creating
    -    it (unless --notick) is provided.
    +    Add an --annotated option to test_commit to create annotated tags. The
    +    tag will share the same message as the commit, and we'll call
    +    test_tick before creating it (unless --notick) is provided.
     
         There's quite a few tests that could be simplified with this
         construct. I've picked one to convert in this change as a
    @@ t/t1403-show-ref.sh: export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
     
      ## t/test-lib-functions.sh ##
     @@ t/test-lib-functions.sh: debug () {
    + #	Invoke "git commit" with --author <author>
      #   --no-tag
    - #	Do not tag the resulting commit, if supplied giving the
    - #	optional "<tag>" argument is an error.
    + #	Do not tag the resulting commit
     +#   --annotate
     +#	Create an annotated tag with "--annotate -m <message>". Calls
    -+#	test_tick between making the commit and tag unless --notick is
    -+#	given.
    ++#	test_tick between making the commit and tag, unless --notick
    ++#	is given.
      #
      # This will commit a file with the given contents and the given commit
      # message, and tag the resulting commit with the given tag name.
    @@ t/test-lib-functions.sh: test_commit () {
     -	fi
     +		;;
     +	annotate)
    -+		if test "$tag$notick" = "annotate"
    ++		if test -z "$notick"
     +		then
     +			test_tick
     +		fi &&
 7:  ec4809e7466 =  7:  683b3ba3dd9 describe tests: convert setup to use test_commit
 8:  352eeff41c9 =  8:  dc0a863db72 test-lib functions: add --printf option to test_commit
 9:  e7432294215 =  9:  90bf55d2d42 submodule tests: use symbolic-ref --short to discover branch name
10:  634038c3a8d = 10:  e0a1e2fd529 test-lib: reformat argument list in test_create_repo()
11:  cdbff4df362 = 11:  cedf5d383b0 test-lib: do not show advice about init.defaultBranch under --verbose
12:  424caad189f ! 12:  a3e20ef18f7 test-lib: modernize test_create_repo() function
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    test-lib: modernize test_create_repo() function
    +    test-lib: split up and deprecate test_create_repo()
     
    -    Remove redundant "mkdir -p", argument number checking', test
    -    environment sanity checking, and disabling of hooks from
    -    test_create_repo(). As we'll see below these were all either redundant
    -    to other test other framework code, or to changes in git itself.
    +    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
     
    -    Respectively:
    +    Reasons for why we can remove various code from test_create_repo():
     
          1. "mkdir -p" isn't needed because "git init" itself will create
             leading directories if needed.
     
    -     2. We don't need to check the number of arguments anymore, instead
    -        we'll feed "git init" with "$@". It will die if given too many
    -        arguments.
    +     2. Since we're now a simple wrapper for "git init" we don't need to
    +        check that we have only one argument. If someone wants to run
    +        "test_create_repo --bare x" that's OK.
     
          3. We won't ever hit that "Cannot setup test environment"
             error.
    @@ 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.
    +
    +     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".
    +
    +        Let's move that special behavior into test-lib.sh itself.
    +
         In the end it turns out that all we needed was a plain "git init"
    -    invocation with a custom --template directory.
    +    invocation.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    @@ t/t5409-colorize-remote-messages.sh: test_description='remote messages are color
     
      ## t/test-lib-functions.sh ##
     @@ t/test-lib-functions.sh: test_atexit () {
    - # Most tests can use the created repository, but some may need to create more.
    + 		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
    + }
    + 
    +-# Most tests can use the created repository, but some may need to create more.
    ++# Deprecated wrapper for "git init", use "git init" directly instead
      # Usage: test_create_repo <directory>
      test_create_repo () {
     -	test "$#" = 1 ||
    @@ t/test-lib-functions.sh: test_atexit () {
     -		error "cannot run git init -- have you built things yet?"
     -		mv .git/hooks .git/hooks-disabled
     -	) || exit
    -+	"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
    -+		init \
    -+		"--template=$GIT_BUILD_DIR/templates/blt/" "$@" >&3 2>&4
    ++	git init "$@"
      }
      
      # This function helps on symlink challenged file systems when it is not
    +
    + ## t/test-lib.sh ##
    +@@ t/test-lib.sh: rm -fr "$TRASH_DIRECTORY" || {
    + remove_trash=t
    + 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 ||
    ++	error "cannot run git init"
    + else
    + 	mkdir -p "$TRASH_DIRECTORY"
    + fi
13:  0813aa8e34e <  -:  ----------- test-lib-functions: normalize test_path_is_missing() debugging
14:  b6e9d971b40 <  -:  ----------- test-lib-functions: use "return 1" instead of "false"
15:  0cd511206c4 <  -:  ----------- Revert and amend "test-lib-functions: assert correct parameter count"
16:  b4a018a63f3 <  -:  ----------- test-lib-functions: remove last two parameter count assertions
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v2 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 02/12] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
                     ` (12 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Add a check for -a/-o in "test", as a follow-up to the
CodingGuidelines having recommended against their use since
897f964c0dc (CodingGuidelines: avoid "test <cond> -a/-o <cond>",
2014-05-20).

These constructs are considered obsolescent by POSIX[1]. GNU has
likewise warned against them[2] for a few decades.

These will only match the simplistic forms of `test -X blah` (where
"-X" is some single letter option), but will miss expressions such as
`test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
things like:

    test whatever && ls -a foo
    test whatever && foo -o outfile

1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_16
2. https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Limitations-of-Builtins.html

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/check-non-portable-shell.pl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl
index fd3303552be..894aa0a4f92 100755
--- a/t/check-non-portable-shell.pl
+++ b/t/check-non-portable-shell.pl
@@ -41,6 +41,8 @@ sub err {
 	/^\s*declare\s+/ and err 'arrays/declare not portable';
 	/^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
 	/\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)';
+	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
+	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
 	/\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)';
 	/\bhead\s+-c\b/ and err 'head -c is not portable (use test_copy_bytes BYTES <file >out)';
 	/(?:\$\(seq|^\s*seq\b)/ and err 'seq is not portable (use test_seq)';
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 02/12] test-lib: bring $remove_trash out of retirement
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
                     ` (11 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

There's no point in creating a repository or directory only to decide
right afterwards that we're skipping all the tests. We can save
ourselves the redundant "git init" or "mkdir" and "rm -rf" in this
case.

We carry around the "$remove_trash" variable because if the directory
is unexpectedly gone at test_done time we'll hit the error about it
being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
can't remove trash directory, 2017-04-20).

So let's partially revert 06478dab4c (test-lib: retire $remove_trash
variable, 2017-04-23) and move the decision about whether to skip all
tests earlier.

I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
under --debug at the end of the test, 2017-04-24) for a bug we don't
want to re-introduce.

While I'm at it let's move the HOME assignment to just before
test_create_repo, it could be lower, but it seems better to set it
before calling anything in test-lib-functions.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib.sh | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 3dec266221c..7522faf39fc 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,7 +1169,7 @@ test_done () {
 			esac
 		fi
 
-		if test -z "$debug"
+		if test -z "$debug" && test -n "$remove_trash"
 		then
 			test -d "$TRASH_DIRECTORY" ||
 			error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1334,6 +1334,21 @@ then
 	exit 1
 fi
 
+# Are we running this test at all?
+this_test=${0##*/}
+this_test=${this_test%%-*}
+if match_pattern_list "$this_test" $GIT_SKIP_TESTS
+then
+	say_color info >&3 "skipping test $this_test altogether"
+	skip_all="skip all tests in $this_test"
+	test_done
+fi
+
+# Last-minute variable setup
+HOME="$TRASH_DIRECTORY"
+GNUPGHOME="$HOME/gnupg-home-not-used"
+export HOME GNUPGHOME
+
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {
 	GIT_EXIT_OK=t
@@ -1341,10 +1356,7 @@ rm -fr "$TRASH_DIRECTORY" || {
 	exit 1
 }
 
-HOME="$TRASH_DIRECTORY"
-GNUPGHOME="$HOME/gnupg-home-not-used"
-export HOME GNUPGHOME
-
+remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
 	test_create_repo "$TRASH_DIRECTORY"
@@ -1356,15 +1368,6 @@ fi
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
 
-this_test=${0##*/}
-this_test=${this_test%%-*}
-if match_pattern_list "$this_test" $GIT_SKIP_TESTS
-then
-	say_color info >&3 "skipping test $this_test altogether"
-	skip_all="skip all tests in $this_test"
-	test_done
-fi
-
 if test -n "$write_junit_xml"
 then
 	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 02/12] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 04/12] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
                     ` (10 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Stop setting the GIT_TEST_FRAMEWORK_SELFTEST variable. This was originally needed
back in 4231d1ba99 (t0000: do not get self-test disrupted by
environment warnings, 2018-09-20).

It hasn't been needed since I deleted the relevant code in test-lib.sh
in c0eedbc009 (test-lib: remove check_var_migration, 2021-02-09), I
just didn't notice that it was set here.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0000-basic.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 705d62cc27a..2c6e34b9478 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
 		passing metrics
 		'
 
-		# Tell the framework that we are self-testing to make sure
-		# it yields a stable result.
-		GIT_TEST_FRAMEWORK_SELFTEST=t &&
-
 		# Point to the t/test-lib.sh, which isn't in ../ as usual
 		. "\$TEST_DIRECTORY"/test-lib.sh
 		EOF
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 04/12] test-lib-functions: reword "test_commit --append" docs
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (2 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 05/12] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
                     ` (9 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Reword the documentation for "test_commit --append" added in my
3373518cc8 (test-lib functions: add an --append option to test_commit,
2021-01-12).

A follow-up commit will make the "echo" part of this configurable, and
in any case saying "echo >>" rather than ">>" was redundant.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6348e8d7339..d169fb2f597 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -172,8 +172,7 @@ debug () {
 #   --notick
 #	Do not call test_tick before making a commit
 #   --append
-#	Use "echo >>" instead of "echo >" when writing "<contents>" to
-#	"<file>"
+#	Use ">>" instead of ">" when writing "<contents>" to "<file>"
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 05/12] test-lib-functions: document test_commit --no-tag
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (3 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 04/12] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 06/12] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
                     ` (8 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

In 76b8b8d05c (test-lib functions: document arguments to test_commit,
2021-01-12) I added missing documentation to test_commit, but in less
than a month later in 3803a3a099 (t: add --no-tag option to
test_commit, 2021-02-09) we got another undocumented option. Let's fix
that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d169fb2f597..d0f4f3885d6 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -177,6 +177,8 @@ debug () {
 #	Invoke "git commit" with --signoff
 #   --author <author>
 #	Invoke "git commit" with --author <author>
+#   --no-tag
+#	Do not tag the resulting commit
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 06/12] test-lib functions: add an --annotated option to "test_commit"
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (4 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 05/12] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 07/12] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
                     ` (7 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Add an --annotated option to test_commit to create annotated tags. The
tag will share the same message as the commit, and we'll call
test_tick before creating it (unless --notick) is provided.

There's quite a few tests that could be simplified with this
construct. I've picked one to convert in this change as a
demonstration.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1403-show-ref.sh     |  6 ++----
 t/test-lib-functions.sh | 27 ++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 6ce62f878c3..17d3cc14050 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
-	git tag -f -a -m "annotated A" A &&
+	test_commit --annotate A &&
 	git checkout -b side &&
-	test_commit B &&
-	git tag -f -a -m "annotated B" B &&
+	test_commit --annotate B &&
 	git checkout main &&
 	test_commit C &&
 	git branch B A^0
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d0f4f3885d6..6e2332a324a 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -179,6 +179,10 @@ debug () {
 #	Invoke "git commit" with --author <author>
 #   --no-tag
 #	Do not tag the resulting commit
+#   --annotate
+#	Create an annotated tag with "--annotate -m <message>". Calls
+#	test_tick between making the commit and tag, unless --notick
+#	is given.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -191,7 +195,7 @@ test_commit () {
 	author= &&
 	signoff= &&
 	indir= &&
-	no_tag= &&
+	tag=light &&
 	while test $# != 0
 	do
 		case "$1" in
@@ -219,7 +223,10 @@ test_commit () {
 			shift
 			;;
 		--no-tag)
-			no_tag=yes
+			tag=none
+			;;
+		--annotate)
+			tag=annotate
 			;;
 		*)
 			break
@@ -243,10 +250,20 @@ test_commit () {
 	git ${indir:+ -C "$indir"} commit \
 	    ${author:+ --author "$author"} \
 	    $signoff -m "$1" &&
-	if test -z "$no_tag"
-	then
+	case "$tag" in
+	none)
+		;;
+	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
-	fi
+		;;
+	annotate)
+		if test -z "$notick"
+		then
+			test_tick
+		fi &&
+		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
+		;;
+	esac
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 07/12] describe tests: convert setup to use test_commit
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (5 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 06/12] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 08/12] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
                     ` (6 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Convert the setup of the describe tests to use test_commit when
possible. This makes use of the new --annotated-tag option to
test_commit.

Some of the setup here could simply be removed since the data being
created wasn't important to any of the subsequent tests, so I've done
so. E.g. assigning to the "one" variable was always useless, and just
checking that we can describe HEAD after the first commit wasn't
useful.

In the case of the "two" variable we could instead use the tag we just
created. See 5312ab11fbf (Add describe test., 2007-01-13) for the
initial version of this code. There's other cases here like redundant
"test_tick" invocations, or the simplification of not echoing "X" to a
file we're about to tag as "x", now we just use "x" in both cases.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6120-describe.sh | 58 ++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 45 deletions(-)

diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index e89b6747bee..88fddc91424 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -31,64 +31,32 @@ check_describe () {
 }
 
 test_expect_success setup '
+	test_commit initial file one &&
+	test_commit second file two &&
+	test_commit third file three &&
+	test_commit --annotate A file A &&
+	test_commit c file c &&
 
-	test_tick &&
-	echo one >file && git add file && git commit -m initial &&
-	one=$(git rev-parse HEAD) &&
-
-	git describe --always HEAD &&
-
-	test_tick &&
-	echo two >file && git add file && git commit -m second &&
-	two=$(git rev-parse HEAD) &&
-
-	test_tick &&
-	echo three >file && git add file && git commit -m third &&
-
-	test_tick &&
-	echo A >file && git add file && git commit -m A &&
-	test_tick &&
-	git tag -a -m A A &&
-
-	test_tick &&
-	echo c >file && git add file && git commit -m c &&
-	test_tick &&
-	git tag c &&
-
-	git reset --hard $two &&
-	test_tick &&
-	echo B >side && git add side && git commit -m B &&
-	test_tick &&
-	git tag -a -m B B &&
+	git reset --hard second &&
+	test_commit --annotate B side B &&
 
 	test_tick &&
 	git merge -m Merged c &&
 	merged=$(git rev-parse HEAD) &&
 
-	git reset --hard $two &&
-	test_tick &&
-	echo D >another && git add another && git commit -m D &&
-	test_tick &&
-	git tag -a -m D D &&
-	test_tick &&
-	git tag -a -m R R &&
-
-	test_tick &&
-	echo DD >another && git commit -a -m another &&
+	git reset --hard second &&
+	test_commit --no-tag D another D &&
 
 	test_tick &&
-	git tag e &&
+	git tag -a -m R R &&
 
-	test_tick &&
-	echo DDD >another && git commit -a -m "yet another" &&
+	test_commit e another DD &&
+	test_commit --no-tag "yet another" another DDD &&
 
 	test_tick &&
 	git merge -m Merged $merged &&
 
-	test_tick &&
-	echo X >file && echo X >side && git add file side &&
-	git commit -m x
-
+	test_commit --no-tag x file
 '
 
 check_describe A-* HEAD
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 08/12] test-lib functions: add --printf option to test_commit
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (6 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 07/12] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 09/12] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
                     ` (5 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Add a --printf option to test_commit to allow writing to the file with
"printf" instead of "echo".

This is useful for writing "\n", "\0" etc., in particular in
combination with the --append option added in 3373518cc8 (test-lib
functions: add an --append option to test_commit, 2021-01-12).

I'm converting a few tests to use the new option rather than a manual
printf/add/commit combination to demonstrate its usefulness. While I'm
at it use "test_create_repo" where appropriate, and give the
first/second commit a meaningful/more conventional log message in
cases where no test cared about that message.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1307-config-blob.sh    |  4 +---
 t/t2030-unresolve-info.sh |  3 +--
 t/t4006-diff-mode.sh      |  6 ++----
 t/t4030-diff-textconv.sh  |  8 ++------
 t/t5520-pull.sh           | 10 ++--------
 t/test-lib-functions.sh   | 12 ++++++++++--
 6 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 002e6d3388e..930dce06f0f 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
 '
 
 test_expect_success 'can parse blob ending with CR' '
-	printf "[some]key = value\\r" >config &&
-	git add config &&
-	git commit -m CR &&
+	test_commit --printf CR config "[some]key = value\\r" &&
 	echo value >expect &&
 	git config --blob=HEAD:config some.key >actual &&
 	test_cmp expect actual
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index be6c84c52a2..f691e6d9032 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
 
 test_expect_success 'rerere forget (binary)' '
 	git checkout -f side &&
-	printf "a\0c" >binary &&
-	git commit -a -m binary &&
+	test_commit --printf binary binary "a\0c" &&
 	test_must_fail git merge second &&
 	git rerere forget binary
 '
diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh
index 275ce5fa15b..6cdee2a2164 100755
--- a/t/t4006-diff-mode.sh
+++ b/t/t4006-diff-mode.sh
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
 '
 
 test_expect_success 'prepare binary file' '
-	git commit -m rezrov &&
-	printf "\00\01\02\03\04\05\06" >binbin &&
-	git add binbin &&
-	git commit -m binbin
+	git commit -m one &&
+	test_commit --printf two binbin "\00\01\02\03\04\05\06"
 '
 
 test_expect_success '--stat output after text chmod' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index c906320b60d..a39a626664d 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -26,12 +26,8 @@ EOF
 chmod +x hexdump
 
 test_expect_success 'setup binary file with history' '
-	printf "\\0\\n" >file &&
-	git add file &&
-	git commit -m one &&
-	printf "\\01\\n" >>file &&
-	git add file &&
-	git commit -m two
+	test_commit --printf one file "\\0\\n" &&
+	test_commit --printf --append two file "\\01\\n"
 '
 
 test_expect_success 'file is considered binary by porcelain' '
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a09411327f9..e2c0c510222 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 '
 
 test_expect_success 'setup for detecting upstreamed changes' '
-	mkdir src &&
-	(
-		cd src &&
-		git init &&
-		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-		git add stuff &&
-		git commit -m "Initial revision"
-	) &&
+	test_create_repo src &&
+	test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
 	git clone src dst &&
 	(
 		cd src &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6e2332a324a..dbeb3d92628 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -173,6 +173,10 @@ debug () {
 #	Do not call test_tick before making a commit
 #   --append
 #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
+#   --printf
+#       Use "printf" instead of "echo" when writing "<contents>" to
+#       "<file>". You will need to provide your own trailing "\n". You
+#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
@@ -191,6 +195,7 @@ debug () {
 
 test_commit () {
 	notick= &&
+	echo=echo &&
 	append= &&
 	author= &&
 	signoff= &&
@@ -202,6 +207,9 @@ test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--printf)
+			echo=printf
+			;;
 		--append)
 			append=yes
 			;;
@@ -238,9 +246,9 @@ test_commit () {
 	file=${2:-"$1.t"} &&
 	if test -n "$append"
 	then
-		echo "${3-$1}" >>"$indir$file"
+		$echo "${3-$1}" >>"$indir$file"
 	else
-		echo "${3-$1}" >"$indir$file"
+		$echo "${3-$1}" >"$indir$file"
 	fi &&
 	git ${indir:+ -C "$indir"} add "$file" &&
 	if test -z "$notick"
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 09/12] submodule tests: use symbolic-ref --short to discover branch name
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (7 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 08/12] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 10/12] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
                     ` (4 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Change a use of $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME added in
704fed9ea22 (tests: start moving to a different default main branch
name, 2020-10-23) to simply discover the initial branch name of a
repository set up in this function with "symbolic-ref --short".

That's something done in another test in 704fed9ea22, so doing it like
this seems like an omission, or rather an overly eager
search/replacement instead of fixing the test logic.

There are only three uses of the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
variable in the test suite, this gets rid of one of those.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-submodule-update.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 4b714e93083..f7c7df0ca42 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
 	git init submodule_update_repo &&
 	(
 		cd submodule_update_repo &&
+		branch=$(git symbolic-ref --short HEAD) &&
 		echo "expect" >>.gitignore &&
 		echo "actual" >>.gitignore &&
 		echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
 		git checkout -b valid_sub1 &&
 		git revert HEAD &&
 
-		git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
+		git checkout "$branch"
 	)
 }
 
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 10/12] test-lib: reformat argument list in test_create_repo()
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (8 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 09/12] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 11/12] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
                     ` (3 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Reformat an argument list changed in 675704c74dd (init: provide useful
advice about init.defaultBranch, 2020-12-11) to have the "-c" on the
same line as the argument it sets. This whitespace-only change makes
it easier to review a subsequent commit.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index dbeb3d92628..21271020c79 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1257,8 +1257,8 @@ test_create_repo () {
 	mkdir -p "$repo"
 	(
 		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
-			init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
+		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
+			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 11/12] test-lib: do not show advice about init.defaultBranch under --verbose
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (9 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 10/12] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:52   ` [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
                     ` (2 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Arrange for the advice about naming the initial branch not to be shown
in the --verbose output of the test suite.

Since 675704c74dd (init: provide useful advice about
init.defaultBranch, 2020-12-11) some tests have been very chatty with
repeated occurrences of this multi-line advice. Having it be this
verbose isn't helpful for anyone in the context of git's own test
suite, and it makes debugging tests that use their own "git init"
invocations needlessly distracting.

By setting the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME variable early in
test-lib.sh itself we'll squash the warning not only for
test_create_repo(), as 675704c74dd explicitly intended, but also for
other "git init" invocations.

And once we'd like to have this configuration set for all "git init"
invocations in the test suite we can get rid of the init.defaultBranch
configuration setting in test_create_repo(), as
repo_default_branch_name() in refs.c will take the GIT_TEST_* variable
over it being set.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 1 -
 t/test-lib.sh           | 5 +++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 21271020c79..8e75a013a43 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1258,7 +1258,6 @@ test_create_repo () {
 	(
 		cd "$repo" || error "Cannot setup test environment"
 		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7522faf39fc..9ebb595c335 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -64,6 +64,11 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 fi
 
+# Explicitly set the default branch name for testing, to avoid the
+# transitory "git init" warning under --verbose.
+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
 ################################################################
 # It appears that people try to run tests without building...
 "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo()
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (10 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 11/12] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:52   ` Ævar Arnfjörð Bjarmason
  2021-04-17 15:42     ` SZEDER Gábor
  2021-04-17 12:58   ` [PATCH 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  13 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:52 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

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

Reasons for why we can remove various code from test_create_repo():

 1. "mkdir -p" isn't needed because "git init" itself will create
    leading directories if needed.

 2. Since we're now a simple wrapper for "git init" we don't need to
    check that we have only one argument. If someone wants to run
    "test_create_repo --bare x" that's OK.

 3. We won't ever hit that "Cannot setup test environment"
    error.

    Checking the test environment sanity when doing "git init" dates
    back to eea420693be (t0000: catch trivial pilot errors.,
    2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
    was successfully created, 2006-01-05).

    We can also see it in another form a bit later in my own
    0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
    $old, 2010-08-30).

    But since 2006f0adaee (t/test-lib: make sure Git has already been
    built, 2012-09-17) we already check if we have a built git
    earlier.

    The one thing this was testing after that 2012 change was that
    we'd just built "git", but not "git-init", but since
    3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
    repositories, 2018-11-12) we invoke "git", not "git-init".

    So all of that's been checked already, and we don't need to
    re-check it here.

 4. We don't need to move .git/hooks out of the way.

    That dates back to c09a69a83e3 (Disable hooks during tests.,
    2005-10-16), since then hooks became disabled by default in
    f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).

    So the hooks were already disabled by default, but as can be seen
    from "mkdir .git/hooks" changes various tests needed to re-setup
    that directory. Now they no longer do.

 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.

 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".

    Let's move that special behavior into test-lib.sh itself.

In the end it turns out that all we needed was a plain "git init"
invocation.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5406-remote-rejects.sh           |  1 -
 t/t5407-post-rewrite-hook.sh        |  2 --
 t/t5409-colorize-remote-messages.sh |  1 -
 t/test-lib-functions.sh             | 15 ++-------------
 t/test-lib.sh                       |  5 ++++-
 5 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh
index ff06f99649e..5c509db6fc3 100755
--- a/t/t5406-remote-rejects.sh
+++ b/t/t5406-remote-rejects.sh
@@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	exit 1
 	EOF
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 5bb23cc3a4e..6da8d760e28 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -20,8 +20,6 @@ test_expect_success 'setup' '
 	git checkout main
 '
 
-mkdir .git/hooks
-
 cat >.git/hooks/post-rewrite <<EOF
 #!/bin/sh
 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index 5d8f401d8ec..9f1a483f426 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	echo error: error
 	echo ERROR: also highlighted
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 8e75a013a43..bd64a15c731 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1248,21 +1248,10 @@ test_atexit () {
 		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
 }
 
-# Most tests can use the created repository, but some may need to create more.
+# Deprecated wrapper for "git init", use "git init" directly instead
 # Usage: test_create_repo <directory>
 test_create_repo () {
-	test "$#" = 1 ||
-	BUG "not 1 parameter to test-create-repo"
-	repo="$1"
-	mkdir -p "$repo"
-	(
-		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			init \
-			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
-		error "cannot run git init -- have you built things yet?"
-		mv .git/hooks .git/hooks-disabled
-	) || exit
+	git init "$@"
 }
 
 # This function helps on symlink challenged file systems when it is not
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9ebb595c335..f73c3c6fc72 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1364,7 +1364,10 @@ rm -fr "$TRASH_DIRECTORY" || {
 remove_trash=t
 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 ||
+	error "cannot run git init"
 else
 	mkdir -p "$TRASH_DIRECTORY"
 fi
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 0/3] test-lib-functions.sh: trickery to make -x less verbose
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (11 preceding siblings ...)
  2021-04-17 12:52   ` [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:58   ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:58     ` [PATCH 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
                       ` (2 more replies)
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  13 siblings, 3 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This series makes the "-x" output less verbose for our various helper
functions, mainly using the trickery of feeding "$@" to "test" to rely
on it to die when given too many arguments.

It was split off from v2 of my larger test-lib.sh series as noted in
its CL:
https://lore.kernel.org/git/cover-00.12-00000000000-20210417T124424Z-avarab@gmail.com/

The range-diff below is to v1 of the relevant part of that series,
showing what's changed just for these commits.

Ævar Arnfjörð Bjarmason (3):
  test-lib-functions: normalize test_path_is_missing() debugging
  Revert and amend "test-lib-functions: assert correct parameter count"
  test-lib-functions: remove last two parameter count assertions

 t/test-lib-functions.sh | 64 +++++++++++++++--------------------------
 1 file changed, 23 insertions(+), 41 deletions(-)

Range-diff:
1:  0813aa8e34e = 1:  c22e3f7764f test-lib-functions: normalize test_path_is_missing() debugging
2:  b6e9d971b40 < -:  ----------- test-lib-functions: use "return 1" instead of "false"
3:  0cd511206c4 ! 2:  6f9e09a2017 Revert and amend "test-lib-functions: assert correct parameter count"
    @@ Commit message
         assert correct parameter count, 2021-02-12) in order to improve the -x
         output.
     
    -    When I added these BUG assertions in e7884b353b7 I missed that this
    -    made the -x output much more verbose.
    +    The goal here is to get rid of the verbosity of having e.g. a "test 2
    +    -ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
    +    to intentionally feed the "test" operator too many arguments if the
    +    functions are called with too many arguments, thus piggy-backing on it
    +    to check the number of arguments we get.
     
    -    E.g. for each test_cmp invocation we'd now emit:
    +    Before this for each test_cmp invocation we'd emit:
     
             + test_cmp expect actual
             + test 2 -ne 2
             + eval diff -u "$@"
             + diff -u expect actual
     
    -    That "test 2 -ne 2" line is new in e7884b353b7. As noted in
    +    That "test 2 -ne 2" line is new in my e7884b353b7. As noted in
         45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
         helper param, 2021-02-12) we had buggy invocations of some of these
         functions with too many parameters.
     
    -    Let's instead use "$@" instead of "$1" to achieve the same ends with
    -    no extra -x output verbosity. The "test" operator will die with an
    -    error if given more than one argument in these contexts, so using "$@"
    -    achieves the same goal.
    +    Now we'll get just:
     
    -    The same goes for "cmp" and "diff -u" (which we typically use for
    -    test_cmp).
    +        + test_cmp expect actual
    +        + eval diff -u "$@"
    +        + diff -u expect actual
    +
    +    This does not to the "right" thing in cases like:
    +
    +        test_path_is_file x -a y
    +
    +    Which will now turn into:
    +
    +        test -f x -a y
    +
    +    I consider that to be OK given the trade-off that any extra checking
    +    would produce more verbose trace output. As shown in 45a2686441b we
    +    had issues with these functions being invoked with multiple
    +    parameters (e.g. a glob) by accident, we don't need to be paranoid in
    +    guarding against hostile misuse from our own test suite.
    +
    +    While I'm at it change a few functions that relied on a "false" being
    +    the last statement in the function to use an explicit "return 1" like
    +    the other functions in this file.
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    @@ t/test-lib-functions.sh: test_external_without_stderr () {
     +	if ! test -f "$@"
      	then
     -		echo "File $1 doesn't exist"
    -+		echo "File $@ doesn't exist"
    - 		return 1
    +-		false
    ++		echo "File $* doesn't exist"
    ++		return 1
      	fi
      }
      
    @@ t/test-lib-functions.sh: test_external_without_stderr () {
     +	if ! test -d "$@"
      	then
     -		echo "Directory $1 doesn't exist"
    -+		echo "Directory $@ doesn't exist"
    - 		return 1
    +-		false
    ++		echo "Directory $* doesn't exist"
    ++		return 1
      	fi
      }
      
    @@ t/test-lib-functions.sh: test_external_without_stderr () {
     +	if ! test -e "$@"
      	then
     -		echo "Path $1 doesn't exist"
    -+		echo "Path $@ doesn't exist"
    - 		return 1
    +-		false
    ++		echo "Path $* doesn't exist"
    ++		return 1
      	fi
      }
      
    @@ t/test-lib-functions.sh: test_external_without_stderr () {
     +	if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')"
      	then
     -		echo "Directory '$1' is not empty, it contains:"
    -+		echo "Directory '$@' is not empty, it contains:"
    ++		echo "Directory '$*' is not empty, it contains:"
      		ls -la "$1"
      		return 1
      	fi
    @@ t/test-lib-functions.sh: test_dir_is_empty () {
     +	if ! test -s "$@"
      	then
     -		echo "'$1' is not a non-empty file."
    -+		echo "'$@' is not a non-empty file."
    - 		return 1
    +-		false
    ++		echo "'$*' is not a non-empty file."
    ++		return 1
      	fi
      }
      
    @@ t/test-lib-functions.sh: test_dir_is_empty () {
     -	if test -e "$1"
     +	if test -e "$@"
      	then
    - 		echo "Path $1 exists!"
    +-		echo "Path $1 exists!"
    ++		echo "Path $* exists!"
      		false
    + 	fi
    + }
     @@ t/test-lib-functions.sh: test_expect_code () {
      # - not all diff versions understand "-u"
      
    @@ t/test-lib-functions.sh: verbose () {
      	then
     -		echo "'$1' is not empty, it contains:"
     -		cat "$1"
    -+		echo "'$@' is not empty, it contains:"
    ++		echo "'$*' is not empty, it contains:"
     +		cat "$@"
      		return 1
      	fi
4:  b4a018a63f3 ! 3:  b7b11a60bcd test-lib-functions: remove last two parameter count assertions
    @@ Metadata
      ## Commit message ##
         test-lib-functions: remove last two parameter count assertions
     
    -    Remove a couple of parameter count assertions where we'll now silently
    -    do the wrong thing if given too many parameters, unlike the "$@" cases
    -    in the preceding commit where "test" etc. handle the check for usi.
    +    Remove a couple of parameter count assertions where, unlike the
    +    preceding commit's migration to 'test -$x "$@"', we'll now silently do
    +    the "wrong" thing if given too many parameters. The benefit is less
    +    verbose trace output, as noted in the preceding commit.
     
         In the case of "test_file_size", the "test-tool" we're invoking is
         happy to accept N parameters (it'll print out all N sizes). Let's just
    -    use "$@" in that case anyway, there's only a few callers, and
    +    use "$@" in that case anyway. There's only a few callers, and
         eventually those should probably be moved to use the test-tool
         directly.
     
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH 1/3] test-lib-functions: normalize test_path_is_missing() debugging
  2021-04-17 12:58   ` [PATCH 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:58     ` Ævar Arnfjörð Bjarmason
  2021-04-17 12:58     ` [PATCH 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
  2021-04-17 12:58     ` [PATCH 3/3] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
  2 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Change the test_path_is_missing() to be consistent with related
functions. Since 2caf20c52b7 (test-lib: user-friendly alternatives to
test [-d|-f|-e], 2010-08-10) we've been ls -ld-ing the bad path and
echo-ing $* if it exists. Let's just say that it exists instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index bd64a15c731..0232cc9f46d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -810,12 +810,7 @@ test_path_is_missing () {
 	test "$#" -ne 1 && BUG "1 param"
 	if test -e "$1"
 	then
-		echo "Path exists:"
-		ls -ld "$1"
-		if test $# -ge 1
-		then
-			echo "$*"
-		fi
+		echo "Path $1 exists!"
 		false
 	fi
 }
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 2/3] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-17 12:58   ` [PATCH 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-17 12:58     ` [PATCH 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:58     ` Ævar Arnfjörð Bjarmason
  2021-04-18  5:11       ` Eric Sunshine
  2021-04-17 12:58     ` [PATCH 3/3] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
  2 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This reverts and amends my my own e7884b353b7 (test-lib-functions:
assert correct parameter count, 2021-02-12) in order to improve the -x
output.

The goal here is to get rid of the verbosity of having e.g. a "test 2
-ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
to intentionally feed the "test" operator too many arguments if the
functions are called with too many arguments, thus piggy-backing on it
to check the number of arguments we get.

Before this for each test_cmp invocation we'd emit:

    + test_cmp expect actual
    + test 2 -ne 2
    + eval diff -u "$@"
    + diff -u expect actual

That "test 2 -ne 2" line is new in my e7884b353b7. As noted in
45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
helper param, 2021-02-12) we had buggy invocations of some of these
functions with too many parameters.

Now we'll get just:

    + test_cmp expect actual
    + eval diff -u "$@"
    + diff -u expect actual

This does not to the "right" thing in cases like:

    test_path_is_file x -a y

Which will now turn into:

    test -f x -a y

I consider that to be OK given the trade-off that any extra checking
would produce more verbose trace output. As shown in 45a2686441b we
had issues with these functions being invoked with multiple
parameters (e.g. a glob) by accident, we don't need to be paranoid in
guarding against hostile misuse from our own test suite.

While I'm at it change a few functions that relied on a "false" being
the last statement in the function to use an explicit "return 1" like
the other functions in this file.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 51 +++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 30 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 0232cc9f46d..9f6d46b8b1b 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -758,39 +758,35 @@ test_external_without_stderr () {
 # debugging-friendly alternatives to "test [-f|-d|-e]"
 # The commands test the existence or non-existence of $1
 test_path_is_file () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -f "$1"
+	if ! test -f "$@"
 	then
-		echo "File $1 doesn't exist"
-		false
+		echo "File $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_is_dir () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -d "$1"
+	if ! test -d "$@"
 	then
-		echo "Directory $1 doesn't exist"
-		false
+		echo "Directory $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_exists () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -e "$1"
+	if ! test -e "$@"
 	then
-		echo "Path $1 doesn't exist"
-		false
+		echo "Path $* doesn't exist"
+		return 1
 	fi
 }
 
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_dir "$1" &&
-	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+	test_path_is_dir "$@" &&
+	if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')"
 	then
-		echo "Directory '$1' is not empty, it contains:"
+		echo "Directory '$*' is not empty, it contains:"
 		ls -la "$1"
 		return 1
 	fi
@@ -798,19 +794,17 @@ test_dir_is_empty () {
 
 # Check if the file exists and has a size greater than zero
 test_file_not_empty () {
-	test "$#" = 2 && BUG "2 param"
-	if ! test -s "$1"
+	if ! test -s "$@"
 	then
-		echo "'$1' is not a non-empty file."
-		false
+		echo "'$*' is not a non-empty file."
+		return 1
 	fi
 }
 
 test_path_is_missing () {
-	test "$#" -ne 1 && BUG "1 param"
-	if test -e "$1"
+	if test -e "$@"
 	then
-		echo "Path $1 exists!"
+		echo "Path $* exists!"
 		false
 	fi
 }
@@ -1012,7 +1006,6 @@ test_expect_code () {
 # - not all diff versions understand "-u"
 
 test_cmp () {
-	test "$#" -ne 2 && BUG "2 param"
 	eval "$GIT_TEST_CMP" '"$@"'
 }
 
@@ -1042,7 +1035,6 @@ test_cmp_config () {
 # test_cmp_bin - helper to compare binary files
 
 test_cmp_bin () {
-	test "$#" -ne 2 && BUG "2 param"
 	cmp "$@"
 }
 
@@ -1103,12 +1095,11 @@ verbose () {
 # otherwise.
 
 test_must_be_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_file "$1" &&
-	if test -s "$1"
+	test_path_is_file "$@" &&
+	if test -s "$@"
 	then
-		echo "'$1' is not empty, it contains:"
-		cat "$1"
+		echo "'$*' is not empty, it contains:"
+		cat "$@"
 		return 1
 	fi
 }
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 3/3] test-lib-functions: remove last two parameter count assertions
  2021-04-17 12:58   ` [PATCH 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-17 12:58     ` [PATCH 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
  2021-04-17 12:58     ` [PATCH 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-17 12:58     ` Ævar Arnfjörð Bjarmason
  2 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 12:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Remove a couple of parameter count assertions where, unlike the
preceding commit's migration to 'test -$x "$@"', we'll now silently do
the "wrong" thing if given too many parameters. The benefit is less
verbose trace output, as noted in the preceding commit.

In the case of "test_file_size", the "test-tool" we're invoking is
happy to accept N parameters (it'll print out all N sizes). Let's just
use "$@" in that case anyway. There's only a few callers, and
eventually those should probably be moved to use the test-tool
directly.

That only leaves test_line_count, I suppose I could leave that one
alone, but since it's the only common function left that does this
assertion let's remove it for the brevity of the -x output and
consistency with other functions.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 9f6d46b8b1b..a2081ebcdea 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -821,10 +821,7 @@ test_path_is_missing () {
 # output through when the number of lines is wrong.
 
 test_line_count () {
-	if test $# != 3
-	then
-		BUG "not 3 parameters to test_line_count"
-	elif ! test $(wc -l <"$3") "$1" "$2"
+	if ! test $(wc -l <"$3") "$1" "$2"
 	then
 		echo "test_line_count: line count for $3 !$1 $2"
 		cat "$3"
@@ -833,8 +830,7 @@ test_line_count () {
 }
 
 test_file_size () {
-	test "$#" -ne 1 && BUG "1 param"
-	test-tool path-utils file-size "$1"
+	test-tool path-utils file-size "$@"
 }
 
 # Returns success if a comma separated string of keywords ($1) contains a
-- 
2.31.1.722.g788886f50a2


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo()
  2021-04-17 12:52   ` [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-17 15:42     ` SZEDER Gábor
  2021-04-17 21:45       ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: SZEDER Gábor @ 2021-04-17 15:42 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh

On Sat, Apr 17, 2021 at 02:52:45PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 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
> 
> Reasons for why we can remove various code from test_create_repo():
> 
>  1. "mkdir -p" isn't needed because "git init" itself will create
>     leading directories if needed.
> 
>  2. Since we're now a simple wrapper for "git init" we don't need to
>     check that we have only one argument. If someone wants to run
>     "test_create_repo --bare x" that's OK.
> 
>  3. We won't ever hit that "Cannot setup test environment"
>     error.
> 
>     Checking the test environment sanity when doing "git init" dates
>     back to eea420693be (t0000: catch trivial pilot errors.,
>     2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
>     was successfully created, 2006-01-05).
> 
>     We can also see it in another form a bit later in my own
>     0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
>     $old, 2010-08-30).
> 
>     But since 2006f0adaee (t/test-lib: make sure Git has already been
>     built, 2012-09-17) we already check if we have a built git
>     earlier.
> 
>     The one thing this was testing after that 2012 change was that
>     we'd just built "git", but not "git-init", but since
>     3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
>     repositories, 2018-11-12) we invoke "git", not "git-init".
> 
>     So all of that's been checked already, and we don't need to
>     re-check it here.
> 
>  4. We don't need to move .git/hooks out of the way.
> 
>     That dates back to c09a69a83e3 (Disable hooks during tests.,
>     2005-10-16), since then hooks became disabled by default in
>     f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).
> 
>     So the hooks were already disabled by default, but as can be seen
>     from "mkdir .git/hooks" changes various tests needed to re-setup
>     that directory. Now they no longer do.
> 
>  5. Since we don't need to move the .git/hooks directory

Since we don't change directory anymore...

> 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.

And then this dubious explanation will not be necessary.

>  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".
> 
>     Let's move that special behavior into test-lib.sh itself.

Quoting myself from my review of the previous version of this patch:

  PATH is already set up to start with GIT_TEST_INSTALLED and/or
  GIT_EXEC_PATH before 'test_create_repo' is called to init the repo in
  the trash directory, so we could simply run 'git' and rely on PATH
  lookup choosing the right executable.

> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 9ebb595c335..f73c3c6fc72 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1364,7 +1364,10 @@ rm -fr "$TRASH_DIRECTORY" || {
>  remove_trash=t
>  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 ||

So this could be just:

  git init "$TRASH_DIRECTORY" >&3 2>&4 ||

> +	error "cannot run git init"
>  else
>  	mkdir -p "$TRASH_DIRECTORY"
>  fi
> -- 
> 2.31.1.722.g788886f50a2
> 

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo()
  2021-04-17 15:42     ` SZEDER Gábor
@ 2021-04-17 21:45       ` Ævar Arnfjörð Bjarmason
  2021-04-20 21:27         ` SZEDER Gábor
  0 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-17 21:45 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh


On Sat, Apr 17 2021, SZEDER Gábor wrote:

> On Sat, Apr 17, 2021 at 02:52:45PM +0200, Ævar Arnfjörð Bjarmason wrote:
>> 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
>> 
>> Reasons for why we can remove various code from test_create_repo():
>> 
>>  1. "mkdir -p" isn't needed because "git init" itself will create
>>     leading directories if needed.
>> 
>>  2. Since we're now a simple wrapper for "git init" we don't need to
>>     check that we have only one argument. If someone wants to run
>>     "test_create_repo --bare x" that's OK.
>> 
>>  3. We won't ever hit that "Cannot setup test environment"
>>     error.
>> 
>>     Checking the test environment sanity when doing "git init" dates
>>     back to eea420693be (t0000: catch trivial pilot errors.,
>>     2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
>>     was successfully created, 2006-01-05).
>> 
>>     We can also see it in another form a bit later in my own
>>     0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
>>     $old, 2010-08-30).
>> 
>>     But since 2006f0adaee (t/test-lib: make sure Git has already been
>>     built, 2012-09-17) we already check if we have a built git
>>     earlier.
>> 
>>     The one thing this was testing after that 2012 change was that
>>     we'd just built "git", but not "git-init", but since
>>     3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
>>     repositories, 2018-11-12) we invoke "git", not "git-init".
>> 
>>     So all of that's been checked already, and we don't need to
>>     re-check it here.
>> 
>>  4. We don't need to move .git/hooks out of the way.
>> 
>>     That dates back to c09a69a83e3 (Disable hooks during tests.,
>>     2005-10-16), since then hooks became disabled by default in
>>     f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).
>> 
>>     So the hooks were already disabled by default, but as can be seen
>>     from "mkdir .git/hooks" changes various tests needed to re-setup
>>     that directory. Now they no longer do.
>> 
>>  5. Since we don't need to move the .git/hooks directory
>
> Since we don't change directory anymore...
>
>> 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.
>
> And then this dubious explanation will not be necessary.

Why dubious? That's why we had the subshell-ing. See 0d314ce834
(test-lib: use subshell instead of cd $new && .. && cd $old,
2010-08-30).

I don't mind rewording or not including some of this verbosity per-se,
but I wonder why you're honing in on the subshell part in
particular. Maybe there's something I'm missing...

The goal of the commit messsage is to point-by-point tear apart facets
of the previous behavior, and assure the reader that e.g. the
subshelling isn't needed for some other subtle reason.

>>  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".
>> 
>>     Let's move that special behavior into test-lib.sh itself.
>
> Quoting myself from my review of the previous version of this patch:
>
>   PATH is already set up to start with GIT_TEST_INSTALLED and/or
>   GIT_EXEC_PATH before 'test_create_repo' is called to init the repo in
>   the trash directory, so we could simply run 'git' and rely on PATH
>   lookup choosing the right executable.
>
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> index 9ebb595c335..f73c3c6fc72 100644
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -1364,7 +1364,10 @@ rm -fr "$TRASH_DIRECTORY" || {
>>  remove_trash=t
>>  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 ||
>
> So this could be just:
>
>   git init "$TRASH_DIRECTORY" >&3 2>&4 ||

Ah yes, I see that now. FWIW I managed to misread that in the last round
as it applying only once we were calling the test-lib-functions.sh
helper, but I see it's finishe setting up a few lines before the
test_create_repo in test-lib.sh too, nice.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/3] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-17 12:58     ` [PATCH 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-18  5:11       ` Eric Sunshine
  2021-04-20 12:25         ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: Eric Sunshine @ 2021-04-18  5:11 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Git List, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab

On Sat, Apr 17, 2021 at 8:58 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> [...]
> The goal here is to get rid of the verbosity of having e.g. a "test 2
> -ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
> to intentionally feed the "test" operator too many arguments if the
> functions are called with too many arguments, thus piggy-backing on it
> to check the number of arguments we get.

My one concern about this change is that it enters the realm of
"huh?". Although it's dead-simple to understand what this code is
doing:

    test "$#" -ne 1 && BUG "1 param"
    if ! test -f "$1"

the replacement code:

    if ! test -f "$@"

can easily lead to head-scratching, wondering why the author chose to
use "$@" rather than the more obvious "$1". This sort of unusual local
idiom might normally deserve an in-code comment explaining why the
more obvious code is not employed. However, adding a comment at each
site would be overkill, so it might be the sort of thing to explain in
documentation somewhere ("In order to make -x output less noisy,
employ "$@" rather than explicitly checking function arguments when
writing new test functions...".) Otherwise, the reader is forced to
consult the commit message.

Not a major objection; just voicing the bit of unease I feel about it.

> This does not to the "right" thing in cases like:

Channeling Dscho's inner Eric Sunshine[1]: s/to/do/

[1]: https://lore.kernel.org/git/nycvar.QRO.7.76.6.2103222235150.50@tvgsbejvaqbjf.bet/

^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
                     ` (12 preceding siblings ...)
  2021-04-17 12:58   ` [PATCH 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21   ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
                       ` (12 more replies)
  13 siblings, 13 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

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"
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 22:25       ` Junio C Hamano
  2021-04-20 12:21     ` [PATCH v3 02/12] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
                       ` (11 subsequent siblings)
  12 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Add a check for -a/-o in "test", as a follow-up to the
CodingGuidelines having recommended against their use since
897f964c0dc (CodingGuidelines: avoid "test <cond> -a/-o <cond>",
2014-05-20).

These constructs are considered obsolescent by POSIX[1]. GNU has
likewise warned against them[2] for a few decades.

These will only match the simplistic forms of `test -X blah` (where
"-X" is some single letter option), but will miss expressions such as
`test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
things like:

    test whatever && ls -a foo
    test whatever && foo -o outfile

1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_16
2. https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Limitations-of-Builtins.html

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/check-non-portable-shell.pl | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl
index fd3303552b..894aa0a4f9 100755
--- a/t/check-non-portable-shell.pl
+++ b/t/check-non-portable-shell.pl
@@ -41,6 +41,8 @@ sub err {
 	/^\s*declare\s+/ and err 'arrays/declare not portable';
 	/^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
 	/\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)';
+	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" preferred to "test A -a B"';
+	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" preferred to "test A -o B"';
 	/\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)';
 	/\bhead\s+-c\b/ and err 'head -c is not portable (use test_copy_bytes BYTES <file >out)';
 	/(?:\$\(seq|^\s*seq\b)/ and err 'seq is not portable (use test_seq)';
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 02/12] test-lib: bring $remove_trash out of retirement
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 22:28       ` Junio C Hamano
  2021-04-20 12:21     ` [PATCH v3 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
                       ` (10 subsequent siblings)
  12 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

There's no point in creating a repository or directory only to decide
right afterwards that we're skipping all the tests. We can save
ourselves the redundant "git init" or "mkdir" and "rm -rf" in this
case.

We carry around the "$remove_trash" variable because if the directory
is unexpectedly gone at test_done time we'll hit the error about it
being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
can't remove trash directory, 2017-04-20).

So let's partially revert 06478dab4c (test-lib: retire $remove_trash
variable, 2017-04-23) and move the decision about whether to skip all
tests earlier.

I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
under --debug at the end of the test, 2017-04-24) for a bug we don't
want to re-introduce.

While I'm at it let's move the HOME assignment to just before
test_create_repo, it could be lower, but it seems better to set it
before calling anything in test-lib-functions.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib.sh | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 3dec266221..7522faf39f 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,7 +1169,7 @@ test_done () {
 			esac
 		fi
 
-		if test -z "$debug"
+		if test -z "$debug" && test -n "$remove_trash"
 		then
 			test -d "$TRASH_DIRECTORY" ||
 			error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1334,6 +1334,21 @@ then
 	exit 1
 fi
 
+# Are we running this test at all?
+this_test=${0##*/}
+this_test=${this_test%%-*}
+if match_pattern_list "$this_test" $GIT_SKIP_TESTS
+then
+	say_color info >&3 "skipping test $this_test altogether"
+	skip_all="skip all tests in $this_test"
+	test_done
+fi
+
+# Last-minute variable setup
+HOME="$TRASH_DIRECTORY"
+GNUPGHOME="$HOME/gnupg-home-not-used"
+export HOME GNUPGHOME
+
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {
 	GIT_EXIT_OK=t
@@ -1341,10 +1356,7 @@ rm -fr "$TRASH_DIRECTORY" || {
 	exit 1
 }
 
-HOME="$TRASH_DIRECTORY"
-GNUPGHOME="$HOME/gnupg-home-not-used"
-export HOME GNUPGHOME
-
+remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
 	test_create_repo "$TRASH_DIRECTORY"
@@ -1356,15 +1368,6 @@ fi
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
 
-this_test=${0##*/}
-this_test=${this_test%%-*}
-if match_pattern_list "$this_test" $GIT_SKIP_TESTS
-then
-	say_color info >&3 "skipping test $this_test altogether"
-	skip_all="skip all tests in $this_test"
-	test_done
-fi
-
 if test -n "$write_junit_xml"
 then
 	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 02/12] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 04/12] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
                       ` (9 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Stop setting the GIT_TEST_FRAMEWORK_SELFTEST variable. This was originally needed
back in 4231d1ba99 (t0000: do not get self-test disrupted by
environment warnings, 2018-09-20).

It hasn't been needed since I deleted the relevant code in test-lib.sh
in c0eedbc009 (test-lib: remove check_var_migration, 2021-02-09), I
just didn't notice that it was set here.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0000-basic.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 705d62cc27..2c6e34b947 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
 		passing metrics
 		'
 
-		# Tell the framework that we are self-testing to make sure
-		# it yields a stable result.
-		GIT_TEST_FRAMEWORK_SELFTEST=t &&
-
 		# Point to the t/test-lib.sh, which isn't in ../ as usual
 		. "\$TEST_DIRECTORY"/test-lib.sh
 		EOF
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 04/12] test-lib-functions: reword "test_commit --append" docs
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (2 preceding siblings ...)
  2021-04-20 12:21     ` [PATCH v3 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 05/12] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
                       ` (8 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Reword the documentation for "test_commit --append" added in my
3373518cc8 (test-lib functions: add an --append option to test_commit,
2021-01-12).

A follow-up commit will make the "echo" part of this configurable, and
in any case saying "echo >>" rather than ">>" was redundant.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6348e8d733..d169fb2f59 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -172,8 +172,7 @@ debug () {
 #   --notick
 #	Do not call test_tick before making a commit
 #   --append
-#	Use "echo >>" instead of "echo >" when writing "<contents>" to
-#	"<file>"
+#	Use ">>" instead of ">" when writing "<contents>" to "<file>"
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 05/12] test-lib-functions: document test_commit --no-tag
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (3 preceding siblings ...)
  2021-04-20 12:21     ` [PATCH v3 04/12] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 06/12] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
                       ` (7 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

In 76b8b8d05c (test-lib functions: document arguments to test_commit,
2021-01-12) I added missing documentation to test_commit, but in less
than a month later in 3803a3a099 (t: add --no-tag option to
test_commit, 2021-02-09) we got another undocumented option. Let's fix
that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d169fb2f59..d0f4f3885d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -177,6 +177,8 @@ debug () {
 #	Invoke "git commit" with --signoff
 #   --author <author>
 #	Invoke "git commit" with --author <author>
+#   --no-tag
+#	Do not tag the resulting commit
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 06/12] test-lib functions: add an --annotated option to "test_commit"
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (4 preceding siblings ...)
  2021-04-20 12:21     ` [PATCH v3 05/12] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 07/12] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
                       ` (6 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Add an --annotated option to test_commit to create annotated tags. The
tag will share the same message as the commit, and we'll call
test_tick before creating it (unless --notick) is provided.

There's quite a few tests that could be simplified with this
construct. I've picked one to convert in this change as a
demonstration.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1403-show-ref.sh     |  6 ++----
 t/test-lib-functions.sh | 27 ++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 6ce62f878c..17d3cc1405 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
-	git tag -f -a -m "annotated A" A &&
+	test_commit --annotate A &&
 	git checkout -b side &&
-	test_commit B &&
-	git tag -f -a -m "annotated B" B &&
+	test_commit --annotate B &&
 	git checkout main &&
 	test_commit C &&
 	git branch B A^0
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d0f4f3885d..6e2332a324 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -179,6 +179,10 @@ debug () {
 #	Invoke "git commit" with --author <author>
 #   --no-tag
 #	Do not tag the resulting commit
+#   --annotate
+#	Create an annotated tag with "--annotate -m <message>". Calls
+#	test_tick between making the commit and tag, unless --notick
+#	is given.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -191,7 +195,7 @@ test_commit () {
 	author= &&
 	signoff= &&
 	indir= &&
-	no_tag= &&
+	tag=light &&
 	while test $# != 0
 	do
 		case "$1" in
@@ -219,7 +223,10 @@ test_commit () {
 			shift
 			;;
 		--no-tag)
-			no_tag=yes
+			tag=none
+			;;
+		--annotate)
+			tag=annotate
 			;;
 		*)
 			break
@@ -243,10 +250,20 @@ test_commit () {
 	git ${indir:+ -C "$indir"} commit \
 	    ${author:+ --author "$author"} \
 	    $signoff -m "$1" &&
-	if test -z "$no_tag"
-	then
+	case "$tag" in
+	none)
+		;;
+	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
-	fi
+		;;
+	annotate)
+		if test -z "$notick"
+		then
+			test_tick
+		fi &&
+		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
+		;;
+	esac
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 07/12] describe tests: convert setup to use test_commit
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (5 preceding siblings ...)
  2021-04-20 12:21     ` [PATCH v3 06/12] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:21     ` [PATCH v3 08/12] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
                       ` (5 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Convert the setup of the describe tests to use test_commit when
possible. This makes use of the new --annotated-tag option to
test_commit.

Some of the setup here could simply be removed since the data being
created wasn't important to any of the subsequent tests, so I've done
so. E.g. assigning to the "one" variable was always useless, and just
checking that we can describe HEAD after the first commit wasn't
useful.

In the case of the "two" variable we could instead use the tag we just
created. See 5312ab11fbf (Add describe test., 2007-01-13) for the
initial version of this code. There's other cases here like redundant
"test_tick" invocations, or the simplification of not echoing "X" to a
file we're about to tag as "x", now we just use "x" in both cases.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6120-describe.sh | 58 ++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 45 deletions(-)

diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index e89b6747be..88fddc9142 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -31,64 +31,32 @@ check_describe () {
 }
 
 test_expect_success setup '
+	test_commit initial file one &&
+	test_commit second file two &&
+	test_commit third file three &&
+	test_commit --annotate A file A &&
+	test_commit c file c &&
 
-	test_tick &&
-	echo one >file && git add file && git commit -m initial &&
-	one=$(git rev-parse HEAD) &&
-
-	git describe --always HEAD &&
-
-	test_tick &&
-	echo two >file && git add file && git commit -m second &&
-	two=$(git rev-parse HEAD) &&
-
-	test_tick &&
-	echo three >file && git add file && git commit -m third &&
-
-	test_tick &&
-	echo A >file && git add file && git commit -m A &&
-	test_tick &&
-	git tag -a -m A A &&
-
-	test_tick &&
-	echo c >file && git add file && git commit -m c &&
-	test_tick &&
-	git tag c &&
-
-	git reset --hard $two &&
-	test_tick &&
-	echo B >side && git add side && git commit -m B &&
-	test_tick &&
-	git tag -a -m B B &&
+	git reset --hard second &&
+	test_commit --annotate B side B &&
 
 	test_tick &&
 	git merge -m Merged c &&
 	merged=$(git rev-parse HEAD) &&
 
-	git reset --hard $two &&
-	test_tick &&
-	echo D >another && git add another && git commit -m D &&
-	test_tick &&
-	git tag -a -m D D &&
-	test_tick &&
-	git tag -a -m R R &&
-
-	test_tick &&
-	echo DD >another && git commit -a -m another &&
+	git reset --hard second &&
+	test_commit --no-tag D another D &&
 
 	test_tick &&
-	git tag e &&
+	git tag -a -m R R &&
 
-	test_tick &&
-	echo DDD >another && git commit -a -m "yet another" &&
+	test_commit e another DD &&
+	test_commit --no-tag "yet another" another DDD &&
 
 	test_tick &&
 	git merge -m Merged $merged &&
 
-	test_tick &&
-	echo X >file && echo X >side && git add file side &&
-	git commit -m x
-
+	test_commit --no-tag x file
 '
 
 check_describe A-* HEAD
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 08/12] test-lib functions: add --printf option to test_commit
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (6 preceding siblings ...)
  2021-04-20 12:21     ` [PATCH v3 07/12] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:21     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:22     ` [PATCH v3 09/12] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
                       ` (4 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Add a --printf option to test_commit to allow writing to the file with
"printf" instead of "echo".

This is useful for writing "\n", "\0" etc., in particular in
combination with the --append option added in 3373518cc8 (test-lib
functions: add an --append option to test_commit, 2021-01-12).

I'm converting a few tests to use the new option rather than a manual
printf/add/commit combination to demonstrate its usefulness. While I'm
at it use "test_create_repo" where appropriate, and give the
first/second commit a meaningful/more conventional log message in
cases where no test cared about that message.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1307-config-blob.sh    |  4 +---
 t/t2030-unresolve-info.sh |  3 +--
 t/t4006-diff-mode.sh      |  6 ++----
 t/t4030-diff-textconv.sh  |  8 ++------
 t/t5520-pull.sh           | 10 ++--------
 t/test-lib-functions.sh   | 12 ++++++++++--
 6 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 002e6d3388..930dce06f0 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
 '
 
 test_expect_success 'can parse blob ending with CR' '
-	printf "[some]key = value\\r" >config &&
-	git add config &&
-	git commit -m CR &&
+	test_commit --printf CR config "[some]key = value\\r" &&
 	echo value >expect &&
 	git config --blob=HEAD:config some.key >actual &&
 	test_cmp expect actual
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index be6c84c52a..f691e6d903 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
 
 test_expect_success 'rerere forget (binary)' '
 	git checkout -f side &&
-	printf "a\0c" >binary &&
-	git commit -a -m binary &&
+	test_commit --printf binary binary "a\0c" &&
 	test_must_fail git merge second &&
 	git rerere forget binary
 '
diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh
index 275ce5fa15..6cdee2a216 100755
--- a/t/t4006-diff-mode.sh
+++ b/t/t4006-diff-mode.sh
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
 '
 
 test_expect_success 'prepare binary file' '
-	git commit -m rezrov &&
-	printf "\00\01\02\03\04\05\06" >binbin &&
-	git add binbin &&
-	git commit -m binbin
+	git commit -m one &&
+	test_commit --printf two binbin "\00\01\02\03\04\05\06"
 '
 
 test_expect_success '--stat output after text chmod' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index c906320b60..a39a626664 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -26,12 +26,8 @@ EOF
 chmod +x hexdump
 
 test_expect_success 'setup binary file with history' '
-	printf "\\0\\n" >file &&
-	git add file &&
-	git commit -m one &&
-	printf "\\01\\n" >>file &&
-	git add file &&
-	git commit -m two
+	test_commit --printf one file "\\0\\n" &&
+	test_commit --printf --append two file "\\01\\n"
 '
 
 test_expect_success 'file is considered binary by porcelain' '
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a09411327f..e2c0c51022 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 '
 
 test_expect_success 'setup for detecting upstreamed changes' '
-	mkdir src &&
-	(
-		cd src &&
-		git init &&
-		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-		git add stuff &&
-		git commit -m "Initial revision"
-	) &&
+	test_create_repo src &&
+	test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
 	git clone src dst &&
 	(
 		cd src &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6e2332a324..dbeb3d9262 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -173,6 +173,10 @@ debug () {
 #	Do not call test_tick before making a commit
 #   --append
 #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
+#   --printf
+#       Use "printf" instead of "echo" when writing "<contents>" to
+#       "<file>". You will need to provide your own trailing "\n". You
+#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
@@ -191,6 +195,7 @@ debug () {
 
 test_commit () {
 	notick= &&
+	echo=echo &&
 	append= &&
 	author= &&
 	signoff= &&
@@ -202,6 +207,9 @@ test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--printf)
+			echo=printf
+			;;
 		--append)
 			append=yes
 			;;
@@ -238,9 +246,9 @@ test_commit () {
 	file=${2:-"$1.t"} &&
 	if test -n "$append"
 	then
-		echo "${3-$1}" >>"$indir$file"
+		$echo "${3-$1}" >>"$indir$file"
 	else
-		echo "${3-$1}" >"$indir$file"
+		$echo "${3-$1}" >"$indir$file"
 	fi &&
 	git ${indir:+ -C "$indir"} add "$file" &&
 	if test -z "$notick"
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 09/12] submodule tests: use symbolic-ref --short to discover branch name
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (7 preceding siblings ...)
  2021-04-20 12:21     ` [PATCH v3 08/12] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:22     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:22     ` [PATCH v3 10/12] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
                       ` (3 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:22 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Change a use of $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME added in
704fed9ea22 (tests: start moving to a different default main branch
name, 2020-10-23) to simply discover the initial branch name of a
repository set up in this function with "symbolic-ref --short".

That's something done in another test in 704fed9ea22, so doing it like
this seems like an omission, or rather an overly eager
search/replacement instead of fixing the test logic.

There are only three uses of the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
variable in the test suite, this gets rid of one of those.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-submodule-update.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 4b714e9308..f7c7df0ca4 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
 	git init submodule_update_repo &&
 	(
 		cd submodule_update_repo &&
+		branch=$(git symbolic-ref --short HEAD) &&
 		echo "expect" >>.gitignore &&
 		echo "actual" >>.gitignore &&
 		echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
 		git checkout -b valid_sub1 &&
 		git revert HEAD &&
 
-		git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
+		git checkout "$branch"
 	)
 }
 
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 10/12] test-lib: reformat argument list in test_create_repo()
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (8 preceding siblings ...)
  2021-04-20 12:22     ` [PATCH v3 09/12] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:22     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:22     ` [PATCH v3 11/12] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
                       ` (2 subsequent siblings)
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:22 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Reformat an argument list changed in 675704c74dd (init: provide useful
advice about init.defaultBranch, 2020-12-11) to have the "-c" on the
same line as the argument it sets. This whitespace-only change makes
it easier to review a subsequent commit.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index dbeb3d9262..21271020c7 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1257,8 +1257,8 @@ test_create_repo () {
 	mkdir -p "$repo"
 	(
 		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
-			init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
+		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
+			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 11/12] test-lib: do not show advice about init.defaultBranch under --verbose
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (9 preceding siblings ...)
  2021-04-20 12:22     ` [PATCH v3 10/12] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:22     ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:22     ` [PATCH v3 12/12] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:22 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

Arrange for the advice about naming the initial branch not to be shown
in the --verbose output of the test suite.

Since 675704c74dd (init: provide useful advice about
init.defaultBranch, 2020-12-11) some tests have been very chatty with
repeated occurrences of this multi-line advice. Having it be this
verbose isn't helpful for anyone in the context of git's own test
suite, and it makes debugging tests that use their own "git init"
invocations needlessly distracting.

By setting the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME variable early in
test-lib.sh itself we'll squash the warning not only for
test_create_repo(), as 675704c74dd explicitly intended, but also for
other "git init" invocations.

And once we'd like to have this configuration set for all "git init"
invocations in the test suite we can get rid of the init.defaultBranch
configuration setting in test_create_repo(), as
repo_default_branch_name() in refs.c will take the GIT_TEST_* variable
over it being set.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 1 -
 t/test-lib.sh           | 5 +++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 21271020c7..8e75a013a4 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1258,7 +1258,6 @@ test_create_repo () {
 	(
 		cd "$repo" || error "Cannot setup test environment"
 		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7522faf39f..9ebb595c33 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -64,6 +64,11 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 fi
 
+# Explicitly set the default branch name for testing, to avoid the
+# transitory "git init" warning under --verbose.
+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
 ################################################################
 # It appears that people try to run tests without building...
 "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 12/12] test-lib: split up and deprecate test_create_repo()
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (10 preceding siblings ...)
  2021-04-20 12:22     ` [PATCH v3 11/12] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:22     ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  12 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:22 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Ævar Arnfjörð Bjarmason

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.

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.

 2. Since we're now a simple wrapper for "git init" we don't need to
    check that we have only one argument. If someone wants to run
    "test_create_repo --bare x" that's OK.

 3. We won't ever hit that "Cannot setup test environment"
    error.

    Checking the test environment sanity when doing "git init" dates
    back to eea420693be (t0000: catch trivial pilot errors.,
    2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
    was successfully created, 2006-01-05).

    We can also see it in another form a bit later in my own
    0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
    $old, 2010-08-30).

    But since 2006f0adaee (t/test-lib: make sure Git has already been
    built, 2012-09-17) we already check if we have a built git
    earlier.

    The one thing this was testing after that 2012 change was that
    we'd just built "git", but not "git-init", but since
    3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
    repositories, 2018-11-12) we invoke "git", not "git-init".

    So all of that's been checked already, and we don't need to
    re-check it here.

 4. We don't need to move .git/hooks out of the way.

    That dates back to c09a69a83e3 (Disable hooks during tests.,
    2005-10-16), since then hooks became disabled by default in
    f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).

    So the hooks were already disabled by default, but as can be seen
    from "mkdir .git/hooks" changes various tests needed to re-setup
    that directory. Now they no longer do.

 5. Since we don't need to move the .git/hooks directory we don't need
    the subshell here either.

    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.

    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.

 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

    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/t5406-remote-rejects.sh           |  1 -
 t/t5407-post-rewrite-hook.sh        |  2 --
 t/t5409-colorize-remote-messages.sh |  1 -
 t/test-lib-functions.sh             | 15 ++-------------
 t/test-lib.sh                       |  3 ++-
 5 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh
index ff06f99649..5c509db6fc 100755
--- a/t/t5406-remote-rejects.sh
+++ b/t/t5406-remote-rejects.sh
@@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	exit 1
 	EOF
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 5bb23cc3a4..6da8d760e2 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -20,8 +20,6 @@ test_expect_success 'setup' '
 	git checkout main
 '
 
-mkdir .git/hooks
-
 cat >.git/hooks/post-rewrite <<EOF
 #!/bin/sh
 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index 5d8f401d8e..9f1a483f42 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	echo error: error
 	echo ERROR: also highlighted
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 8e75a013a4..bd64a15c73 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1248,21 +1248,10 @@ test_atexit () {
 		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
 }
 
-# Most tests can use the created repository, but some may need to create more.
+# Deprecated wrapper for "git init", use "git init" directly instead
 # Usage: test_create_repo <directory>
 test_create_repo () {
-	test "$#" = 1 ||
-	BUG "not 1 parameter to test-create-repo"
-	repo="$1"
-	mkdir -p "$repo"
-	(
-		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			init \
-			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
-		error "cannot run git init -- have you built things yet?"
-		mv .git/hooks .git/hooks-disabled
-	) || exit
+	git init "$@"
 }
 
 # This function helps on symlink challenged file systems when it is not
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9ebb595c33..06026bbe75 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1364,7 +1364,8 @@ rm -fr "$TRASH_DIRECTORY" || {
 remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
-	test_create_repo "$TRASH_DIRECTORY"
+	git init "$TRASH_DIRECTORY" >&3 2>&4 ||
+	error "cannot run git init"
 else
 	mkdir -p "$TRASH_DIRECTORY"
 fi
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/3] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-18  5:11       ` Eric Sunshine
@ 2021-04-20 12:25         ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:25 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Git List, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab


On Sun, Apr 18 2021, Eric Sunshine wrote:

> On Sat, Apr 17, 2021 at 8:58 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> [...]
>> The goal here is to get rid of the verbosity of having e.g. a "test 2
>> -ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
>> to intentionally feed the "test" operator too many arguments if the
>> functions are called with too many arguments, thus piggy-backing on it
>> to check the number of arguments we get.
>
> My one concern about this change is that it enters the realm of
> "huh?". Although it's dead-simple to understand what this code is
> doing:
>
>     test "$#" -ne 1 && BUG "1 param"
>     if ! test -f "$1"
>
> the replacement code:
>
>     if ! test -f "$@"
>
> can easily lead to head-scratching, wondering why the author chose to
> use "$@" rather than the more obvious "$1". This sort of unusual local
> idiom might normally deserve an in-code comment explaining why the
> more obvious code is not employed. However, adding a comment at each
> site would be overkill, so it might be the sort of thing to explain in
> documentation somewhere ("In order to make -x output less noisy,
> employ "$@" rather than explicitly checking function arguments when
> writing new test functions...".) Otherwise, the reader is forced to
> consult the commit message.
>
> Not a major objection; just voicing the bit of unease I feel about it.

I'm including a well-placed comment in the re-roll of this. FWIW this
would be much easier to follow with my rejected split-up of
test-lib-functions.sh, then we could group these functions into one
file:
https://lore.kernel.org/git/20210209214159.22815-13-avarab@gmail.com/

>> This does not to the "right" thing in cases like:
>
> Channeling Dscho's inner Eric Sunshine[1]: s/to/do/

Sunshine recursion error? :)

> [1]: https://lore.kernel.org/git/nycvar.QRO.7.76.6.2103222235150.50@tvgsbejvaqbjf.bet/


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose
  2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                   ` (17 preceding siblings ...)
  2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:29 ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:29   ` [PATCH v2 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
                     ` (3 more replies)
  18 siblings, 4 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This series makes the "-x" output less verbose for our various helper
functions, mainly using the trickery of feeding "$@" to "test" to rely
on it to die when given too many arguments.

Since v1 the only change is adding a comment as suggested by Eric
Sunshine, it's not ideal as noted in
<87pmyp2led.fsf@evledraar.gmail.com> (I wish these were just in one
file, so we could have a comment at the top), but will aid future
maintenance anyway.

Ævar Arnfjörð Bjarmason (3):
  test-lib-functions: normalize test_path_is_missing() debugging
  Revert and amend "test-lib-functions: assert correct parameter count"
  test-lib-functions: remove last two parameter count assertions

 t/test-lib-functions.sh | 72 +++++++++++++++++------------------------
 1 file changed, 30 insertions(+), 42 deletions(-)

Range-diff against v1:
1:  a3e20ef18f < -:  ---------- test-lib: split up and deprecate test_create_repo()
2:  c22e3f7764 = 1:  fd33f6d71f test-lib-functions: normalize test_path_is_missing() debugging
3:  6f9e09a201 ! 2:  67ddd821df Revert and amend "test-lib-functions: assert correct parameter count"
    @@ Commit message
     
      ## t/test-lib-functions.sh ##
     @@ t/test-lib-functions.sh: test_external_without_stderr () {
    + }
    + 
      # debugging-friendly alternatives to "test [-f|-d|-e]"
    - # The commands test the existence or non-existence of $1
    +-# The commands test the existence or non-existence of $1
    ++# The commands test the existence or non-existence of
    ++# a given argument.
    ++#
    ++# The pattern of using "$@" to "test" instead of "$1" is not a bug. We
    ++# are counting on "test" to error on too many arguments if more than
    ++# one is given. Checking "$#" explicitly would lead to overly verbose
    ++# -x output.
      test_path_is_file () {
     -	test "$#" -ne 1 && BUG "1 param"
     -	if ! test -f "$1"
4:  b7b11a60bc = 3:  8fd51861b5 test-lib-functions: remove last two parameter count assertions
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v2 1/3] test-lib-functions: normalize test_path_is_missing() debugging
  2021-04-20 12:29 ` [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:29   ` Ævar Arnfjörð Bjarmason
  2021-04-20 12:29   ` [PATCH v2 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Change the test_path_is_missing() to be consistent with related
functions. Since 2caf20c52b7 (test-lib: user-friendly alternatives to
test [-d|-f|-e], 2010-08-10) we've been ls -ld-ing the bad path and
echo-ing $* if it exists. Let's just say that it exists instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index bd64a15c73..0232cc9f46 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -810,12 +810,7 @@ test_path_is_missing () {
 	test "$#" -ne 1 && BUG "1 param"
 	if test -e "$1"
 	then
-		echo "Path exists:"
-		ls -ld "$1"
-		if test $# -ge 1
-		then
-			echo "$*"
-		fi
+		echo "Path $1 exists!"
 		false
 	fi
 }
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 2/3] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-20 12:29 ` [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-20 12:29   ` [PATCH v2 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:29   ` Ævar Arnfjörð Bjarmason
  2021-04-20 15:07     ` Eric Sunshine
  2021-04-20 12:29   ` [PATCH v2 3/3] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  3 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This reverts and amends my my own e7884b353b7 (test-lib-functions:
assert correct parameter count, 2021-02-12) in order to improve the -x
output.

The goal here is to get rid of the verbosity of having e.g. a "test 2
-ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
to intentionally feed the "test" operator too many arguments if the
functions are called with too many arguments, thus piggy-backing on it
to check the number of arguments we get.

Before this for each test_cmp invocation we'd emit:

    + test_cmp expect actual
    + test 2 -ne 2
    + eval diff -u "$@"
    + diff -u expect actual

That "test 2 -ne 2" line is new in my e7884b353b7. As noted in
45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
helper param, 2021-02-12) we had buggy invocations of some of these
functions with too many parameters.

Now we'll get just:

    + test_cmp expect actual
    + eval diff -u "$@"
    + diff -u expect actual

This does not to the "right" thing in cases like:

    test_path_is_file x -a y

Which will now turn into:

    test -f x -a y

I consider that to be OK given the trade-off that any extra checking
would produce more verbose trace output. As shown in 45a2686441b we
had issues with these functions being invoked with multiple
parameters (e.g. a glob) by accident, we don't need to be paranoid in
guarding against hostile misuse from our own test suite.

While I'm at it change a few functions that relied on a "false" being
the last statement in the function to use an explicit "return 1" like
the other functions in this file.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 59 +++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 0232cc9f46..f8f5bf9de1 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -756,41 +756,43 @@ test_external_without_stderr () {
 }
 
 # debugging-friendly alternatives to "test [-f|-d|-e]"
-# The commands test the existence or non-existence of $1
+# The commands test the existence or non-existence of
+# a given argument.
+#
+# The pattern of using "$@" to "test" instead of "$1" is not a bug. We
+# are counting on "test" to error on too many arguments if more than
+# one is given. Checking "$#" explicitly would lead to overly verbose
+# -x output.
 test_path_is_file () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -f "$1"
+	if ! test -f "$@"
 	then
-		echo "File $1 doesn't exist"
-		false
+		echo "File $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_is_dir () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -d "$1"
+	if ! test -d "$@"
 	then
-		echo "Directory $1 doesn't exist"
-		false
+		echo "Directory $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_exists () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -e "$1"
+	if ! test -e "$@"
 	then
-		echo "Path $1 doesn't exist"
-		false
+		echo "Path $* doesn't exist"
+		return 1
 	fi
 }
 
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_dir "$1" &&
-	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+	test_path_is_dir "$@" &&
+	if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')"
 	then
-		echo "Directory '$1' is not empty, it contains:"
+		echo "Directory '$*' is not empty, it contains:"
 		ls -la "$1"
 		return 1
 	fi
@@ -798,19 +800,17 @@ test_dir_is_empty () {
 
 # Check if the file exists and has a size greater than zero
 test_file_not_empty () {
-	test "$#" = 2 && BUG "2 param"
-	if ! test -s "$1"
+	if ! test -s "$@"
 	then
-		echo "'$1' is not a non-empty file."
-		false
+		echo "'$*' is not a non-empty file."
+		return 1
 	fi
 }
 
 test_path_is_missing () {
-	test "$#" -ne 1 && BUG "1 param"
-	if test -e "$1"
+	if test -e "$@"
 	then
-		echo "Path $1 exists!"
+		echo "Path $* exists!"
 		false
 	fi
 }
@@ -1012,7 +1012,6 @@ test_expect_code () {
 # - not all diff versions understand "-u"
 
 test_cmp () {
-	test "$#" -ne 2 && BUG "2 param"
 	eval "$GIT_TEST_CMP" '"$@"'
 }
 
@@ -1042,7 +1041,6 @@ test_cmp_config () {
 # test_cmp_bin - helper to compare binary files
 
 test_cmp_bin () {
-	test "$#" -ne 2 && BUG "2 param"
 	cmp "$@"
 }
 
@@ -1103,12 +1101,11 @@ verbose () {
 # otherwise.
 
 test_must_be_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_file "$1" &&
-	if test -s "$1"
+	test_path_is_file "$@" &&
+	if test -s "$@"
 	then
-		echo "'$1' is not empty, it contains:"
-		cat "$1"
+		echo "'$*' is not empty, it contains:"
+		cat "$@"
 		return 1
 	fi
 }
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 3/3] test-lib-functions: remove last two parameter count assertions
  2021-04-20 12:29 ` [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-20 12:29   ` [PATCH v2 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
  2021-04-20 12:29   ` [PATCH v2 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-20 12:29   ` Ævar Arnfjörð Bjarmason
  2021-04-20 21:15     ` Junio C Hamano
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  3 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-20 12:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Remove a couple of parameter count assertions where, unlike the
preceding commit's migration to 'test -$x "$@"', we'll now silently do
the "wrong" thing if given too many parameters. The benefit is less
verbose trace output, as noted in the preceding commit.

In the case of "test_file_size", the "test-tool" we're invoking is
happy to accept N parameters (it'll print out all N sizes). Let's just
use "$@" in that case anyway. There's only a few callers, and
eventually those should probably be moved to use the test-tool
directly.

That only leaves test_line_count, I suppose I could leave that one
alone, but since it's the only common function left that does this
assertion let's remove it for the brevity of the -x output and
consistency with other functions.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index f8f5bf9de1..e128b341ff 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -827,10 +827,7 @@ test_path_is_missing () {
 # output through when the number of lines is wrong.
 
 test_line_count () {
-	if test $# != 3
-	then
-		BUG "not 3 parameters to test_line_count"
-	elif ! test $(wc -l <"$3") "$1" "$2"
+	if ! test $(wc -l <"$3") "$1" "$2"
 	then
 		echo "test_line_count: line count for $3 !$1 $2"
 		cat "$3"
@@ -839,8 +836,7 @@ test_line_count () {
 }
 
 test_file_size () {
-	test "$#" -ne 1 && BUG "1 param"
-	test-tool path-utils file-size "$1"
+	test-tool path-utils file-size "$@"
 }
 
 # Returns success if a comma separated string of keywords ($1) contains a
-- 
2.31.1.723.gf6bad1b9ba1


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH v2 2/3] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-20 12:29   ` [PATCH v2 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-20 15:07     ` Eric Sunshine
  2021-04-21  8:22       ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: Eric Sunshine @ 2021-04-20 15:07 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Git List, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab

On Tue, Apr 20, 2021 at 8:29 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> [...]
> The goal here is to get rid of the verbosity of having e.g. a "test 2
> -ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
> to intentionally feed the "test" operator too many arguments if the
> functions are called with too many arguments, thus piggy-backing on it
> to check the number of arguments we get.
> [...]
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -756,41 +756,43 @@ test_external_without_stderr () {
>  # debugging-friendly alternatives to "test [-f|-d|-e]"
> +# The commands test the existence or non-existence of
> +# a given argument.
> +#
> +# The pattern of using "$@" to "test" instead of "$1" is not a bug. We
> +# are counting on "test" to error on too many arguments if more than
> +# one is given. Checking "$#" explicitly would lead to overly verbose
> +# -x output.
>  test_path_is_file () {
> +       if ! test -f "$@"

Thanks. The new comment makes the intent of "$@" clear.

If you do re-roll for some reason, it might make sense to move the new
comment (the one starting "The pattern of...") into the function
itself just before the use of "$@". The reasons I suggest this are:
(1) the comment explains an implementation detail, thus is intended
for people who might change this function, whereas all the text above
the new paragraph is API documentation for callers of the function who
need only the black-box description; (2) it places the comment closer
to the relevant code, thus is less likely to be overlooked by someone
changing the function.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v2 3/3] test-lib-functions: remove last two parameter count assertions
  2021-04-20 12:29   ` [PATCH v2 3/3] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
@ 2021-04-20 21:15     ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-20 21:15 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Remove a couple of parameter count assertions where, unlike the
> preceding commit's migration to 'test -$x "$@"', we'll now silently do
> the "wrong" thing if given too many parameters. The benefit is less
> verbose trace output, as noted in the preceding commit.
>
> In the case of "test_file_size", the "test-tool" we're invoking is
> happy to accept N parameters (it'll print out all N sizes). Let's just
> use "$@" in that case anyway. There's only a few callers, and
> eventually those should probably be moved to use the test-tool
> directly.
>
> That only leaves test_line_count, I suppose I could leave that one
> alone, but since it's the only common function left that does this
> assertion let's remove it for the brevity of the -x output and
> consistency with other functions.

Unlike the previous step that did not entirely sacrifice the "test
writers are human and they need our help in detecting their
mistakes", this step feels like "shortening '-x' output is the most
important thing in the world, and helping test writers is much less
important."

IOW, I am not convinced it is a good change.


> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/test-lib-functions.sh | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index f8f5bf9de1..e128b341ff 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -827,10 +827,7 @@ test_path_is_missing () {
>  # output through when the number of lines is wrong.
>  
>  test_line_count () {
> -	if test $# != 3
> -	then
> -		BUG "not 3 parameters to test_line_count"
> -	elif ! test $(wc -l <"$3") "$1" "$2"
> +	if ! test $(wc -l <"$3") "$1" "$2"
>  	then
>  		echo "test_line_count: line count for $3 !$1 $2"
>  		cat "$3"
> @@ -839,8 +836,7 @@ test_line_count () {
>  }
>  
>  test_file_size () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	test-tool path-utils file-size "$1"
> +	test-tool path-utils file-size "$@"
>  }
>  
>  # Returns success if a comma separated string of keywords ($1) contains a

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo()
  2021-04-17 21:45       ` Ævar Arnfjörð Bjarmason
@ 2021-04-20 21:27         ` SZEDER Gábor
  0 siblings, 0 replies; 175+ messages in thread
From: SZEDER Gábor @ 2021-04-20 21:27 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh

On Sat, Apr 17, 2021 at 11:45:41PM +0200, Ævar Arnfjörð Bjarmason wrote:
> >>  5. Since we don't need to move the .git/hooks directory
> >
> > Since we don't change directory anymore...
> >
> >> 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.
> >
> > And then this dubious explanation will not be necessary.
> 
> Why dubious? That's why we had the subshell-ing. See 0d314ce834
> (test-lib: use subshell instead of cd $new && .. && cd $old,
> 2010-08-30).

That commit doesn't mention hooks at all, so I'm not sure what I
should see there.  OTOH, you did specifically write "use a subshell
instead of keeping track of the old working directory and cd-ing back
when it's done"...  which is in line with our best practices on how to
change directories in our tests in order to reliably change back even
in case of an error.

And that cd-ing back and forth was not added because of the hooks
either, but because back in the day when 'test_create_repo' was
created 'git init-db' could only create a new repository in the
current directory.

> I don't mind rewording or not including some of this verbosity per-se,
> but I wonder why you're honing in on the subshell part in
> particular. Maybe there's something I'm missing...
> 
> The goal of the commit messsage is to point-by-point tear apart facets
> of the previous behavior,

Agreed.

> and assure the reader that e.g. the
> subshelling isn't needed for some other subtle reason.

The role of moving the hooks with respect to the subshell is not a
subtlety, it is simply irrelevant.  And while you are so focused on
this irrevelancy you keep forgetting to mention the factor that
actually does matter: that we won't change directories anymore.



^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-20 12:21     ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
@ 2021-04-20 22:25       ` Junio C Hamano
  2021-04-21  8:46         ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-20 22:25 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> These will only match the simplistic forms of `test -X blah` (where
> "-X" is some single letter option), but will miss expressions such as
> `test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
> things like:
>
>     test whatever && ls -a foo
>     test whatever && foo -o outfile

I still do not understand why you have to insist on dashed operator
as the first thing given to "test", like this:

> +	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" ...
> +	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" ...

IOW, what over-matching would we get if we simplified the condition
like so?

    /\btest\s+[^&|]+\s+-a\s/
    /\btest\s+[^&|]+\s+-o\s/

The one in the patch would miss things like

	test "$a" = "$b" -o "$a" -lt "$b"
	test "$n" -a "$n" -lt 4

but the only thing that we care about is that a command that started
with "test " has "-a" or "-o" before we see "&" or "|", no?

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 02/12] test-lib: bring $remove_trash out of retirement
  2021-04-20 12:21     ` [PATCH v3 02/12] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-04-20 22:28       ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-20 22:28 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> We carry around the "$remove_trash" variable because if the directory
> is unexpectedly gone at test_done time we'll hit the error about it
> being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
> can't remove trash directory, 2017-04-20).

Makes sense, but then remove_trash should be initialized to a
non-empty string at the beginning, to avoid it leaking from end-user
environment, just like the way store_arg_to and opt_required_arg are
protected?

> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 3dec266221..7522faf39f 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1169,7 +1169,7 @@ test_done () {
>  			esac
>  		fi
>  
> -		if test -z "$debug"
> +		if test -z "$debug" && test -n "$remove_trash"
>  		then
>  			test -d "$TRASH_DIRECTORY" ||
>  			error "Tests passed but trash directory already removed before test cleanup; aborting"
> @@ -1334,6 +1334,21 @@ then
>  	exit 1
>  fi
>  
> +# Are we running this test at all?
> +this_test=${0##*/}
> +this_test=${this_test%%-*}
> +if match_pattern_list "$this_test" $GIT_SKIP_TESTS
> +then
> +	say_color info >&3 "skipping test $this_test altogether"
> +	skip_all="skip all tests in $this_test"
> +	test_done
> +fi
> +
> +# Last-minute variable setup
> +HOME="$TRASH_DIRECTORY"
> +GNUPGHOME="$HOME/gnupg-home-not-used"
> +export HOME GNUPGHOME
> +
>  # Test repository
>  rm -fr "$TRASH_DIRECTORY" || {
>  	GIT_EXIT_OK=t
> @@ -1341,10 +1356,7 @@ rm -fr "$TRASH_DIRECTORY" || {
>  	exit 1
>  }
>  
> -HOME="$TRASH_DIRECTORY"
> -GNUPGHOME="$HOME/gnupg-home-not-used"
> -export HOME GNUPGHOME
> -
> +remove_trash=t
>  if test -z "$TEST_NO_CREATE_REPO"
>  then
>  	test_create_repo "$TRASH_DIRECTORY"
> @@ -1356,15 +1368,6 @@ fi
>  # in subprocesses like git equals our $PWD (for pathname comparisons).
>  cd -P "$TRASH_DIRECTORY" || exit 1
>  
> -this_test=${0##*/}
> -this_test=${this_test%%-*}
> -if match_pattern_list "$this_test" $GIT_SKIP_TESTS
> -then
> -	say_color info >&3 "skipping test $this_test altogether"
> -	skip_all="skip all tests in $this_test"
> -	test_done
> -fi
> -
>  if test -n "$write_junit_xml"
>  then
>  	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v2 2/3] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-20 15:07     ` Eric Sunshine
@ 2021-04-21  8:22       ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21  8:22 UTC (permalink / raw)
  To: Eric Sunshine
  Cc: Git List, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab


On Tue, Apr 20 2021, Eric Sunshine wrote:

> On Tue, Apr 20, 2021 at 8:29 AM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> [...]
>> The goal here is to get rid of the verbosity of having e.g. a "test 2
>> -ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
>> to intentionally feed the "test" operator too many arguments if the
>> functions are called with too many arguments, thus piggy-backing on it
>> to check the number of arguments we get.
>> [...]
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
>> @@ -756,41 +756,43 @@ test_external_without_stderr () {
>>  # debugging-friendly alternatives to "test [-f|-d|-e]"
>> +# The commands test the existence or non-existence of
>> +# a given argument.
>> +#
>> +# The pattern of using "$@" to "test" instead of "$1" is not a bug. We
>> +# are counting on "test" to error on too many arguments if more than
>> +# one is given. Checking "$#" explicitly would lead to overly verbose
>> +# -x output.
>>  test_path_is_file () {
>> +       if ! test -f "$@"
>
> Thanks. The new comment makes the intent of "$@" clear.
>
> If you do re-roll for some reason, it might make sense to move the new
> comment (the one starting "The pattern of...") into the function
> itself just before the use of "$@". The reasons I suggest this are:
> (1) the comment explains an implementation detail, thus is intended
> for people who might change this function, whereas all the text above
> the new paragraph is API documentation for callers of the function who
> need only the black-box description; (2) it places the comment closer
> to the relevant code, thus is less likely to be overlooked by someone
> changing the function.

I think moving it would be worse / wouldn't make sense.

The comment doesn't just apply to test_path_is_file(), but the next N
functions that use the "$@" pattern. Just like the existing
"debugging-friendly alternatives" comment does. I.e. test_path_is_file
is just the "-f" part of thta comment, the following test_path_is_dir is
the "-d" etc.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-20 22:25       ` Junio C Hamano
@ 2021-04-21  8:46         ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:39           ` Đoàn Trần Công Danh
  2021-04-21 18:56           ` Junio C Hamano
  0 siblings, 2 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21  8:46 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor


On Wed, Apr 21 2021, Junio C Hamano wrote:

> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>
>> These will only match the simplistic forms of `test -X blah` (where
>> "-X" is some single letter option), but will miss expressions such as
>> `test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
>> things like:
>>
>>     test whatever && ls -a foo
>>     test whatever && foo -o outfile
>
> I still do not understand why you have to insist on dashed operator
> as the first thing given to "test", like this:
>
>> +	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" ...
>> +	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" ...
>
> IOW, what over-matching would we get if we simplified the condition
> like so?
>
>     /\btest\s+[^&|]+\s+-a\s/
>     /\btest\s+[^&|]+\s+-o\s/
>
> The one in the patch would miss things like
>
> 	test "$a" = "$b" -o "$a" -lt "$b"
> 	test "$n" -a "$n" -lt 4
>
> but the only thing that we care about is that a command that started
> with "test " has "-a" or "-o" before we see "&" or "|", no?

Applying your suggestion results in these false positives:
	
	t4038-diff-combined.sh:135: error: "test A && test B" preferred to "test A -a B": git commit -m "test space change" -a &&
	t4038-diff-combined.sh:147: error: "test A && test B" preferred to "test A -a B": git commit -m "test other space changes" -a &&
	t6400-merge-df.sh:89: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l)
	t6400-merge-df.sh:91: error: "test A || test B" preferred to "test A -o B": test 1 -eq $(git ls-files -o | wc -l)
	t6400-merge-df.sh:110: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l)
	t6400-merge-df.sh:112: error: "test A || test B" preferred to "test A -o B": test 1 -eq $(git ls-files -o | wc -l)
	t6402-merge-rename.sh:639: error: "test A || test B" preferred to "test A -o B": test 0 -eq "$(git ls-files -o | wc -l)"
	t6402-merge-rename.sh:646: error: "test A || test B" preferred to "test A -o B": test 2 -eq "$(git ls-files -o | wc -l)"
	t6402-merge-rename.sh:686: error: "test A || test B" preferred to "test A -o B": test 0 -eq "$(git ls-files -o | wc -l)" &&
	t6402-merge-rename.sh:865: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l) &&
	annotate-tests.sh:201: error: "test A && test B" preferred to "test A -a B": GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" git commit -a -m "norobots"

I'll just drop this from the re-roll of this series. Maybe you/someone
has a better suggestion for something that's simple but still catches
these cases, but in any case I'd like to not have this series blocked on
this minor thing (which none of the rest of it needs).

^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                       ` (11 preceding siblings ...)
  2021-04-20 12:22     ` [PATCH v3 12/12] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15     ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
                         ` (11 more replies)
  12 siblings, 12 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

A fast re-roll of this test topic that a few things depend on, per
https://lore.kernel.org/git/xmqqk0ow1plt.fsf@gitster.g/

Changes since v3:

 * Dropped the check-non-portable-shell change

   As noted in
   https://lore.kernel.org/git/87r1j42ffz.fsf@evledraar.gmail.com/ it
   wasn't needed for the rest of this series, so let's not hold it up
   for the discussion of if/how to check "-a" and "-o" invocations of
   "test".

 * Set the remove_trash= variable so we won't leak it from the
   environment.

Ævar Arnfjörð Bjarmason (11):
  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/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                       | 40 +++++++++++--------
 14 files changed, 87 insertions(+), 119 deletions(-)

Range-diff against v3:
 1:  a8b483bc77 <  -:  ---------- check-non-portable-shell: check for "test <cond> -a/-o <cond>"
 2:  39759d00ad !  1:  a76ea749bb test-lib: bring $remove_trash out of retirement
    @@ Commit message
         variable, 2017-04-23) and move the decision about whether to skip all
         tests earlier.
     
    +    Let's also fix a bug that was with us since abc5d372ec (Enable
    +    parallel tests, 2008-08-08): we would leak $remove_trash from the
    +    environment. We don't want this to error out, so let's reset it to the
    +    empty string first:
    +
    +         remove_trash=t GIT_SKIP_TESTS=t0001 ./t0001-init.sh
    +
         I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
         under --debug at the end of the test, 2017-04-24) for a bug we don't
         want to re-introduce.
    @@ t/test-lib.sh: then
      fi
      
     +# Are we running this test at all?
    ++remove_trash=
     +this_test=${0##*/}
     +this_test=${this_test%%-*}
     +if match_pattern_list "$this_test" $GIT_SKIP_TESTS
 3:  d669ce3196 =  2:  de7be7844e test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
 4:  9313d35bf8 =  3:  709bc773fb test-lib-functions: reword "test_commit --append" docs
 5:  c916d648e4 =  4:  b67654334e test-lib-functions: document test_commit --no-tag
 6:  9b6bf65ce1 =  5:  3a166c9206 test-lib functions: add an --annotated option to "test_commit"
 7:  683b3ba3dd =  6:  981fc43ee6 describe tests: convert setup to use test_commit
 8:  dc0a863db7 =  7:  15057cdecf test-lib functions: add --printf option to test_commit
 9:  90bf55d2d4 =  8:  5d437f53ec submodule tests: use symbolic-ref --short to discover branch name
10:  e0a1e2fd52 =  9:  9ee13ee71b test-lib: reformat argument list in test_create_repo()
11:  cedf5d383b = 10:  6ba568df9f test-lib: do not show advice about init.defaultBranch under --verbose
12:  0dc0da9490 = 11:  311a9dba36 test-lib: split up and deprecate test_create_repo()
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v4 01/11] test-lib: bring $remove_trash out of retirement
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
                         ` (10 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

There's no point in creating a repository or directory only to decide
right afterwards that we're skipping all the tests. We can save
ourselves the redundant "git init" or "mkdir" and "rm -rf" in this
case.

We carry around the "$remove_trash" variable because if the directory
is unexpectedly gone at test_done time we'll hit the error about it
being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
can't remove trash directory, 2017-04-20).

So let's partially revert 06478dab4c (test-lib: retire $remove_trash
variable, 2017-04-23) and move the decision about whether to skip all
tests earlier.

Let's also fix a bug that was with us since abc5d372ec (Enable
parallel tests, 2008-08-08): we would leak $remove_trash from the
environment. We don't want this to error out, so let's reset it to the
empty string first:

     remove_trash=t GIT_SKIP_TESTS=t0001 ./t0001-init.sh

I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
under --debug at the end of the test, 2017-04-24) for a bug we don't
want to re-introduce.

While I'm at it let's move the HOME assignment to just before
test_create_repo, it could be lower, but it seems better to set it
before calling anything in test-lib-functions.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib.sh | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 3dec266221..105c424bf5 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,7 +1169,7 @@ test_done () {
 			esac
 		fi
 
-		if test -z "$debug"
+		if test -z "$debug" && test -n "$remove_trash"
 		then
 			test -d "$TRASH_DIRECTORY" ||
 			error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1334,6 +1334,22 @@ then
 	exit 1
 fi
 
+# Are we running this test at all?
+remove_trash=
+this_test=${0##*/}
+this_test=${this_test%%-*}
+if match_pattern_list "$this_test" $GIT_SKIP_TESTS
+then
+	say_color info >&3 "skipping test $this_test altogether"
+	skip_all="skip all tests in $this_test"
+	test_done
+fi
+
+# Last-minute variable setup
+HOME="$TRASH_DIRECTORY"
+GNUPGHOME="$HOME/gnupg-home-not-used"
+export HOME GNUPGHOME
+
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {
 	GIT_EXIT_OK=t
@@ -1341,10 +1357,7 @@ rm -fr "$TRASH_DIRECTORY" || {
 	exit 1
 }
 
-HOME="$TRASH_DIRECTORY"
-GNUPGHOME="$HOME/gnupg-home-not-used"
-export HOME GNUPGHOME
-
+remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
 	test_create_repo "$TRASH_DIRECTORY"
@@ -1356,15 +1369,6 @@ fi
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
 
-this_test=${0##*/}
-this_test=${this_test%%-*}
-if match_pattern_list "$this_test" $GIT_SKIP_TESTS
-then
-	say_color info >&3 "skipping test $this_test altogether"
-	skip_all="skip all tests in $this_test"
-	test_done
-fi
-
 if test -n "$write_junit_xml"
 then
 	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
                         ` (9 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Stop setting the GIT_TEST_FRAMEWORK_SELFTEST variable. This was originally needed
back in 4231d1ba99 (t0000: do not get self-test disrupted by
environment warnings, 2018-09-20).

It hasn't been needed since I deleted the relevant code in test-lib.sh
in c0eedbc009 (test-lib: remove check_var_migration, 2021-02-09), I
just didn't notice that it was set here.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0000-basic.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 705d62cc27..2c6e34b947 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
 		passing metrics
 		'
 
-		# Tell the framework that we are self-testing to make sure
-		# it yields a stable result.
-		GIT_TEST_FRAMEWORK_SELFTEST=t &&
-
 		# Point to the t/test-lib.sh, which isn't in ../ as usual
 		. "\$TEST_DIRECTORY"/test-lib.sh
 		EOF
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 03/11] test-lib-functions: reword "test_commit --append" docs
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
                         ` (8 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Reword the documentation for "test_commit --append" added in my
3373518cc8 (test-lib functions: add an --append option to test_commit,
2021-01-12).

A follow-up commit will make the "echo" part of this configurable, and
in any case saying "echo >>" rather than ">>" was redundant.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6348e8d733..d169fb2f59 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -172,8 +172,7 @@ debug () {
 #   --notick
 #	Do not call test_tick before making a commit
 #   --append
-#	Use "echo >>" instead of "echo >" when writing "<contents>" to
-#	"<file>"
+#	Use ">>" instead of ">" when writing "<contents>" to "<file>"
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 04/11] test-lib-functions: document test_commit --no-tag
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (2 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
                         ` (7 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

In 76b8b8d05c (test-lib functions: document arguments to test_commit,
2021-01-12) I added missing documentation to test_commit, but in less
than a month later in 3803a3a099 (t: add --no-tag option to
test_commit, 2021-02-09) we got another undocumented option. Let's fix
that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d169fb2f59..d0f4f3885d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -177,6 +177,8 @@ debug () {
 #	Invoke "git commit" with --signoff
 #   --author <author>
 #	Invoke "git commit" with --author <author>
+#   --no-tag
+#	Do not tag the resulting commit
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 05/11] test-lib functions: add an --annotated option to "test_commit"
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (3 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
                         ` (6 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Add an --annotated option to test_commit to create annotated tags. The
tag will share the same message as the commit, and we'll call
test_tick before creating it (unless --notick) is provided.

There's quite a few tests that could be simplified with this
construct. I've picked one to convert in this change as a
demonstration.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1403-show-ref.sh     |  6 ++----
 t/test-lib-functions.sh | 27 ++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 6ce62f878c..17d3cc1405 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
-	git tag -f -a -m "annotated A" A &&
+	test_commit --annotate A &&
 	git checkout -b side &&
-	test_commit B &&
-	git tag -f -a -m "annotated B" B &&
+	test_commit --annotate B &&
 	git checkout main &&
 	test_commit C &&
 	git branch B A^0
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index d0f4f3885d..6e2332a324 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -179,6 +179,10 @@ debug () {
 #	Invoke "git commit" with --author <author>
 #   --no-tag
 #	Do not tag the resulting commit
+#   --annotate
+#	Create an annotated tag with "--annotate -m <message>". Calls
+#	test_tick between making the commit and tag, unless --notick
+#	is given.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -191,7 +195,7 @@ test_commit () {
 	author= &&
 	signoff= &&
 	indir= &&
-	no_tag= &&
+	tag=light &&
 	while test $# != 0
 	do
 		case "$1" in
@@ -219,7 +223,10 @@ test_commit () {
 			shift
 			;;
 		--no-tag)
-			no_tag=yes
+			tag=none
+			;;
+		--annotate)
+			tag=annotate
 			;;
 		*)
 			break
@@ -243,10 +250,20 @@ test_commit () {
 	git ${indir:+ -C "$indir"} commit \
 	    ${author:+ --author "$author"} \
 	    $signoff -m "$1" &&
-	if test -z "$no_tag"
-	then
+	case "$tag" in
+	none)
+		;;
+	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
-	fi
+		;;
+	annotate)
+		if test -z "$notick"
+		then
+			test_tick
+		fi &&
+		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
+		;;
+	esac
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 06/11] describe tests: convert setup to use test_commit
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (4 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
                         ` (5 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Convert the setup of the describe tests to use test_commit when
possible. This makes use of the new --annotated-tag option to
test_commit.

Some of the setup here could simply be removed since the data being
created wasn't important to any of the subsequent tests, so I've done
so. E.g. assigning to the "one" variable was always useless, and just
checking that we can describe HEAD after the first commit wasn't
useful.

In the case of the "two" variable we could instead use the tag we just
created. See 5312ab11fbf (Add describe test., 2007-01-13) for the
initial version of this code. There's other cases here like redundant
"test_tick" invocations, or the simplification of not echoing "X" to a
file we're about to tag as "x", now we just use "x" in both cases.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6120-describe.sh | 58 ++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 45 deletions(-)

diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index e89b6747be..88fddc9142 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -31,64 +31,32 @@ check_describe () {
 }
 
 test_expect_success setup '
+	test_commit initial file one &&
+	test_commit second file two &&
+	test_commit third file three &&
+	test_commit --annotate A file A &&
+	test_commit c file c &&
 
-	test_tick &&
-	echo one >file && git add file && git commit -m initial &&
-	one=$(git rev-parse HEAD) &&
-
-	git describe --always HEAD &&
-
-	test_tick &&
-	echo two >file && git add file && git commit -m second &&
-	two=$(git rev-parse HEAD) &&
-
-	test_tick &&
-	echo three >file && git add file && git commit -m third &&
-
-	test_tick &&
-	echo A >file && git add file && git commit -m A &&
-	test_tick &&
-	git tag -a -m A A &&
-
-	test_tick &&
-	echo c >file && git add file && git commit -m c &&
-	test_tick &&
-	git tag c &&
-
-	git reset --hard $two &&
-	test_tick &&
-	echo B >side && git add side && git commit -m B &&
-	test_tick &&
-	git tag -a -m B B &&
+	git reset --hard second &&
+	test_commit --annotate B side B &&
 
 	test_tick &&
 	git merge -m Merged c &&
 	merged=$(git rev-parse HEAD) &&
 
-	git reset --hard $two &&
-	test_tick &&
-	echo D >another && git add another && git commit -m D &&
-	test_tick &&
-	git tag -a -m D D &&
-	test_tick &&
-	git tag -a -m R R &&
-
-	test_tick &&
-	echo DD >another && git commit -a -m another &&
+	git reset --hard second &&
+	test_commit --no-tag D another D &&
 
 	test_tick &&
-	git tag e &&
+	git tag -a -m R R &&
 
-	test_tick &&
-	echo DDD >another && git commit -a -m "yet another" &&
+	test_commit e another DD &&
+	test_commit --no-tag "yet another" another DDD &&
 
 	test_tick &&
 	git merge -m Merged $merged &&
 
-	test_tick &&
-	echo X >file && echo X >side && git add file side &&
-	git commit -m x
-
+	test_commit --no-tag x file
 '
 
 check_describe A-* HEAD
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 07/11] test-lib functions: add --printf option to test_commit
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (5 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
                         ` (4 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Add a --printf option to test_commit to allow writing to the file with
"printf" instead of "echo".

This is useful for writing "\n", "\0" etc., in particular in
combination with the --append option added in 3373518cc8 (test-lib
functions: add an --append option to test_commit, 2021-01-12).

I'm converting a few tests to use the new option rather than a manual
printf/add/commit combination to demonstrate its usefulness. While I'm
at it use "test_create_repo" where appropriate, and give the
first/second commit a meaningful/more conventional log message in
cases where no test cared about that message.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1307-config-blob.sh    |  4 +---
 t/t2030-unresolve-info.sh |  3 +--
 t/t4006-diff-mode.sh      |  6 ++----
 t/t4030-diff-textconv.sh  |  8 ++------
 t/t5520-pull.sh           | 10 ++--------
 t/test-lib-functions.sh   | 12 ++++++++++--
 6 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 002e6d3388..930dce06f0 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
 '
 
 test_expect_success 'can parse blob ending with CR' '
-	printf "[some]key = value\\r" >config &&
-	git add config &&
-	git commit -m CR &&
+	test_commit --printf CR config "[some]key = value\\r" &&
 	echo value >expect &&
 	git config --blob=HEAD:config some.key >actual &&
 	test_cmp expect actual
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index be6c84c52a..f691e6d903 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
 
 test_expect_success 'rerere forget (binary)' '
 	git checkout -f side &&
-	printf "a\0c" >binary &&
-	git commit -a -m binary &&
+	test_commit --printf binary binary "a\0c" &&
 	test_must_fail git merge second &&
 	git rerere forget binary
 '
diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh
index 275ce5fa15..6cdee2a216 100755
--- a/t/t4006-diff-mode.sh
+++ b/t/t4006-diff-mode.sh
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
 '
 
 test_expect_success 'prepare binary file' '
-	git commit -m rezrov &&
-	printf "\00\01\02\03\04\05\06" >binbin &&
-	git add binbin &&
-	git commit -m binbin
+	git commit -m one &&
+	test_commit --printf two binbin "\00\01\02\03\04\05\06"
 '
 
 test_expect_success '--stat output after text chmod' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index c906320b60..a39a626664 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -26,12 +26,8 @@ EOF
 chmod +x hexdump
 
 test_expect_success 'setup binary file with history' '
-	printf "\\0\\n" >file &&
-	git add file &&
-	git commit -m one &&
-	printf "\\01\\n" >>file &&
-	git add file &&
-	git commit -m two
+	test_commit --printf one file "\\0\\n" &&
+	test_commit --printf --append two file "\\01\\n"
 '
 
 test_expect_success 'file is considered binary by porcelain' '
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a09411327f..e2c0c51022 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 '
 
 test_expect_success 'setup for detecting upstreamed changes' '
-	mkdir src &&
-	(
-		cd src &&
-		git init &&
-		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-		git add stuff &&
-		git commit -m "Initial revision"
-	) &&
+	test_create_repo src &&
+	test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
 	git clone src dst &&
 	(
 		cd src &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6e2332a324..dbeb3d9262 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -173,6 +173,10 @@ debug () {
 #	Do not call test_tick before making a commit
 #   --append
 #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
+#   --printf
+#       Use "printf" instead of "echo" when writing "<contents>" to
+#       "<file>". You will need to provide your own trailing "\n". You
+#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
@@ -191,6 +195,7 @@ debug () {
 
 test_commit () {
 	notick= &&
+	echo=echo &&
 	append= &&
 	author= &&
 	signoff= &&
@@ -202,6 +207,9 @@ test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--printf)
+			echo=printf
+			;;
 		--append)
 			append=yes
 			;;
@@ -238,9 +246,9 @@ test_commit () {
 	file=${2:-"$1.t"} &&
 	if test -n "$append"
 	then
-		echo "${3-$1}" >>"$indir$file"
+		$echo "${3-$1}" >>"$indir$file"
 	else
-		echo "${3-$1}" >"$indir$file"
+		$echo "${3-$1}" >"$indir$file"
 	fi &&
 	git ${indir:+ -C "$indir"} add "$file" &&
 	if test -z "$notick"
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 08/11] submodule tests: use symbolic-ref --short to discover branch name
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (6 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
                         ` (3 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Change a use of $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME added in
704fed9ea22 (tests: start moving to a different default main branch
name, 2020-10-23) to simply discover the initial branch name of a
repository set up in this function with "symbolic-ref --short".

That's something done in another test in 704fed9ea22, so doing it like
this seems like an omission, or rather an overly eager
search/replacement instead of fixing the test logic.

There are only three uses of the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
variable in the test suite, this gets rid of one of those.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-submodule-update.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 4b714e9308..f7c7df0ca4 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
 	git init submodule_update_repo &&
 	(
 		cd submodule_update_repo &&
+		branch=$(git symbolic-ref --short HEAD) &&
 		echo "expect" >>.gitignore &&
 		echo "actual" >>.gitignore &&
 		echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
 		git checkout -b valid_sub1 &&
 		git revert HEAD &&
 
-		git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
+		git checkout "$branch"
 	)
 }
 
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 09/11] test-lib: reformat argument list in test_create_repo()
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (7 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
                         ` (2 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Reformat an argument list changed in 675704c74dd (init: provide useful
advice about init.defaultBranch, 2020-12-11) to have the "-c" on the
same line as the argument it sets. This whitespace-only change makes
it easier to review a subsequent commit.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index dbeb3d9262..21271020c7 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1257,8 +1257,8 @@ test_create_repo () {
 	mkdir -p "$repo"
 	(
 		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
-			init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
+		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
+			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 10/11] test-lib: do not show advice about init.defaultBranch under --verbose
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (8 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:15       ` [PATCH v4 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Arrange for the advice about naming the initial branch not to be shown
in the --verbose output of the test suite.

Since 675704c74dd (init: provide useful advice about
init.defaultBranch, 2020-12-11) some tests have been very chatty with
repeated occurrences of this multi-line advice. Having it be this
verbose isn't helpful for anyone in the context of git's own test
suite, and it makes debugging tests that use their own "git init"
invocations needlessly distracting.

By setting the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME variable early in
test-lib.sh itself we'll squash the warning not only for
test_create_repo(), as 675704c74dd explicitly intended, but also for
other "git init" invocations.

And once we'd like to have this configuration set for all "git init"
invocations in the test suite we can get rid of the init.defaultBranch
configuration setting in test_create_repo(), as
repo_default_branch_name() in refs.c will take the GIT_TEST_* variable
over it being set.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 1 -
 t/test-lib.sh           | 5 +++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 21271020c7..8e75a013a4 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1258,7 +1258,6 @@ test_create_repo () {
 	(
 		cd "$repo" || error "Cannot setup test environment"
 		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 105c424bf5..ab1fe98ccc 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -64,6 +64,11 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 fi
 
+# Explicitly set the default branch name for testing, to avoid the
+# transitory "git init" warning under --verbose.
+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
 ################################################################
 # It appears that people try to run tests without building...
 "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v4 11/11] test-lib: split up and deprecate test_create_repo()
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (9 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:15       ` Ævar Arnfjörð Bjarmason
  2021-04-21 16:43         ` SZEDER Gábor
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  11 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 10:15 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

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.

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.

 2. Since we're now a simple wrapper for "git init" we don't need to
    check that we have only one argument. If someone wants to run
    "test_create_repo --bare x" that's OK.

 3. We won't ever hit that "Cannot setup test environment"
    error.

    Checking the test environment sanity when doing "git init" dates
    back to eea420693be (t0000: catch trivial pilot errors.,
    2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
    was successfully created, 2006-01-05).

    We can also see it in another form a bit later in my own
    0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
    $old, 2010-08-30).

    But since 2006f0adaee (t/test-lib: make sure Git has already been
    built, 2012-09-17) we already check if we have a built git
    earlier.

    The one thing this was testing after that 2012 change was that
    we'd just built "git", but not "git-init", but since
    3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
    repositories, 2018-11-12) we invoke "git", not "git-init".

    So all of that's been checked already, and we don't need to
    re-check it here.

 4. We don't need to move .git/hooks out of the way.

    That dates back to c09a69a83e3 (Disable hooks during tests.,
    2005-10-16), since then hooks became disabled by default in
    f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).

    So the hooks were already disabled by default, but as can be seen
    from "mkdir .git/hooks" changes various tests needed to re-setup
    that directory. Now they no longer do.

 5. Since we don't need to move the .git/hooks directory we don't need
    the subshell here either.

    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.

    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.

 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

    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/t5406-remote-rejects.sh           |  1 -
 t/t5407-post-rewrite-hook.sh        |  2 --
 t/t5409-colorize-remote-messages.sh |  1 -
 t/test-lib-functions.sh             | 15 ++-------------
 t/test-lib.sh                       |  3 ++-
 5 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh
index ff06f99649..5c509db6fc 100755
--- a/t/t5406-remote-rejects.sh
+++ b/t/t5406-remote-rejects.sh
@@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	exit 1
 	EOF
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 5bb23cc3a4..6da8d760e2 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -20,8 +20,6 @@ test_expect_success 'setup' '
 	git checkout main
 '
 
-mkdir .git/hooks
-
 cat >.git/hooks/post-rewrite <<EOF
 #!/bin/sh
 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index 5d8f401d8e..9f1a483f42 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	echo error: error
 	echo ERROR: also highlighted
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 8e75a013a4..bd64a15c73 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1248,21 +1248,10 @@ test_atexit () {
 		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
 }
 
-# Most tests can use the created repository, but some may need to create more.
+# Deprecated wrapper for "git init", use "git init" directly instead
 # Usage: test_create_repo <directory>
 test_create_repo () {
-	test "$#" = 1 ||
-	BUG "not 1 parameter to test-create-repo"
-	repo="$1"
-	mkdir -p "$repo"
-	(
-		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			init \
-			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
-		error "cannot run git init -- have you built things yet?"
-		mv .git/hooks .git/hooks-disabled
-	) || exit
+	git init "$@"
 }
 
 # This function helps on symlink challenged file systems when it is not
diff --git a/t/test-lib.sh b/t/test-lib.sh
index ab1fe98ccc..5fd968d11b 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1365,7 +1365,8 @@ rm -fr "$TRASH_DIRECTORY" || {
 remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
-	test_create_repo "$TRASH_DIRECTORY"
+	git init "$TRASH_DIRECTORY" >&3 2>&4 ||
+	error "cannot run git init"
 else
 	mkdir -p "$TRASH_DIRECTORY"
 fi
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-21  8:46         ` Ævar Arnfjörð Bjarmason
@ 2021-04-21 10:39           ` Đoàn Trần Công Danh
  2021-04-21 10:41             ` [PATCH 1/2] t6400: check exit status of ls-files Đoàn Trần Công Danh
  2021-04-21 14:18             ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
  2021-04-21 18:56           ` Junio C Hamano
  1 sibling, 2 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-04-21 10:39 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Junio C Hamano, git, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine, SZEDER Gábor

On 2021-04-21 10:46:08+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> 
> On Wed, Apr 21 2021, Junio C Hamano wrote:
> 
> > Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
> >
> >> These will only match the simplistic forms of `test -X blah` (where
> >> "-X" is some single letter option), but will miss expressions such as
> >> `test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
> >> things like:
> >>
> >>     test whatever && ls -a foo
> >>     test whatever && foo -o outfile
> >
> > I still do not understand why you have to insist on dashed operator
> > as the first thing given to "test", like this:
> >
> >> +	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" ...
> >> +	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" ...
> >
> > IOW, what over-matching would we get if we simplified the condition
> > like so?
> >
> >     /\btest\s+[^&|]+\s+-a\s/
> >     /\btest\s+[^&|]+\s+-o\s/
> >
> > The one in the patch would miss things like
> >
> > 	test "$a" = "$b" -o "$a" -lt "$b"
> > 	test "$n" -a "$n" -lt 4
> >
> > but the only thing that we care about is that a command that started
> > with "test " has "-a" or "-o" before we see "&" or "|", no?
> 
> Applying your suggestion results in these false positives:
> 	
> 	t4038-diff-combined.sh:135: error: "test A && test B" preferred to "test A -a B": git commit -m "test space change" -a &&
> 	t4038-diff-combined.sh:147: error: "test A && test B" preferred to "test A -a B": git commit -m "test other space changes" -a &&
> 	t6400-merge-df.sh:89: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l)
> 	t6400-merge-df.sh:91: error: "test A || test B" preferred to "test A -o B": test 1 -eq $(git ls-files -o | wc -l)
> 	t6400-merge-df.sh:110: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l)
> 	t6400-merge-df.sh:112: error: "test A || test B" preferred to "test A -o B": test 1 -eq $(git ls-files -o | wc -l)
> 	t6402-merge-rename.sh:639: error: "test A || test B" preferred to "test A -o B": test 0 -eq "$(git ls-files -o | wc -l)"
> 	t6402-merge-rename.sh:646: error: "test A || test B" preferred to "test A -o B": test 2 -eq "$(git ls-files -o | wc -l)"
> 	t6402-merge-rename.sh:686: error: "test A || test B" preferred to "test A -o B": test 0 -eq "$(git ls-files -o | wc -l)" &&
> 	t6402-merge-rename.sh:865: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l) &&

With: 7dbe8c8003, (check-non-portable-shell.pl: `wc -l` may have
leading WS, 2017-12-21)
Unless the situation has been changed, since.
I think those tests with quoted "$(.. | wc -l)" has been deemed
unportable and should be replaced with test_line_count anyway?
Does "test -eq" strip spaces from integer strings?

And I think we're working on moving "git" command to its own commmand
instead of put it in the left of a pipe.

2 followed patch will clean them out


-- 
Danh

^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH 1/2] t6400: check exit status of ls-files
  2021-04-21 10:39           ` Đoàn Trần Công Danh
@ 2021-04-21 10:41             ` Đoàn Trần Công Danh
  2021-04-21 10:41               ` [PATCH 2/2] t6402: " Đoàn Trần Công Danh
  2021-04-21 14:18             ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
  1 sibling, 1 reply; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-04-21 10:41 UTC (permalink / raw)
  To: git; +Cc: Đoàn Trần Công Danh

We will lose the exit status of "git ls-files" if it's being run in
anywhere-but-not-final part of a pipe.

Let's send the output of "git ls-files" to a file first,
and adjust the expected result for "git ls-files -o" since a new
untracked file will be created as a side effect.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
 t/t6400-merge-df.sh | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/t/t6400-merge-df.sh b/t/t6400-merge-df.sh
index 38700d29b5..fd99a78360 100755
--- a/t/t6400-merge-df.sh
+++ b/t/t6400-merge-df.sh
@@ -82,13 +82,16 @@ test_expect_success 'modify/delete + directory/file conflict' '
 	git checkout delete^0 &&
 	test_must_fail git merge modify &&
 
-	test 5 -eq $(git ls-files -s | wc -l) &&
-	test 4 -eq $(git ls-files -u | wc -l) &&
+	git ls-files -s >out &&
+	test_line_count = 5 out &&
+	git ls-files -u >out &&
+	test_line_count = 4 out &&
+	git ls-files -o >out &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 0 -eq $(git ls-files -o | wc -l)
+		test_line_count = 1 out
 	else
-		test 1 -eq $(git ls-files -o | wc -l)
+		test_line_count = 2 out
 	fi &&
 
 	test_path_is_file letters/file &&
@@ -103,13 +106,16 @@ test_expect_success 'modify/delete + directory/file conflict; other way' '
 
 	test_must_fail git merge delete &&
 
-	test 5 -eq $(git ls-files -s | wc -l) &&
-	test 4 -eq $(git ls-files -u | wc -l) &&
+	git ls-files -s >out &&
+	test_line_count = 5 out &&
+	git ls-files -u >out &&
+	test_line_count = 4 out &&
+	git ls-files -o >out &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 0 -eq $(git ls-files -o | wc -l)
+		test_line_count = 1 out
 	else
-		test 1 -eq $(git ls-files -o | wc -l)
+		test_line_count = 2 out
 	fi &&
 
 	test_path_is_file letters/file &&
-- 
2.31.1.192.g0881477623


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-21 10:41             ` [PATCH 1/2] t6400: check exit status of ls-files Đoàn Trần Công Danh
@ 2021-04-21 10:41               ` Đoàn Trần Công Danh
  2021-04-21 16:55                 ` Eric Sunshine
  0 siblings, 1 reply; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-04-21 10:41 UTC (permalink / raw)
  To: git; +Cc: Đoàn Trần Công Danh

We will lose the exit status of "git ls-files" if it's being run in
anywhere-but-not-final part of a pipe.

Let's send the output of "git ls-files" to a file first,
and adjust the expected result for "git ls-files -o" since a new
untracked file will be created as a side effect.

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
 t/t6402-merge-rename.sh | 148 +++++++++++++++++++++++++++-------------
 1 file changed, 101 insertions(+), 47 deletions(-)

diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh
index 425dad97d5..d705847f26 100755
--- a/t/t6402-merge-rename.sh
+++ b/t/t6402-merge-rename.sh
@@ -330,8 +330,10 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
 		test_i18ngrep "Adding as dir~HEAD instead" output
 	fi &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -357,8 +359,10 @@ test_expect_success 'Same as previous, but merged other way' '
 		test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output
 	fi &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -374,8 +378,10 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in
 	git checkout -q renamed-file-has-conflicts^0 &&
 	test_must_fail git merge --strategy=recursive dir-not-in-way &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 3 -eq "$(git ls-files -u dir | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u dir >output &&
+	test_line_count = 3 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -409,14 +415,19 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t
 	git checkout -q renamed-file-has-conflicts^0 &&
 	test_must_fail git merge --strategy=recursive dir-in-way &&
 
-	test 5 -eq "$(git ls-files -u | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 5 output &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 3 -eq "$(git ls-files -u dir~HEAD | wc -l)"
+		git ls-files -u dir~HEAD >output &&
+		test_line_count = 3 output
 	else
-		test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
+		git ls-files -u dir >output &&
+		grep -v file-in-the-way output >filtered
+		test_line_count = 3 filtered
 	fi &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -432,14 +443,19 @@ test_expect_success 'Same as previous, but merged other way' '
 	git checkout -q dir-in-way^0 &&
 	test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
 
-	test 5 -eq "$(git ls-files -u | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 5 output &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 3 -eq "$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)"
+		git ls-files -u dir~renamed-file-has-conflicts >output &&
+		test_line_count = 3 output
 	else
-		test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
+		git ls-files -u dir >output &&
+		grep -v file-in-the-way output >filtered
+		test_line_count = 3 filtered
 	fi &&
-	test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
+	git ls-files -u dir/file-in-the-way >output &&
+	test_line_count = 2 output &&
 
 	test_must_fail git diff --quiet &&
 	test_must_fail git diff --cached --quiet &&
@@ -494,11 +510,12 @@ test_expect_success 'both rename source and destination involved in D/F conflict
 	git checkout -q rename-dest^0 &&
 	test_must_fail git merge --strategy=recursive source-conflict &&
 
+	git ls-files -u >output &&
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 2 -eq "$(git ls-files -u | wc -l)"
+		test_line_count = 2 output
 	else
-		test 1 -eq "$(git ls-files -u | wc -l)"
+		test_line_count = 1 output
 	fi &&
 
 	test_must_fail git diff --quiet &&
@@ -540,9 +557,13 @@ then
 		mkdir one &&
 		test_must_fail git merge --strategy=recursive rename-two &&
 
-		test 4 -eq "$(git ls-files -u | wc -l)" &&
-		test 2 -eq "$(git ls-files -u one | wc -l)" &&
-		test 2 -eq "$(git ls-files -u two | wc -l)" &&
+		git ls-files -u >output &&
+		test_line_count = 4 output &&
+		git ls-files -u one >output &&
+		test_line_count = 2 output &&
+		git ls-files -u two >output &&
+		test_line_count = 2 output &&
+		rm -f output &&
 
 		test_must_fail git diff --quiet &&
 
@@ -559,9 +580,13 @@ else
 		mkdir one &&
 		test_must_fail git merge --strategy=recursive rename-two &&
 
-		test 2 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two | wc -l)" &&
+		git ls-files -u >output &&
+		test_line_count = 2 output &&
+		git ls-files -u one >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two >output &&
+		test_line_count = 1 output &&
+		rm -f output &&
 
 		test_must_fail git diff --quiet &&
 
@@ -582,14 +607,21 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta
 
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 4 -eq "$(git ls-files -u | wc -l)" &&
-		test 2 -eq "$(git ls-files -u one | wc -l)" &&
-		test 2 -eq "$(git ls-files -u two | wc -l)"
+		git ls-files -u >output &&
+		test_line_count = 4 output &&
+		git ls-files -u one >output &&
+		test_line_count = 2 output &&
+		git ls-files -u two >output &&
+		test_line_count = 2 output
 	else
-		test 2 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two | wc -l)"
+		git ls-files -u >output &&
+		test_line_count = 2 output &&
+		git ls-files -u one >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two >output &&
+		test_line_count = 1 output
 	fi &&
+	rm -f output &&
 
 	test_must_fail git diff --quiet &&
 
@@ -631,20 +663,33 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
 
 	if test "$GIT_TEST_MERGE_ALGORITHM" = ort
 	then
-		test 5 -eq "$(git ls-files -s | wc -l)" &&
-		test 3 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two~second-rename | wc -l)" &&
-		test 1 -eq "$(git ls-files -u original | wc -l)" &&
-		test 0 -eq "$(git ls-files -o | wc -l)"
+		git ls-files -s >output &&
+		test_line_count = 5 output &&
+		git ls-files -u >output &&
+		test_line_count = 3 output &&
+		git ls-files -u one~HEAD >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two~second-rename >output &&
+		test_line_count = 1 output &&
+		git ls-files -u original >output &&
+		test_line_count = 1 output &&
+		git ls-files -o >output &&
+		test_line_count = 1 output
 	else
-		test 5 -eq "$(git ls-files -s | wc -l)" &&
-		test 3 -eq "$(git ls-files -u | wc -l)" &&
-		test 1 -eq "$(git ls-files -u one | wc -l)" &&
-		test 1 -eq "$(git ls-files -u two | wc -l)" &&
-		test 1 -eq "$(git ls-files -u original | wc -l)" &&
-		test 2 -eq "$(git ls-files -o | wc -l)"
+		git ls-files -s >output &&
+		test_line_count = 5 output &&
+		git ls-files -u >output &&
+		test_line_count = 3 output &&
+		git ls-files -u one >output &&
+		test_line_count = 1 output &&
+		git ls-files -u two >output &&
+		test_line_count = 1 output &&
+		git ls-files -u original >output &&
+		test_line_count = 1 output &&
+		git ls-files -o >output &&
+		test_line_count = 3 output
 	fi &&
+	rm -f output &&
 
 	test_path_is_file one/file &&
 	test_path_is_file two/file &&
@@ -679,11 +724,17 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
 	git checkout -q first-rename-redo^0 &&
 	test_must_fail git merge --strategy=recursive second-rename-redo &&
 
-	test 3 -eq "$(git ls-files -u | wc -l)" &&
-	test 1 -eq "$(git ls-files -u one | wc -l)" &&
-	test 1 -eq "$(git ls-files -u two | wc -l)" &&
-	test 1 -eq "$(git ls-files -u original | wc -l)" &&
-	test 0 -eq "$(git ls-files -o | wc -l)" &&
+	git ls-files -u >output &&
+	test_line_count = 3 output &&
+	git ls-files -u one >output &&
+	test_line_count = 1 output &&
+	git ls-files -u two >output &&
+	test_line_count = 1 output &&
+	git ls-files -u original >output &&
+	test_line_count = 1 output &&
+	git ls-files -o >output &&
+	test_line_count = 1 output &&
+	rm -f output &&
 
 	test_path_is_file one &&
 	test_path_is_file two &&
@@ -861,8 +912,11 @@ test_expect_success 'setup merge of rename + small change' '
 test_expect_success 'merge rename + small change' '
 	git merge rename_branch &&
 
-	test 1 -eq $(git ls-files -s | wc -l) &&
-	test 0 -eq $(git ls-files -o | wc -l) &&
+	git ls-files -s >output &&
+	test_line_count = 1 output &&
+	git ls-files -o >output &&
+	test_line_count = 1 output &&
+	rm -f output &&
 	test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
 '
 
-- 
2.31.1.192.g0881477623


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-21 10:39           ` Đoàn Trần Công Danh
  2021-04-21 10:41             ` [PATCH 1/2] t6400: check exit status of ls-files Đoàn Trần Công Danh
@ 2021-04-21 14:18             ` Ævar Arnfjörð Bjarmason
  2021-04-21 16:32               ` Junio C Hamano
  1 sibling, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 14:18 UTC (permalink / raw)
  To: Đoàn Trần Công Danh
  Cc: Junio C Hamano, git, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine, SZEDER Gábor


On Wed, Apr 21 2021, Đoàn Trần Công Danh wrote:

> On 2021-04-21 10:46:08+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> 
>> On Wed, Apr 21 2021, Junio C Hamano wrote:
>> 
>> > Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
>> >
>> >> These will only match the simplistic forms of `test -X blah` (where
>> >> "-X" is some single letter option), but will miss expressions such as
>> >> `test "$foo" = bar`. We stop at "&" or "|" to try not to overmatch
>> >> things like:
>> >>
>> >>     test whatever && ls -a foo
>> >>     test whatever && foo -o outfile
>> >
>> > I still do not understand why you have to insist on dashed operator
>> > as the first thing given to "test", like this:
>> >
>> >> +	/\btest\s+-[a-z]\s+[^&|]+\s+-a\s+/ and err '"test A && test B" ...
>> >> +	/\btest\s+-[a-z]\s+[^&|]+\s+-o\s+/ and err '"test A || test B" ...
>> >
>> > IOW, what over-matching would we get if we simplified the condition
>> > like so?
>> >
>> >     /\btest\s+[^&|]+\s+-a\s/
>> >     /\btest\s+[^&|]+\s+-o\s/
>> >
>> > The one in the patch would miss things like
>> >
>> > 	test "$a" = "$b" -o "$a" -lt "$b"
>> > 	test "$n" -a "$n" -lt 4
>> >
>> > but the only thing that we care about is that a command that started
>> > with "test " has "-a" or "-o" before we see "&" or "|", no?
>> 
>> Applying your suggestion results in these false positives:
>> 	
>> 	t4038-diff-combined.sh:135: error: "test A && test B" preferred to "test A -a B": git commit -m "test space change" -a &&
>> 	t4038-diff-combined.sh:147: error: "test A && test B" preferred to "test A -a B": git commit -m "test other space changes" -a &&
>> 	t6400-merge-df.sh:89: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l)
>> 	t6400-merge-df.sh:91: error: "test A || test B" preferred to "test A -o B": test 1 -eq $(git ls-files -o | wc -l)
>> 	t6400-merge-df.sh:110: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l)
>> 	t6400-merge-df.sh:112: error: "test A || test B" preferred to "test A -o B": test 1 -eq $(git ls-files -o | wc -l)
>> 	t6402-merge-rename.sh:639: error: "test A || test B" preferred to "test A -o B": test 0 -eq "$(git ls-files -o | wc -l)"
>> 	t6402-merge-rename.sh:646: error: "test A || test B" preferred to "test A -o B": test 2 -eq "$(git ls-files -o | wc -l)"
>> 	t6402-merge-rename.sh:686: error: "test A || test B" preferred to "test A -o B": test 0 -eq "$(git ls-files -o | wc -l)" &&
>> 	t6402-merge-rename.sh:865: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l) &&
>
> With: 7dbe8c8003, (check-non-portable-shell.pl: `wc -l` may have
> leading WS, 2017-12-21)
> Unless the situation has been changed, since.
> I think those tests with quoted "$(.. | wc -l)" has been deemed
> unportable and should be replaced with test_line_count anyway?
> Does "test -eq" strip spaces from integer strings?
>
> And I think we're working on moving "git" command to its own commmand
> instead of put it in the left of a pipe.
>
> 2 followed patch will clean them out

I think those patches are good in their own right, i.e. replacing things
with more incremental helpers and test_cmp-like functions.

But I believe the code you're changing is not non-portable. It was using
the output of "wc -l" with the "=" operator that wasn't portable.

These ones are all occurances that use "-eq".

And:

    test "0" -eq " 0"

etc., is true, which is why these pass on OSX and beyond.


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose
  2021-04-20 12:29 ` [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
                     ` (2 preceding siblings ...)
  2021-04-20 12:29   ` [PATCH v2 3/3] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
@ 2021-04-21 14:58   ` Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 1/5] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
                       ` (5 more replies)
  3 siblings, 6 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 14:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This series makes the "-x" output less verbose for our various helper
functions, mainly using the trickery of feeding "$@" to "test" to rely
on it to die when given too many arguments.

Since v2[1] I ejected the patch to make the "test_line_count" function
unsafer per Junio's feedback.

The test_file_size has lost its "BUG" invocation, but is now safe as
we do that check in the test helper, as shown in 5/5 we fixed one
previous mild regression while doing that.

The 3-4/5 patches are just trivial "while we're at it" work.

1. http://lore.kernel.org/git/cover-0.3-0000000000-20210420T122706Z-avarab@gmail.com

Ævar Arnfjörð Bjarmason (5):
  test-lib-functions: normalize test_path_is_missing() debugging
  Revert and amend "test-lib-functions: assert correct parameter count"
  test helpers: remove unused test-tool path-utils slice-tests
  test-helpers: rename "path-utils is_valid_path" to "is-valid-paths"
  test-helpers: split "file-size" into "file-size(s)"

 t/helper/test-path-utils.c  | 44 ++++++------------------
 t/t0060-path-utils.sh       |  2 +-
 t/t1050-large.sh            |  2 +-
 t/t5319-multi-pack-index.sh |  6 ++--
 t/test-lib-functions.sh     | 67 ++++++++++++++++---------------------
 5 files changed, 45 insertions(+), 76 deletions(-)

Range-diff against v1:
1:  fd33f6d71f0 = 1:  ba9d6251ad5 test-lib-functions: normalize test_path_is_missing() debugging
2:  67ddd821dfa = 2:  5f8e5ad27f5 Revert and amend "test-lib-functions: assert correct parameter count"
3:  8fd51861b59 < -:  ----------- test-lib-functions: remove last two parameter count assertions
-:  ----------- > 3:  44948c6ace9 test helpers: remove unused test-tool path-utils slice-tests
-:  ----------- > 4:  ae5dc5d03b3 test-helpers: rename "path-utils is_valid_path" to "is-valid-paths"
-:  ----------- > 5:  947791d9535 test-helpers: split "file-size" into "file-size(s)"
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v2 1/5] test-lib-functions: normalize test_path_is_missing() debugging
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
@ 2021-04-21 14:58     ` Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 2/5] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
                       ` (4 subsequent siblings)
  5 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 14:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Change the test_path_is_missing() to be consistent with related
functions. Since 2caf20c52b7 (test-lib: user-friendly alternatives to
test [-d|-f|-e], 2010-08-10) we've been ls -ld-ing the bad path and
echo-ing $* if it exists. Let's just say that it exists instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index bd64a15c731..0232cc9f46d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -810,12 +810,7 @@ test_path_is_missing () {
 	test "$#" -ne 1 && BUG "1 param"
 	if test -e "$1"
 	then
-		echo "Path exists:"
-		ls -ld "$1"
-		if test $# -ge 1
-		then
-			echo "$*"
-		fi
+		echo "Path $1 exists!"
 		false
 	fi
 }
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 2/5] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 1/5] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
@ 2021-04-21 14:58     ` Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 3/5] test helpers: remove unused test-tool path-utils slice-tests Ævar Arnfjörð Bjarmason
                       ` (3 subsequent siblings)
  5 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 14:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This reverts and amends my my own e7884b353b7 (test-lib-functions:
assert correct parameter count, 2021-02-12) in order to improve the -x
output.

The goal here is to get rid of the verbosity of having e.g. a "test 2
-ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
to intentionally feed the "test" operator too many arguments if the
functions are called with too many arguments, thus piggy-backing on it
to check the number of arguments we get.

Before this for each test_cmp invocation we'd emit:

    + test_cmp expect actual
    + test 2 -ne 2
    + eval diff -u "$@"
    + diff -u expect actual

That "test 2 -ne 2" line is new in my e7884b353b7. As noted in
45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
helper param, 2021-02-12) we had buggy invocations of some of these
functions with too many parameters.

Now we'll get just:

    + test_cmp expect actual
    + eval diff -u "$@"
    + diff -u expect actual

This does not to the "right" thing in cases like:

    test_path_is_file x -a y

Which will now turn into:

    test -f x -a y

I consider that to be OK given the trade-off that any extra checking
would produce more verbose trace output. As shown in 45a2686441b we
had issues with these functions being invoked with multiple
parameters (e.g. a glob) by accident, we don't need to be paranoid in
guarding against hostile misuse from our own test suite.

While I'm at it change a few functions that relied on a "false" being
the last statement in the function to use an explicit "return 1" like
the other functions in this file.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 59 +++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 0232cc9f46d..f8f5bf9de1e 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -756,41 +756,43 @@ test_external_without_stderr () {
 }
 
 # debugging-friendly alternatives to "test [-f|-d|-e]"
-# The commands test the existence or non-existence of $1
+# The commands test the existence or non-existence of
+# a given argument.
+#
+# The pattern of using "$@" to "test" instead of "$1" is not a bug. We
+# are counting on "test" to error on too many arguments if more than
+# one is given. Checking "$#" explicitly would lead to overly verbose
+# -x output.
 test_path_is_file () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -f "$1"
+	if ! test -f "$@"
 	then
-		echo "File $1 doesn't exist"
-		false
+		echo "File $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_is_dir () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -d "$1"
+	if ! test -d "$@"
 	then
-		echo "Directory $1 doesn't exist"
-		false
+		echo "Directory $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_exists () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -e "$1"
+	if ! test -e "$@"
 	then
-		echo "Path $1 doesn't exist"
-		false
+		echo "Path $* doesn't exist"
+		return 1
 	fi
 }
 
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_dir "$1" &&
-	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+	test_path_is_dir "$@" &&
+	if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')"
 	then
-		echo "Directory '$1' is not empty, it contains:"
+		echo "Directory '$*' is not empty, it contains:"
 		ls -la "$1"
 		return 1
 	fi
@@ -798,19 +800,17 @@ test_dir_is_empty () {
 
 # Check if the file exists and has a size greater than zero
 test_file_not_empty () {
-	test "$#" = 2 && BUG "2 param"
-	if ! test -s "$1"
+	if ! test -s "$@"
 	then
-		echo "'$1' is not a non-empty file."
-		false
+		echo "'$*' is not a non-empty file."
+		return 1
 	fi
 }
 
 test_path_is_missing () {
-	test "$#" -ne 1 && BUG "1 param"
-	if test -e "$1"
+	if test -e "$@"
 	then
-		echo "Path $1 exists!"
+		echo "Path $* exists!"
 		false
 	fi
 }
@@ -1012,7 +1012,6 @@ test_expect_code () {
 # - not all diff versions understand "-u"
 
 test_cmp () {
-	test "$#" -ne 2 && BUG "2 param"
 	eval "$GIT_TEST_CMP" '"$@"'
 }
 
@@ -1042,7 +1041,6 @@ test_cmp_config () {
 # test_cmp_bin - helper to compare binary files
 
 test_cmp_bin () {
-	test "$#" -ne 2 && BUG "2 param"
 	cmp "$@"
 }
 
@@ -1103,12 +1101,11 @@ verbose () {
 # otherwise.
 
 test_must_be_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_file "$1" &&
-	if test -s "$1"
+	test_path_is_file "$@" &&
+	if test -s "$@"
 	then
-		echo "'$1' is not empty, it contains:"
-		cat "$1"
+		echo "'$*' is not empty, it contains:"
+		cat "$@"
 		return 1
 	fi
 }
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 3/5] test helpers: remove unused test-tool path-utils slice-tests
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 1/5] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 2/5] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-21 14:58     ` Ævar Arnfjörð Bjarmason
  2021-04-21 18:02       ` Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 4/5] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Ævar Arnfjörð Bjarmason
                       ` (2 subsequent siblings)
  5 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 14:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This utility was last used in the code removed in 4c2c38e800f (ci:
modification of main.yml to use cmake for vs-build job,
2020-06-26). Let's also remove this now-dead code.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-path-utils.c | 31 -------------------------------
 1 file changed, 31 deletions(-)

diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 313a153209c..3d7c0f1d19d 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -177,14 +177,6 @@ static int is_dotgitmodules(const char *path)
 	return is_hfs_dotgitmodules(path) || is_ntfs_dotgitmodules(path);
 }
 
-static int cmp_by_st_size(const void *a, const void *b)
-{
-	intptr_t x = (intptr_t)((struct string_list_item *)a)->util;
-	intptr_t y = (intptr_t)((struct string_list_item *)b)->util;
-
-	return x > y ? -1 : (x < y ? +1 : 0);
-}
-
 /*
  * A very simple, reproducible pseudo-random generator. Copied from
  * `test-genrandom.c`.
@@ -428,29 +420,6 @@ int cmd__path_utils(int argc, const char **argv)
 		return 0;
 	}
 
-	if (argc > 5 && !strcmp(argv[1], "slice-tests")) {
-		int res = 0;
-		long offset, stride, i;
-		struct string_list list = STRING_LIST_INIT_NODUP;
-		struct stat st;
-
-		offset = strtol(argv[2], NULL, 10);
-		stride = strtol(argv[3], NULL, 10);
-		if (stride < 1)
-			stride = 1;
-		for (i = 4; i < argc; i++)
-			if (stat(argv[i], &st))
-				res = error_errno("Cannot stat '%s'", argv[i]);
-			else
-				string_list_append(&list, argv[i])->util =
-					(void *)(intptr_t)st.st_size;
-		QSORT(list.items, list.nr, cmp_by_st_size);
-		for (i = offset; i < list.nr; i+= stride)
-			printf("%s\n", list.items[i].string);
-
-		return !!res;
-	}
-
 	if (argc > 1 && !strcmp(argv[1], "protect_ntfs_hfs"))
 		return !!protect_ntfs_hfs_benchmark(argc - 1, argv + 1);
 
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 4/5] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths"
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
                       ` (2 preceding siblings ...)
  2021-04-21 14:58     ` [PATCH v2 3/5] test helpers: remove unused test-tool path-utils slice-tests Ævar Arnfjörð Bjarmason
@ 2021-04-21 14:58     ` Ævar Arnfjörð Bjarmason
  2021-04-21 14:58     ` [PATCH v2 5/5] test-helpers: split "file-size" into "file-size(s)" Ævar Arnfjörð Bjarmason
  2021-04-23  7:29     ` [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  5 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 14:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Rename this utility added in d2c84dad1c8 (mingw: refuse to access
paths with trailing spaces or periods, 2019-09-05) to make it clear
that it expects N number of arguments, and for consistency with
dc2d9ba3187 (is_{hfs,ntfs}_dotgitmodules: add tests, 2018-05-12).

Let's also make it a dashed "is-valid-paths" instead of
"is_valid_path*" to make it easier to grep the helper v.s. the C
function it calls.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-path-utils.c | 2 +-
 t/t0060-path-utils.sh      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 3d7c0f1d19d..af7d7fd5454 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -423,7 +423,7 @@ int cmd__path_utils(int argc, const char **argv)
 	if (argc > 1 && !strcmp(argv[1], "protect_ntfs_hfs"))
 		return !!protect_ntfs_hfs_benchmark(argc - 1, argv + 1);
 
-	if (argc > 1 && !strcmp(argv[1], "is_valid_path")) {
+	if (argc > 1 && !strcmp(argv[1], "is-valid-paths")) {
 		int res = 0, expect = 1, i;
 
 		for (i = 2; i < argc; i++)
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 0ff06b5d1b3..e7fb748b19c 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -469,7 +469,7 @@ test_expect_success 'match .gitmodules' '
 '
 
 test_expect_success MINGW 'is_valid_path() on Windows' '
-	test-tool path-utils is_valid_path \
+	test-tool path-utils is-valid-paths \
 		win32 \
 		"win32 x" \
 		../hello.txt \
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v2 5/5] test-helpers: split "file-size" into "file-size(s)"
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
                       ` (3 preceding siblings ...)
  2021-04-21 14:58     ` [PATCH v2 4/5] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Ævar Arnfjörð Bjarmason
@ 2021-04-21 14:58     ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:29     ` [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  5 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 14:58 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Split the "file-size" helper into two helpers, one that takes 1
argument, and another one that takes N.

This allows us to remove the "BUG" check in test-lib-functions.sh for
briefer -x output, and more importantly will clearly distinguish those
cases where we expect one argument v.s. many.

The use in t1050-large.sh wants to check just one pack, we used to
check that explicitly before 53b67a801bb (tests: consolidate the
`file_size` function into `test-lib-functions.sh`, 2020-11-07), now we
do so again.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-path-utils.c  | 11 ++++++++++-
 t/t1050-large.sh            |  2 +-
 t/t5319-multi-pack-index.sh |  6 +++---
 t/test-lib-functions.sh     |  3 +--
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index af7d7fd5454..23970db8183 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -272,6 +272,8 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)
 
 int cmd__path_utils(int argc, const char **argv)
 {
+	int is_file_size, is_file_sizes;
+
 	if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
 		char *buf = xmallocz(strlen(argv[2]));
 		int rv = normalize_path_copy(buf, argv[2]);
@@ -387,10 +389,17 @@ int cmd__path_utils(int argc, const char **argv)
 		return !!res;
 	}
 
-	if (argc > 2 && !strcmp(argv[1], "file-size")) {
+	is_file_size = !strcmp(argv[1], "file-size");
+	is_file_sizes = !strcmp(argv[1], "file-sizes");
+	if (argc > 2 && (is_file_size || is_file_sizes)) {
 		int res = 0, i;
 		struct stat st;
 
+		if (is_file_size && argc > 3) {
+			res = error("too many arguments to is-file-size, use is-file-sizes?");
+			return res;
+		}
+
 		for (i = 2; i < argc; i++)
 			if (stat(argv[i], &st))
 				res = error_errno("Cannot stat '%s'", argv[i]);
diff --git a/t/t1050-large.sh b/t/t1050-large.sh
index 4bab6a513c5..0b76ab0e3f9 100755
--- a/t/t1050-large.sh
+++ b/t/t1050-large.sh
@@ -23,7 +23,7 @@ do
 	test_expect_success "add with $config" '
 		test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
 		git $config add large1 &&
-		sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
+		sz=$(test-tool path-utils file-size .git/objects/pack/pack-*.pack) &&
 		case "$expect" in
 		small) test "$sz" -le 100000 ;;
 		large) test "$sz" -ge 100000 ;;
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 5641d158dfc..baeda407b90 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -648,7 +648,7 @@ test_expect_success 'repack with minimum size does not alter existing packs' '
 		test-tool chmtime =-3 .git/objects/pack/pack-B* &&
 		test-tool chmtime =-2 .git/objects/pack/pack-A* &&
 		ls .git/objects/pack >expect &&
-		MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
+		MINSIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | head -n 1) &&
 		git multi-pack-index repack --batch-size=$MINSIZE &&
 		ls .git/objects/pack >actual &&
 		test_cmp expect actual
@@ -672,7 +672,7 @@ test_expect_success 'repack respects repack.packKeptObjects=false' '
 		test_line_count = 5 idx-list &&
 		test-tool read-midx .git/objects | grep idx >midx-list &&
 		test_line_count = 5 midx-list &&
-		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
+		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | sed -n 3p) &&
 		BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
 		git multi-pack-index repack --batch-size=$BATCH_SIZE &&
 		ls .git/objects/pack/*idx >idx-list &&
@@ -687,7 +687,7 @@ test_expect_success 'repack creates a new pack' '
 		cd dup &&
 		ls .git/objects/pack/*idx >idx-list &&
 		test_line_count = 5 idx-list &&
-		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
+		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
 		BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
 		git multi-pack-index repack --batch-size=$BATCH_SIZE &&
 		ls .git/objects/pack/*idx >idx-list &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index f8f5bf9de1e..20d1f94fd97 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -839,8 +839,7 @@ test_line_count () {
 }
 
 test_file_size () {
-	test "$#" -ne 1 && BUG "1 param"
-	test-tool path-utils file-size "$1"
+	test-tool path-utils file-size "$@"
 }
 
 # Returns success if a comma separated string of keywords ($1) contains a
-- 
2.31.1.721.gbeb6a21927


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-21 14:18             ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
@ 2021-04-21 16:32               ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-21 16:32 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Đoàn Trần Công Danh, git, Jeff King,
	Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	SZEDER Gábor

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

>>> 	t6402-merge-rename.sh:865: error: "test A || test B" preferred to "test A -o B": test 0 -eq $(git ls-files -o | wc -l) &&
>>
>> With: 7dbe8c8003, (check-non-portable-shell.pl: `wc -l` may have
> ...
> I think those patches are good in their own right, i.e. replacing things
> with more incremental helpers and test_cmp-like functions.
>
> But I believe the code you're changing is not non-portable. It was using
> the output of "wc -l" with the "=" operator that wasn't portable.

Not necessarily.  The last one shown above

	test 0 -eq $(git ls-files -o | wc -l) &&

is still valid and correct with s/-eq/=/.  It lets shell to remove
excess whitespaces around output from some implementations of "wc",
so textual '=' is perfectly fine.

> These ones are all occurances that use "-eq".
>
> And:
>
>     test "0" -eq " 0"
>
> etc., is true, which is why these pass on OSX and beyond.

Perhaps, but I am not sure how portable it is to rely on "-eq"
ignoring the leading whitespaces.

A more conventional (read: time tested) way is to $(... | wc -l)
*NOT* enclosed inside dq, so that the shell will strip out any
excess spaces around it, and use '=', i.e.

    test 3 = $(... | wc -l)

and that is what we end up evaluating when we write

    test_line_count = 3 file

This does rely on that "wc -l" will run and produce _some_ output to
be syntactically correct, though.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v4 11/11] test-lib: split up and deprecate test_create_repo()
  2021-04-21 10:15       ` [PATCH v4 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-21 16:43         ` SZEDER Gábor
  2021-04-22 12:39           ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: SZEDER Gábor @ 2021-04-21 16:43 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, Andreas Schwab

On Wed, Apr 21, 2021 at 12:15:16PM +0200, Ævar Arnfjörð Bjarmason wrote:
>  5. Since we don't need to move the .git/hooks directory we don't need

Again: Since we don't need to change directories....

>     the subshell here either.
> 
>     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.

I think this is worse and even more misleading than even v2 was, for
the reasons I mentioned earlier.


^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-21 10:41               ` [PATCH 2/2] t6402: " Đoàn Trần Công Danh
@ 2021-04-21 16:55                 ` Eric Sunshine
  2021-04-21 17:32                   ` Eric Sunshine
  2021-04-22 12:45                   ` Ævar Arnfjörð Bjarmason
  0 siblings, 2 replies; 175+ messages in thread
From: Eric Sunshine @ 2021-04-21 16:55 UTC (permalink / raw)
  To: Đoàn Trần Công Danh; +Cc: Git List

On Wed, Apr 21, 2021 at 6:41 AM Đoàn Trần Công Danh
<congdanhqx@gmail.com> wrote:
> We will lose the exit status of "git ls-files" if it's being run in
> anywhere-but-not-final part of a pipe.
>
> Let's send the output of "git ls-files" to a file first,
> and adjust the expected result for "git ls-files -o" since a new
> untracked file will be created as a side effect.
>
> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
> ---
> diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh
> @@ -631,20 +663,33 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
> -               test 5 -eq "$(git ls-files -s | wc -l)" &&
> -               test 3 -eq "$(git ls-files -u | wc -l)" &&
> -               test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
> +               git ls-files -s >output &&
> +               test_line_count = 5 output &&
> +               git ls-files -u >output &&
> +               test_line_count = 3 output &&
> +               git ls-files -u one~HEAD >output &&
> +               test_line_count = 1 output &&

This idiom crops up so frequently in this test script that it almost
begs for the introduction of a helper function rather than applying
the manual transformation repeatedly. For instance, the helper might
be called like this:

    count_ls_files 5 -s &&
    count_ls_files 3 -u &&
    count_ls_files 1 -u one~HEAD &&
    ...

The nice thing about having a helper function is that it can clean up
after itself by not leaving a new file lying around, thus you wouldn't
have to make adjustments to the expected number of untracked files (as
mentioned in the commit message). If this is the sort of thing which
comes up often enough (if there are more such cases beyond the two
scripts you changed in this series), then it might make sense to
promote the helper function to test-lib-functions.sh.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-21 16:55                 ` Eric Sunshine
@ 2021-04-21 17:32                   ` Eric Sunshine
  2021-04-21 23:32                     ` Junio C Hamano
  2021-04-22 12:45                   ` Ævar Arnfjörð Bjarmason
  1 sibling, 1 reply; 175+ messages in thread
From: Eric Sunshine @ 2021-04-21 17:32 UTC (permalink / raw)
  To: Đoàn Trần Công Danh; +Cc: Git List

On Wed, Apr 21, 2021 at 12:55 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>     count_ls_files 5 -s &&
>     count_ls_files 3 -u &&
>     count_ls_files 1 -u one~HEAD &&
>     ...
>
> The nice thing about having a helper function is that it can clean up
> after itself by not leaving a new file lying around, thus you wouldn't
> have to make adjustments to the expected number of untracked files (as
> mentioned in the commit message). If this is the sort of thing which
> comes up often enough (if there are more such cases beyond the two
> scripts you changed in this series), then it might make sense to
> promote the helper function to test-lib-functions.sh.

The frequency with which this idiom crops up with commands beyond
git-ls-files suggests the more general solution of supporting it
directly in test-lib-functions.sh for any command. For instance:

    test_cmd_line_count = 3 git ls-files -u &&

Or, perhaps, a new mode of test_line_count():

    test_line_count = 3 -c git ls-files -u &&

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v2 3/5] test helpers: remove unused test-tool path-utils slice-tests
  2021-04-21 14:58     ` [PATCH v2 3/5] test helpers: remove unused test-tool path-utils slice-tests Ævar Arnfjörð Bjarmason
@ 2021-04-21 18:02       ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-21 18:02 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason


On Wed, Apr 21 2021, Ævar Arnfjörð Bjarmason wrote:

> This utility was last used in the code removed in 4c2c38e800f (ci:
> modification of main.yml to use cmake for vs-build job,
> 2020-06-26). Let's also remove this now-dead code.

This patch needs to be dropped, turns out it's used outside of t/ in
ci/, didn't think to grep for test helpers there. Will hold off on a
re-roll for a bit pending further feedback.

Junio, unless you'd like to have it sooner than later?

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>"
  2021-04-21  8:46         ` Ævar Arnfjörð Bjarmason
  2021-04-21 10:39           ` Đoàn Trần Công Danh
@ 2021-04-21 18:56           ` Junio C Hamano
  1 sibling, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-21 18:56 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> Applying your suggestion results in these false positives:
> 	
> 	t4038-diff-combined.sh:135: error: "test A && test B" preferred to "test A -a B": git commit -m "test space change" -a &&

This is utterly amusing.  Consider the suggestion withdrawn.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-21 17:32                   ` Eric Sunshine
@ 2021-04-21 23:32                     ` Junio C Hamano
  2021-04-22 13:49                       ` Đoàn Trần Công Danh
  0 siblings, 1 reply; 175+ messages in thread
From: Junio C Hamano @ 2021-04-21 23:32 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Đoàn Trần Công Danh, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Wed, Apr 21, 2021 at 12:55 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>>     count_ls_files 5 -s &&
>>     count_ls_files 3 -u &&
>>     count_ls_files 1 -u one~HEAD &&
>>     ...
>>
>> The nice thing about having a helper function is that it can clean up
>> after itself by not leaving a new file lying around, thus you wouldn't
>> have to make adjustments to the expected number of untracked files (as
>> mentioned in the commit message). If this is the sort of thing which
>> comes up often enough (if there are more such cases beyond the two
>> scripts you changed in this series), then it might make sense to
>> promote the helper function to test-lib-functions.sh.
>
> The frequency with which this idiom crops up with commands beyond
> git-ls-files suggests the more general solution of supporting it
> directly in test-lib-functions.sh for any command. For instance:
>
>     test_cmd_line_count = 3 git ls-files -u &&
>
> Or, perhaps, a new mode of test_line_count():
>
>     test_line_count = 3 -c git ls-files -u &&

That looks nice on paper, but may be going too far.

We may want to count the lines in the error message, or we may want
to count the lines after filtering the output with pipe.

A test file that is dedicated to test ls-files with a file local
helper "count_ls_files" smells like a better place to stop, at least
to me.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v4 11/11] test-lib: split up and deprecate test_create_repo()
  2021-04-21 16:43         ` SZEDER Gábor
@ 2021-04-22 12:39           ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-22 12:39 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, Andreas Schwab


On Wed, Apr 21 2021, SZEDER Gábor wrote:

> On Wed, Apr 21, 2021 at 12:15:16PM +0200, Ævar Arnfjörð Bjarmason wrote:
>>  5. Since we don't need to move the .git/hooks directory we don't need
>
> Again: Since we don't need to change directories....
>
>>     the subshell here either.
>> 
>>     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.
>
> I think this is worse and even more misleading than even v2 was, for
> the reasons I mentioned earlier.

Between this & the thread at
http://lore.kernel.org/git/20210420212731.GY2947267@szeder.dev I'm not
sure what wording you'd be OK with, would you mind suggesting an
alternative?

As far as I can see it's some subtlety of how we explain the cd-ing &
subshelling we did as a combination of eedf8f97e58 (Abstract
test_create_repo out for use in tests., 2006-02-17) and my 0d314ce834d
(test-lib: use subshell instead of cd $new && .. && cd $old,
2010-08-30).

Maybe you'd be happy with this:

    In the code being removed here we both "cd"'d to the repository
    before calling "init", and did so in a subshell. It's not important
    to do either, so both of those can be removed. We cd'd because this
    code grew from test-lib.sh code where we'd have done so already, see
    0d314ce834d, and later "cd"'d inside a subshell since 0d314ce834d to
    avoid having to keep track of an "old pwd" variable to cd back after
    the setup.

    Being in the repository directory made moving the hooks around
    easier (we wouldn't have to fully qualify the path), but since we're
    not moving the hooks anymore we don't need it for that reason
    either.

?

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-21 16:55                 ` Eric Sunshine
  2021-04-21 17:32                   ` Eric Sunshine
@ 2021-04-22 12:45                   ` Ævar Arnfjörð Bjarmason
  1 sibling, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-22 12:45 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Đoàn Trần Công Danh, Git List


On Wed, Apr 21 2021, Eric Sunshine wrote:

> On Wed, Apr 21, 2021 at 6:41 AM Đoàn Trần Công Danh
> <congdanhqx@gmail.com> wrote:
>> We will lose the exit status of "git ls-files" if it's being run in
>> anywhere-but-not-final part of a pipe.
>>
>> Let's send the output of "git ls-files" to a file first,
>> and adjust the expected result for "git ls-files -o" since a new
>> untracked file will be created as a side effect.
>>
>> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
>> ---
>> diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh
>> @@ -631,20 +663,33 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
>> -               test 5 -eq "$(git ls-files -s | wc -l)" &&
>> -               test 3 -eq "$(git ls-files -u | wc -l)" &&
>> -               test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
>> +               git ls-files -s >output &&
>> +               test_line_count = 5 output &&
>> +               git ls-files -u >output &&
>> +               test_line_count = 3 output &&
>> +               git ls-files -u one~HEAD >output &&
>> +               test_line_count = 1 output &&
>
> This idiom crops up so frequently in this test script that it almost
> begs for the introduction of a helper function rather than applying
> the manual transformation repeatedly. For instance, the helper might
> be called like this:
>
>     count_ls_files 5 -s &&
>     count_ls_files 3 -u &&
>     count_ls_files 1 -u one~HEAD &&
>     ...
>
> The nice thing about having a helper function is that it can clean up
> after itself by not leaving a new file lying around, thus you wouldn't
> have to make adjustments to the expected number of untracked files (as
> mentioned in the commit message). If this is the sort of thing which
> comes up often enough (if there are more such cases beyond the two
> scripts you changed in this series), then it might make sense to
> promote the helper function to test-lib-functions.sh.

Agreed, but I'd saythat it makes more sense to have something like:

	test_line_count = 1 -- git ls-files

Or maybe another function, but in any case not something specific to
ls-files, but just a wrapper like the various "$@" wrappers in
test-lib-functions.sh to count the lines emitted by an arbitrary
command.

It would also leave things open for:

    test_line_count --stout=1 --stderr=2 -- git ls-files
    test_line_count --combined=3 -- git ls-files

Or whatever, to count the different output streams.


^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-21 23:32                     ` Junio C Hamano
@ 2021-04-22 13:49                       ` Đoàn Trần Công Danh
  2021-04-22 15:04                         ` Ævar Arnfjörð Bjarmason
  2021-04-22 15:07                         ` Đoàn Trần Công Danh
  0 siblings, 2 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-04-22 13:49 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Eric Sunshine, Git List

On 2021-04-21 16:32:40-0700, Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> 
> > On Wed, Apr 21, 2021 at 12:55 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> >>     count_ls_files 5 -s &&
> >>     count_ls_files 3 -u &&
> >>     count_ls_files 1 -u one~HEAD &&
> >>     ...
> >>
> >> The nice thing about having a helper function is that it can clean up
> >> after itself by not leaving a new file lying around, thus you wouldn't
> >> have to make adjustments to the expected number of untracked files (as
> >> mentioned in the commit message). If this is the sort of thing which
> >> comes up often enough (if there are more such cases beyond the two
> >> scripts you changed in this series), then it might make sense to
> >> promote the helper function to test-lib-functions.sh.
> >
> > The frequency with which this idiom crops up with commands beyond
> > git-ls-files suggests the more general solution of supporting it
> > directly in test-lib-functions.sh for any command. For instance:
> >
> >     test_cmd_line_count = 3 git ls-files -u &&
> >
> > Or, perhaps, a new mode of test_line_count():
> >
> >     test_line_count = 3 -c git ls-files -u &&

Hm, I'm not sure how would we implement such mode:

* Will we run such command in a subprocess and and pipe to "wc -l"
  directly to avoid a temporary file, but we will lose the exit code
  of running command in process?
* Will we run in a separated chain? Thus, a temporary file would be
  created, skimming over test-lib-functions.sh, I couldn't find any
  convention for creating such files, except for specific use cases,
  let's say "*.config".
* Another clever hacks that I don't know *shrug*

> 
> That looks nice on paper, but may be going too far.
> 
> We may want to count the lines in the error message,

Let's assume that we solve above puzzle.

Count the lines in the error messages is not too hard to be imagined,
let's say by -c2 or something like that.

> or we may want
> to count the lines after filtering the output with pipe.

However, when it involved a pipe, things becomes complicated.

> A test file that is dedicated to test ls-files with a file local
> helper "count_ls_files" smells like a better place to stop, at least
> to me.

Hence, I'll stick with local help "count_ls_files" for now.

-- 
Danh

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-22 13:49                       ` Đoàn Trần Công Danh
@ 2021-04-22 15:04                         ` Ævar Arnfjörð Bjarmason
  2021-04-22 15:30                           ` Eric Sunshine
  2021-04-22 15:07                         ` Đoàn Trần Công Danh
  1 sibling, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-22 15:04 UTC (permalink / raw)
  To: Đoàn Trần Công Danh
  Cc: Junio C Hamano, Eric Sunshine, Git List


On Thu, Apr 22 2021, Đoàn Trần Công Danh wrote:

> On 2021-04-21 16:32:40-0700, Junio C Hamano <gitster@pobox.com> wrote:
>> Eric Sunshine <sunshine@sunshineco.com> writes:
>> 
>> > On Wed, Apr 21, 2021 at 12:55 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>> >>     count_ls_files 5 -s &&
>> >>     count_ls_files 3 -u &&
>> >>     count_ls_files 1 -u one~HEAD &&
>> >>     ...
>> >>
>> >> The nice thing about having a helper function is that it can clean up
>> >> after itself by not leaving a new file lying around, thus you wouldn't
>> >> have to make adjustments to the expected number of untracked files (as
>> >> mentioned in the commit message). If this is the sort of thing which
>> >> comes up often enough (if there are more such cases beyond the two
>> >> scripts you changed in this series), then it might make sense to
>> >> promote the helper function to test-lib-functions.sh.
>> >
>> > The frequency with which this idiom crops up with commands beyond
>> > git-ls-files suggests the more general solution of supporting it
>> > directly in test-lib-functions.sh for any command. For instance:
>> >
>> >     test_cmd_line_count = 3 git ls-files -u &&
>> >
>> > Or, perhaps, a new mode of test_line_count():
>> >
>> >     test_line_count = 3 -c git ls-files -u &&
>
> Hm, I'm not sure how would we implement such mode:
>
> * Will we run such command in a subprocess and and pipe to "wc -l"
>   directly to avoid a temporary file, but we will lose the exit code
>   of running command in process?

Just use a tempfile.

> * Will we run in a separated chain? Thus, a temporary file would be
>   created, skimming over test-lib-functions.sh, I couldn't find any
>   convention for creating such files, except for specific use cases,
>   let's say "*.config".

Yeah we happen not to have one of those in test-lib-functions.sh, but a
bunch of helpers create those.

> * Another clever hacks that I don't know *shrug*

>> 
>> That looks nice on paper, but may be going too far.
>> 
>> We may want to count the lines in the error message,
>
> Let's assume that we solve above puzzle.
>
> Count the lines in the error messages is not too hard to be imagined,
> let's say by -c2 or something like that.
>
>> or we may want
>> to count the lines after filtering the output with pipe.
>
> However, when it involved a pipe, things becomes complicated.

Yes, there's no portable way to both stream stdout/stderr in the correct
order and to intercept it. You'd need a mkfifo. See also how the "--tee"
mode works (i.e. they're squashed).

>> A test file that is dedicated to test ls-files with a file local
>> helper "count_ls_files" smells like a better place to stop, at least
>> to me.
>
> Hence, I'll stick with local help "count_ls_files" for now.

Here's an implementation that works, sans the fancy opts parsing etc. I
just use -1 for "don't care". You can see "test_commit" etc. for how to
do that.

It doesn't emit output, but that's just a matter of re-cat-ing the
relevant files.

Yes we wouldn't have combined output when you do that, but I don't think
we care, you can chain this thing, and most thing that would do so would
only care about piping stdout/stderr to their own files anyway, and not
that we emit one line of stdout, then another of stderr, another of
stdout etc.

diff --git a/t/t6402-merge-rename.sh b/t/t6402-merge-rename.sh
index 425dad97d54..c7251102a3d 100755
--- a/t/t6402-merge-rename.sh
+++ b/t/t6402-merge-rename.sh
@@ -154,14 +154,10 @@ test_expect_success 'pull conflicting renames' \
 	git reset --hard &&
 	git show-branch &&
 	test_expect_code 1 git pull . blue &&
-	git ls-files -u A >a.stages &&
-	test_line_count = 1 a.stages &&
-	git ls-files -u B >b.stages &&
-	test_line_count = 1 b.stages &&
-	git ls-files -u C >c.stages &&
-	test_line_count = 1 c.stages &&
-	git ls-files -s N >n.stages &&
-	test_line_count = 1 n.stages &&
+	test_line_count_command = 1 0 git ls-files -u A &&
+	test_line_count_command = 1 0 git ls-files -u B &&
+	test_line_count_command = 1 0 git ls-files -u C &&
+	test_line_count_command = 1 0 git ls-files -s N &&
 	sed -ne "/^g/{
 	p
 	q
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b823c140271..10e3cbe0d47 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -817,6 +817,24 @@ test_line_count () {
 	fi
 }
 
+test_line_count_command () {
+	local op=$1
+	local ocnt=$2
+	local ecnt=$3
+	shift 3
+	"$@" 2>cnt.err >cnt.out
+	local exit_code=$?
+	if test "$ocnt" -gt -1
+	then
+		test_line_count "$op" "$ocnt" cnt.out
+	fi &&
+	if test "$ecnt" -gt -1
+	then
+		test_line_count "$op" "$ecnt" cnt.err
+	fi &&
+	return "$exit_code"
+}
+
 test_file_size () {
 	test "$#" -ne 1 && BUG "1 param"
 	test-tool path-utils file-size "$1"

^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-22 13:49                       ` Đoàn Trần Công Danh
  2021-04-22 15:04                         ` Ævar Arnfjörð Bjarmason
@ 2021-04-22 15:07                         ` Đoàn Trần Công Danh
  1 sibling, 0 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-04-22 15:07 UTC (permalink / raw)
  To: Junio C Hamano, Eric Sunshine, Ævar Arnfjörð Bjarmason
  Cc: Eric Sunshine, Git List

On 2021-04-22 20:49:04+0700, Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
> On 2021-04-21 16:32:40-0700, Junio C Hamano <gitster@pobox.com> wrote:
> > Eric Sunshine <sunshine@sunshineco.com> writes:
> > 
> > > On Wed, Apr 21, 2021 at 12:55 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > >>     count_ls_files 5 -s &&
> > >>     count_ls_files 3 -u &&
> > >>     count_ls_files 1 -u one~HEAD &&
> > >>     ...
> > >>
> > >> The nice thing about having a helper function is that it can clean up
> > >> after itself by not leaving a new file lying around, thus you wouldn't
> > >> have to make adjustments to the expected number of untracked files (as
> > >> mentioned in the commit message). If this is the sort of thing which
> > >> comes up often enough (if there are more such cases beyond the two
> > >> scripts you changed in this series), then it might make sense to
> > >> promote the helper function to test-lib-functions.sh.
> > >
> > > The frequency with which this idiom crops up with commands beyond
> > > git-ls-files suggests the more general solution of supporting it
> > > directly in test-lib-functions.sh for any command. For instance:
> > >
> > >     test_cmd_line_count = 3 git ls-files -u &&
> > >
> > > Or, perhaps, a new mode of test_line_count():
> > >
> > >     test_line_count = 3 -c git ls-files -u &&
> 
> Hm, I'm not sure how would we implement such mode:
> 
> * Will we run such command in a subprocess and and pipe to "wc -l"
>   directly to avoid a temporary file, but we will lose the exit code
>   of running command in process?
> * Will we run in a separated chain? Thus, a temporary file would be
>   created, skimming over test-lib-functions.sh, I couldn't find any
>   convention for creating such files, except for specific use cases,
>   let's say "*.config".
> * Another clever hacks that I don't know *shrug*

Hm, I figured out, just a bit insane for reviewing.
-----8<--------
Subject: [PATCH] test-lib-functions: add test_line_count_in helper

Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
 t/t0000-basic.sh        |  7 +++++
 t/test-lib-functions.sh | 62 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 705d62cc27..2ddb50e919 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -60,6 +60,13 @@ test_expect_success '.git/objects should have 3 subdirectories' '
 	test_line_count = 3 full-of-directories
 '
 
+test_expect_success 'check test_line_count_in' '
+	test_line_count_in --stdout = 4 --stderr = 3 -- sh -c "
+		printf \"%s\\n\" 1 2 3 4
+		printf >&2 \"%s\\n\" a b c
+		"
+'
+
 ################################################################
 # Test harness
 test_expect_success 'success is reported like this' '
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6348e8d733..3b3dc3020a 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -817,6 +817,68 @@ test_line_count () {
 	fi
 }
 
+# test_line_count_in checks if stdout and/or stderr has the number of lines it
+# ought to. E.g.
+#
+# 	test_expect_success 'product 1 line in stdout and 2 lines in stderr' '
+# 		test_line_count_in --stdout = 1 --stderr = 3 do_something
+# 	'
+test_line_count_in () {
+	local out_ops=-ge
+	local out_val=0
+	local err_ops=-ge
+	local err_val=0
+	local opt_set=
+
+	while test $# != 0
+	do
+		case "$1" in
+		--stdout)
+			if test $# -lt 3
+			then
+				BUG "need ops and value for --stdout"
+			fi
+			out_ops=$2
+			out_val=$3
+			opt_set=yes
+			shift 3
+			;;
+		--stderr)
+			if test $# -lt 3
+			then
+				BUG "need ops and value for --stderr"
+			fi
+			err_ops=$2
+			err_val=$3
+			opt_set=yes
+			shift 3
+			;;
+		--)
+			shift
+			break
+			;;
+		esac
+	done
+
+	if test -z "$opt_set"
+	then
+		BUG "need check ops for test_line_count_in"
+	else
+		! (
+		test $(
+			(
+			test $(
+				( "$@" || echo "'$*' run into failure" >&3) |
+				wc -l
+				) "$out_ops" "$out_val" ||
+			echo "test_line_count_in --stdout: !$out_ops $out_val '$*'" >&3
+			) 2>&1 | wc -l
+		) "$err_ops" "$err_val" ||
+		echo "test_line_count_in --stderr: !$out_ops $out_val '$*'" >&3
+		) 3>&1 | grep .
+	fi
+}
+
 test_file_size () {
 	test "$#" -ne 1 && BUG "1 param"
 	test-tool path-utils file-size "$1"
-- 
2.31.1.500.gbc6bbdd36b


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH 2/2] t6402: check exit status of ls-files
  2021-04-22 15:04                         ` Ævar Arnfjörð Bjarmason
@ 2021-04-22 15:30                           ` Eric Sunshine
  0 siblings, 0 replies; 175+ messages in thread
From: Eric Sunshine @ 2021-04-22 15:30 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Đoàn Trần Công Danh, Junio C Hamano, Git List

On Thu, Apr 22, 2021 at 11:04 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Thu, Apr 22 2021, Đoàn Trần Công Danh wrote:
> > Hm, I'm not sure how would we implement such mode:
> >
> > * Will we run such command in a subprocess and and pipe to "wc -l"
> >   directly to avoid a temporary file, but we will lose the exit code
> >   of running command in process?
>
> Just use a tempfile.

That's what I had in mind when I suggested the function. The function
would remove the tempfile if the check succeeded.

> Here's an implementation that works, sans the fancy opts parsing etc. I
> just use -1 for "don't care". You can see "test_commit" etc. for how to
> do that.
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> @@ -817,6 +817,24 @@ test_line_count () {
> +test_line_count_command () {
> +       local op=$1
> +       local ocnt=$2
> +       local ecnt=$3
> +       shift 3
> +       "$@" 2>cnt.err >cnt.out
> +       local exit_code=$?
> +       if test "$ocnt" -gt -1
> +       then
> +               test_line_count "$op" "$ocnt" cnt.out
> +       fi &&
> +       if test "$ecnt" -gt -1
> +       then
> +               test_line_count "$op" "$ecnt" cnt.err
> +       fi &&
> +       return "$exit_code"
> +}

It's not clear why you manually catch the exit code of the command
being run but then use &&-chain for the other parts.

An important reason I suggested creating a function was because the
function could clean up after itself thus freeing the test author from
worrying about adjusting counts in later tests (or later in the same
test). So, just before this function returns, I'd expect to see:

    rm -f cnt.out cnt.err &&

^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                         ` (10 preceding siblings ...)
  2021-04-21 10:15       ` [PATCH v4 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21       ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
                           ` (13 more replies)
  11 siblings, 14 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Changes since v4: Only a commit message change/re-wording per
<87v98e1oj7.fsf@evledraar.gmail.com>.

Ævar Arnfjörð Bjarmason (11):
  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/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                       | 40 +++++++++++--------
 14 files changed, 87 insertions(+), 119 deletions(-)

Range-diff against v4:
 1:  a76ea749bb6 =  1:  75667f98f3a test-lib: bring $remove_trash out of retirement
 2:  de7be7844ea =  2:  55c9413f9cd test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
 3:  709bc773fb0 =  3:  361e34654e9 test-lib-functions: reword "test_commit --append" docs
 4:  b67654334e6 =  4:  2db68a4ac7c test-lib-functions: document test_commit --no-tag
 5:  3a166c92063 =  5:  4ceba3d404b test-lib functions: add an --annotated option to "test_commit"
 6:  981fc43ee69 =  6:  589eaf7a078 describe tests: convert setup to use test_commit
 7:  15057cdecfe =  7:  a0fe0640148 test-lib functions: add --printf option to test_commit
 8:  5d437f53ec8 =  8:  7fb8849ce66 submodule tests: use symbolic-ref --short to discover branch name
 9:  9ee13ee71bc =  9:  f67245ba40d test-lib: reformat argument list in test_create_repo()
10:  6ba568df9f4 = 10:  37338c88300 test-lib: do not show advice about init.defaultBranch under --verbose
11:  311a9dba36b ! 11:  7793311e5f1 test-lib: split up and deprecate test_create_repo()
    @@ Commit message
             from "mkdir .git/hooks" changes various tests needed to re-setup
             that directory. Now they no longer do.
     
    -     5. Since we don't need to move the .git/hooks directory we don't need
    -        the subshell here either.
    -
    -        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.
    +        This makes us implicitly depend on the default hooks being
    +        disabled, which is a good thing. If and when we'd have any
    +        on-by-default hooks (I see no reason we ever would) we'd want to
    +        see the subtle and not so subtle ways that would break the test
    +        suite.
    +
    +     5. We don't need to "cd" to the "$repo" directory at all anymore.
    +
    +        In the code being removed here we both "cd"'d to the repository
    +        before calling "init", and did so in a subshell.
    +
    +        It's not important to do either, so both of those can be
    +        removed. We cd'd because this code grew from test-lib.sh code
    +        where we'd have done so already, see eedf8f97e58 (Abstract
    +        test_create_repo out for use in tests., 2006-02-17), and later
    +        "cd"'d inside a subshell since 0d314ce834d to avoid having to keep
    +        track of an "old pwd" variable to cd back after the setup.
    +
    +        Being in the repository directory made moving the hooks around
    +        easier (we wouldn't have to fully qualify the path). Since we're
    +        not moving the hooks per #4 above we don't need to "cd" for that
    +        reason either.
     
          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
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v5 01/11] test-lib: bring $remove_trash out of retirement
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-05-06 15:46           ` Đoàn Trần Công Danh
  2021-04-23  7:21         ` [PATCH v5 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
                           ` (12 subsequent siblings)
  13 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

There's no point in creating a repository or directory only to decide
right afterwards that we're skipping all the tests. We can save
ourselves the redundant "git init" or "mkdir" and "rm -rf" in this
case.

We carry around the "$remove_trash" variable because if the directory
is unexpectedly gone at test_done time we'll hit the error about it
being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
can't remove trash directory, 2017-04-20).

So let's partially revert 06478dab4c (test-lib: retire $remove_trash
variable, 2017-04-23) and move the decision about whether to skip all
tests earlier.

Let's also fix a bug that was with us since abc5d372ec (Enable
parallel tests, 2008-08-08): we would leak $remove_trash from the
environment. We don't want this to error out, so let's reset it to the
empty string first:

     remove_trash=t GIT_SKIP_TESTS=t0001 ./t0001-init.sh

I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
under --debug at the end of the test, 2017-04-24) for a bug we don't
want to re-introduce.

While I'm at it let's move the HOME assignment to just before
test_create_repo, it could be lower, but it seems better to set it
before calling anything in test-lib-functions.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib.sh | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 3dec266221c..105c424bf56 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,7 +1169,7 @@ test_done () {
 			esac
 		fi
 
-		if test -z "$debug"
+		if test -z "$debug" && test -n "$remove_trash"
 		then
 			test -d "$TRASH_DIRECTORY" ||
 			error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1334,6 +1334,22 @@ then
 	exit 1
 fi
 
+# Are we running this test at all?
+remove_trash=
+this_test=${0##*/}
+this_test=${this_test%%-*}
+if match_pattern_list "$this_test" $GIT_SKIP_TESTS
+then
+	say_color info >&3 "skipping test $this_test altogether"
+	skip_all="skip all tests in $this_test"
+	test_done
+fi
+
+# Last-minute variable setup
+HOME="$TRASH_DIRECTORY"
+GNUPGHOME="$HOME/gnupg-home-not-used"
+export HOME GNUPGHOME
+
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {
 	GIT_EXIT_OK=t
@@ -1341,10 +1357,7 @@ rm -fr "$TRASH_DIRECTORY" || {
 	exit 1
 }
 
-HOME="$TRASH_DIRECTORY"
-GNUPGHOME="$HOME/gnupg-home-not-used"
-export HOME GNUPGHOME
-
+remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
 	test_create_repo "$TRASH_DIRECTORY"
@@ -1356,15 +1369,6 @@ fi
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
 
-this_test=${0##*/}
-this_test=${this_test%%-*}
-if match_pattern_list "$this_test" $GIT_SKIP_TESTS
-then
-	say_color info >&3 "skipping test $this_test altogether"
-	skip_all="skip all tests in $this_test"
-	test_done
-fi
-
 if test -n "$write_junit_xml"
 then
 	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
                           ` (11 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Stop setting the GIT_TEST_FRAMEWORK_SELFTEST variable. This was originally needed
back in 4231d1ba99 (t0000: do not get self-test disrupted by
environment warnings, 2018-09-20).

It hasn't been needed since I deleted the relevant code in test-lib.sh
in c0eedbc009 (test-lib: remove check_var_migration, 2021-02-09), I
just didn't notice that it was set here.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0000-basic.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 705d62cc27a..2c6e34b9478 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
 		passing metrics
 		'
 
-		# Tell the framework that we are self-testing to make sure
-		# it yields a stable result.
-		GIT_TEST_FRAMEWORK_SELFTEST=t &&
-
 		# Point to the t/test-lib.sh, which isn't in ../ as usual
 		. "\$TEST_DIRECTORY"/test-lib.sh
 		EOF
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 03/11] test-lib-functions: reword "test_commit --append" docs
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
                           ` (10 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Reword the documentation for "test_commit --append" added in my
3373518cc8 (test-lib functions: add an --append option to test_commit,
2021-01-12).

A follow-up commit will make the "echo" part of this configurable, and
in any case saying "echo >>" rather than ">>" was redundant.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b823c140271..1f787ff0726 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -172,8 +172,7 @@ debug () {
 #   --notick
 #	Do not call test_tick before making a commit
 #   --append
-#	Use "echo >>" instead of "echo >" when writing "<contents>" to
-#	"<file>"
+#	Use ">>" instead of ">" when writing "<contents>" to "<file>"
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 04/11] test-lib-functions: document test_commit --no-tag
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (2 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
                           ` (9 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

In 76b8b8d05c (test-lib functions: document arguments to test_commit,
2021-01-12) I added missing documentation to test_commit, but in less
than a month later in 3803a3a099 (t: add --no-tag option to
test_commit, 2021-02-09) we got another undocumented option. Let's fix
that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 1f787ff0726..c6d07f4ce32 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -177,6 +177,8 @@ debug () {
 #	Invoke "git commit" with --signoff
 #   --author <author>
 #	Invoke "git commit" with --author <author>
+#   --no-tag
+#	Do not tag the resulting commit
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 05/11] test-lib functions: add an --annotated option to "test_commit"
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (3 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
                           ` (8 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Add an --annotated option to test_commit to create annotated tags. The
tag will share the same message as the commit, and we'll call
test_tick before creating it (unless --notick) is provided.

There's quite a few tests that could be simplified with this
construct. I've picked one to convert in this change as a
demonstration.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1403-show-ref.sh     |  6 ++----
 t/test-lib-functions.sh | 27 ++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 6ce62f878c3..17d3cc14050 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
-	git tag -f -a -m "annotated A" A &&
+	test_commit --annotate A &&
 	git checkout -b side &&
-	test_commit B &&
-	git tag -f -a -m "annotated B" B &&
+	test_commit --annotate B &&
 	git checkout main &&
 	test_commit C &&
 	git branch B A^0
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index c6d07f4ce32..827c8502b10 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -179,6 +179,10 @@ debug () {
 #	Invoke "git commit" with --author <author>
 #   --no-tag
 #	Do not tag the resulting commit
+#   --annotate
+#	Create an annotated tag with "--annotate -m <message>". Calls
+#	test_tick between making the commit and tag, unless --notick
+#	is given.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -191,7 +195,7 @@ test_commit () {
 	author= &&
 	signoff= &&
 	indir= &&
-	no_tag= &&
+	tag=light &&
 	while test $# != 0
 	do
 		case "$1" in
@@ -219,7 +223,10 @@ test_commit () {
 			shift
 			;;
 		--no-tag)
-			no_tag=yes
+			tag=none
+			;;
+		--annotate)
+			tag=annotate
 			;;
 		*)
 			break
@@ -243,10 +250,20 @@ test_commit () {
 	git ${indir:+ -C "$indir"} commit \
 	    ${author:+ --author "$author"} \
 	    $signoff -m "$1" &&
-	if test -z "$no_tag"
-	then
+	case "$tag" in
+	none)
+		;;
+	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
-	fi
+		;;
+	annotate)
+		if test -z "$notick"
+		then
+			test_tick
+		fi &&
+		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
+		;;
+	esac
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 06/11] describe tests: convert setup to use test_commit
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (4 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-05-06 15:58           ` Đoàn Trần Công Danh
  2021-04-23  7:21         ` [PATCH v5 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
                           ` (7 subsequent siblings)
  13 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Convert the setup of the describe tests to use test_commit when
possible. This makes use of the new --annotated-tag option to
test_commit.

Some of the setup here could simply be removed since the data being
created wasn't important to any of the subsequent tests, so I've done
so. E.g. assigning to the "one" variable was always useless, and just
checking that we can describe HEAD after the first commit wasn't
useful.

In the case of the "two" variable we could instead use the tag we just
created. See 5312ab11fbf (Add describe test., 2007-01-13) for the
initial version of this code. There's other cases here like redundant
"test_tick" invocations, or the simplification of not echoing "X" to a
file we're about to tag as "x", now we just use "x" in both cases.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6120-describe.sh | 58 ++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 45 deletions(-)

diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index e89b6747bee..88fddc91424 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -31,64 +31,32 @@ check_describe () {
 }
 
 test_expect_success setup '
+	test_commit initial file one &&
+	test_commit second file two &&
+	test_commit third file three &&
+	test_commit --annotate A file A &&
+	test_commit c file c &&
 
-	test_tick &&
-	echo one >file && git add file && git commit -m initial &&
-	one=$(git rev-parse HEAD) &&
-
-	git describe --always HEAD &&
-
-	test_tick &&
-	echo two >file && git add file && git commit -m second &&
-	two=$(git rev-parse HEAD) &&
-
-	test_tick &&
-	echo three >file && git add file && git commit -m third &&
-
-	test_tick &&
-	echo A >file && git add file && git commit -m A &&
-	test_tick &&
-	git tag -a -m A A &&
-
-	test_tick &&
-	echo c >file && git add file && git commit -m c &&
-	test_tick &&
-	git tag c &&
-
-	git reset --hard $two &&
-	test_tick &&
-	echo B >side && git add side && git commit -m B &&
-	test_tick &&
-	git tag -a -m B B &&
+	git reset --hard second &&
+	test_commit --annotate B side B &&
 
 	test_tick &&
 	git merge -m Merged c &&
 	merged=$(git rev-parse HEAD) &&
 
-	git reset --hard $two &&
-	test_tick &&
-	echo D >another && git add another && git commit -m D &&
-	test_tick &&
-	git tag -a -m D D &&
-	test_tick &&
-	git tag -a -m R R &&
-
-	test_tick &&
-	echo DD >another && git commit -a -m another &&
+	git reset --hard second &&
+	test_commit --no-tag D another D &&
 
 	test_tick &&
-	git tag e &&
+	git tag -a -m R R &&
 
-	test_tick &&
-	echo DDD >another && git commit -a -m "yet another" &&
+	test_commit e another DD &&
+	test_commit --no-tag "yet another" another DDD &&
 
 	test_tick &&
 	git merge -m Merged $merged &&
 
-	test_tick &&
-	echo X >file && echo X >side && git add file side &&
-	git commit -m x
-
+	test_commit --no-tag x file
 '
 
 check_describe A-* HEAD
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 07/11] test-lib functions: add --printf option to test_commit
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (5 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-05-06 16:08           ` Đoàn Trần Công Danh
  2021-04-23  7:21         ` [PATCH v5 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
                           ` (6 subsequent siblings)
  13 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Add a --printf option to test_commit to allow writing to the file with
"printf" instead of "echo".

This is useful for writing "\n", "\0" etc., in particular in
combination with the --append option added in 3373518cc8 (test-lib
functions: add an --append option to test_commit, 2021-01-12).

I'm converting a few tests to use the new option rather than a manual
printf/add/commit combination to demonstrate its usefulness. While I'm
at it use "test_create_repo" where appropriate, and give the
first/second commit a meaningful/more conventional log message in
cases where no test cared about that message.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1307-config-blob.sh    |  4 +---
 t/t2030-unresolve-info.sh |  3 +--
 t/t4006-diff-mode.sh      |  6 ++----
 t/t4030-diff-textconv.sh  |  8 ++------
 t/t5520-pull.sh           | 10 ++--------
 t/test-lib-functions.sh   | 12 ++++++++++--
 6 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 002e6d3388e..930dce06f0f 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
 '
 
 test_expect_success 'can parse blob ending with CR' '
-	printf "[some]key = value\\r" >config &&
-	git add config &&
-	git commit -m CR &&
+	test_commit --printf CR config "[some]key = value\\r" &&
 	echo value >expect &&
 	git config --blob=HEAD:config some.key >actual &&
 	test_cmp expect actual
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index be6c84c52a2..f691e6d9032 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
 
 test_expect_success 'rerere forget (binary)' '
 	git checkout -f side &&
-	printf "a\0c" >binary &&
-	git commit -a -m binary &&
+	test_commit --printf binary binary "a\0c" &&
 	test_must_fail git merge second &&
 	git rerere forget binary
 '
diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh
index 275ce5fa15b..6cdee2a2164 100755
--- a/t/t4006-diff-mode.sh
+++ b/t/t4006-diff-mode.sh
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
 '
 
 test_expect_success 'prepare binary file' '
-	git commit -m rezrov &&
-	printf "\00\01\02\03\04\05\06" >binbin &&
-	git add binbin &&
-	git commit -m binbin
+	git commit -m one &&
+	test_commit --printf two binbin "\00\01\02\03\04\05\06"
 '
 
 test_expect_success '--stat output after text chmod' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index c906320b60d..a39a626664d 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -26,12 +26,8 @@ EOF
 chmod +x hexdump
 
 test_expect_success 'setup binary file with history' '
-	printf "\\0\\n" >file &&
-	git add file &&
-	git commit -m one &&
-	printf "\\01\\n" >>file &&
-	git add file &&
-	git commit -m two
+	test_commit --printf one file "\\0\\n" &&
+	test_commit --printf --append two file "\\01\\n"
 '
 
 test_expect_success 'file is considered binary by porcelain' '
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a09411327f9..e2c0c510222 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 '
 
 test_expect_success 'setup for detecting upstreamed changes' '
-	mkdir src &&
-	(
-		cd src &&
-		git init &&
-		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-		git add stuff &&
-		git commit -m "Initial revision"
-	) &&
+	test_create_repo src &&
+	test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
 	git clone src dst &&
 	(
 		cd src &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 827c8502b10..701518f5fd3 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -173,6 +173,10 @@ debug () {
 #	Do not call test_tick before making a commit
 #   --append
 #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
+#   --printf
+#       Use "printf" instead of "echo" when writing "<contents>" to
+#       "<file>". You will need to provide your own trailing "\n". You
+#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
@@ -191,6 +195,7 @@ debug () {
 
 test_commit () {
 	notick= &&
+	echo=echo &&
 	append= &&
 	author= &&
 	signoff= &&
@@ -202,6 +207,9 @@ test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--printf)
+			echo=printf
+			;;
 		--append)
 			append=yes
 			;;
@@ -238,9 +246,9 @@ test_commit () {
 	file=${2:-"$1.t"} &&
 	if test -n "$append"
 	then
-		echo "${3-$1}" >>"$indir$file"
+		$echo "${3-$1}" >>"$indir$file"
 	else
-		echo "${3-$1}" >"$indir$file"
+		$echo "${3-$1}" >"$indir$file"
 	fi &&
 	git ${indir:+ -C "$indir"} add "$file" &&
 	if test -z "$notick"
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 08/11] submodule tests: use symbolic-ref --short to discover branch name
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (6 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
                           ` (5 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Change a use of $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME added in
704fed9ea22 (tests: start moving to a different default main branch
name, 2020-10-23) to simply discover the initial branch name of a
repository set up in this function with "symbolic-ref --short".

That's something done in another test in 704fed9ea22, so doing it like
this seems like an omission, or rather an overly eager
search/replacement instead of fixing the test logic.

There are only three uses of the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
variable in the test suite, this gets rid of one of those.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-submodule-update.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 4b714e93083..f7c7df0ca42 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
 	git init submodule_update_repo &&
 	(
 		cd submodule_update_repo &&
+		branch=$(git symbolic-ref --short HEAD) &&
 		echo "expect" >>.gitignore &&
 		echo "actual" >>.gitignore &&
 		echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
 		git checkout -b valid_sub1 &&
 		git revert HEAD &&
 
-		git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
+		git checkout "$branch"
 	)
 }
 
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 09/11] test-lib: reformat argument list in test_create_repo()
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (7 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
                           ` (4 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Reformat an argument list changed in 675704c74dd (init: provide useful
advice about init.defaultBranch, 2020-12-11) to have the "-c" on the
same line as the argument it sets. This whitespace-only change makes
it easier to review a subsequent commit.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 701518f5fd3..7101030f042 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1250,8 +1250,8 @@ test_create_repo () {
 	mkdir -p "$repo"
 	(
 		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
-			init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
+		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
+			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 10/11] test-lib: do not show advice about init.defaultBranch under --verbose
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (8 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:21         ` [PATCH v5 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
                           ` (3 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Arrange for the advice about naming the initial branch not to be shown
in the --verbose output of the test suite.

Since 675704c74dd (init: provide useful advice about
init.defaultBranch, 2020-12-11) some tests have been very chatty with
repeated occurrences of this multi-line advice. Having it be this
verbose isn't helpful for anyone in the context of git's own test
suite, and it makes debugging tests that use their own "git init"
invocations needlessly distracting.

By setting the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME variable early in
test-lib.sh itself we'll squash the warning not only for
test_create_repo(), as 675704c74dd explicitly intended, but also for
other "git init" invocations.

And once we'd like to have this configuration set for all "git init"
invocations in the test suite we can get rid of the init.defaultBranch
configuration setting in test_create_repo(), as
repo_default_branch_name() in refs.c will take the GIT_TEST_* variable
over it being set.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 1 -
 t/test-lib.sh           | 5 +++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 7101030f042..c9f33b79151 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1251,7 +1251,6 @@ test_create_repo () {
 	(
 		cd "$repo" || error "Cannot setup test environment"
 		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 105c424bf56..ab1fe98ccce 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -64,6 +64,11 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 fi
 
+# Explicitly set the default branch name for testing, to avoid the
+# transitory "git init" warning under --verbose.
+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
 ################################################################
 # It appears that people try to run tests without building...
 "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v5 11/11] test-lib: split up and deprecate test_create_repo()
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (9 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:21         ` Ævar Arnfjörð Bjarmason
  2021-04-29  7:23         ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Junio C Hamano
                           ` (2 subsequent siblings)
  13 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:21 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

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.

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.

 2. Since we're now a simple wrapper for "git init" we don't need to
    check that we have only one argument. If someone wants to run
    "test_create_repo --bare x" that's OK.

 3. We won't ever hit that "Cannot setup test environment"
    error.

    Checking the test environment sanity when doing "git init" dates
    back to eea420693be (t0000: catch trivial pilot errors.,
    2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
    was successfully created, 2006-01-05).

    We can also see it in another form a bit later in my own
    0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
    $old, 2010-08-30).

    But since 2006f0adaee (t/test-lib: make sure Git has already been
    built, 2012-09-17) we already check if we have a built git
    earlier.

    The one thing this was testing after that 2012 change was that
    we'd just built "git", but not "git-init", but since
    3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
    repositories, 2018-11-12) we invoke "git", not "git-init".

    So all of that's been checked already, and we don't need to
    re-check it here.

 4. We don't need to move .git/hooks out of the way.

    That dates back to c09a69a83e3 (Disable hooks during tests.,
    2005-10-16), since then hooks became disabled by default in
    f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).

    So the hooks were already disabled by default, but as can be seen
    from "mkdir .git/hooks" changes various tests needed to re-setup
    that directory. Now they no longer do.

    This makes us implicitly depend on the default hooks being
    disabled, which is a good thing. If and when we'd have any
    on-by-default hooks (I see no reason we ever would) we'd want to
    see the subtle and not so subtle ways that would break the test
    suite.

 5. We don't need to "cd" to the "$repo" directory at all anymore.

    In the code being removed here we both "cd"'d to the repository
    before calling "init", and did so in a subshell.

    It's not important to do either, so both of those can be
    removed. We cd'd because this code grew from test-lib.sh code
    where we'd have done so already, see eedf8f97e58 (Abstract
    test_create_repo out for use in tests., 2006-02-17), and later
    "cd"'d inside a subshell since 0d314ce834d to avoid having to keep
    track of an "old pwd" variable to cd back after the setup.

    Being in the repository directory made moving the hooks around
    easier (we wouldn't have to fully qualify the path). Since we're
    not moving the hooks per #4 above we don't need to "cd" for that
    reason either.

 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.

    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.

 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

    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/t5406-remote-rejects.sh           |  1 -
 t/t5407-post-rewrite-hook.sh        |  2 --
 t/t5409-colorize-remote-messages.sh |  1 -
 t/test-lib-functions.sh             | 15 ++-------------
 t/test-lib.sh                       |  3 ++-
 5 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh
index ff06f99649e..5c509db6fc3 100755
--- a/t/t5406-remote-rejects.sh
+++ b/t/t5406-remote-rejects.sh
@@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	exit 1
 	EOF
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 5bb23cc3a4e..6da8d760e28 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -20,8 +20,6 @@ test_expect_success 'setup' '
 	git checkout main
 '
 
-mkdir .git/hooks
-
 cat >.git/hooks/post-rewrite <<EOF
 #!/bin/sh
 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index 5d8f401d8ec..9f1a483f426 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	echo error: error
 	echo ERROR: also highlighted
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index c9f33b79151..213b1988aa4 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1241,21 +1241,10 @@ test_atexit () {
 		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
 }
 
-# Most tests can use the created repository, but some may need to create more.
+# Deprecated wrapper for "git init", use "git init" directly instead
 # Usage: test_create_repo <directory>
 test_create_repo () {
-	test "$#" = 1 ||
-	BUG "not 1 parameter to test-create-repo"
-	repo="$1"
-	mkdir -p "$repo"
-	(
-		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			init \
-			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
-		error "cannot run git init -- have you built things yet?"
-		mv .git/hooks .git/hooks-disabled
-	) || exit
+	git init "$@"
 }
 
 # This function helps on symlink challenged file systems when it is not
diff --git a/t/test-lib.sh b/t/test-lib.sh
index ab1fe98ccce..5fd968d11b2 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1365,7 +1365,8 @@ rm -fr "$TRASH_DIRECTORY" || {
 remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
-	test_create_repo "$TRASH_DIRECTORY"
+	git init "$TRASH_DIRECTORY" >&3 2>&4 ||
+	error "cannot run git init"
 else
 	mkdir -p "$TRASH_DIRECTORY"
 fi
-- 
2.31.1.737.g98b508eba36


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose
  2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
                       ` (4 preceding siblings ...)
  2021-04-21 14:58     ` [PATCH v2 5/5] test-helpers: split "file-size" into "file-size(s)" Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:29     ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:29       ` [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
                         ` (3 more replies)
  5 siblings, 4 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This series makes the "-x" output less verbose for our various helper
functions, mainly using the trickery of feeding "$@" to "test" to rely
on it to die when given too many arguments.

Since v2[1] I ejected the 3rd patch. I thought some test-lib code was
removed, but was only grepping t/, turned out it was used in ci/.

https://lore.kernel.org/git/cover-0.5-00000000000-20210421T144921Z-avarab@gmail.com

Ævar Arnfjörð Bjarmason (4):
  test-lib-functions: normalize test_path_is_missing() debugging
  Revert and amend "test-lib-functions: assert correct parameter count"
  test-helpers: rename "path-utils is_valid_path" to "is-valid-paths"
  test-helpers: split "file-size" into "file-size(s)"

 t/helper/test-path-utils.c  | 13 +++++--
 t/t0060-path-utils.sh       |  2 +-
 t/t1050-large.sh            |  2 +-
 t/t5319-multi-pack-index.sh |  6 ++--
 t/test-lib-functions.sh     | 67 ++++++++++++++++---------------------
 5 files changed, 45 insertions(+), 45 deletions(-)

Range-diff against v2:
1:  ba9d6251ad5 = 1:  26a3d552d88 test-lib-functions: normalize test_path_is_missing() debugging
2:  5f8e5ad27f5 = 2:  3a570321770 Revert and amend "test-lib-functions: assert correct parameter count"
3:  44948c6ace9 < -:  ----------- test helpers: remove unused test-tool path-utils slice-tests
4:  ae5dc5d03b3 = 3:  bf35091a112 test-helpers: rename "path-utils is_valid_path" to "is-valid-paths"
5:  947791d9535 = 4:  ac0b920c041 test-helpers: split "file-size" into "file-size(s)"
-- 
2.31.1.734.gdef39492517


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging
  2021-04-23  7:29     ` [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:29       ` Ævar Arnfjörð Bjarmason
  2021-04-29  3:49         ` Junio C Hamano
  2021-04-23  7:29       ` [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Change the test_path_is_missing() to be consistent with related
functions. Since 2caf20c52b7 (test-lib: user-friendly alternatives to
test [-d|-f|-e], 2010-08-10) we've been ls -ld-ing the bad path and
echo-ing $* if it exists. Let's just say that it exists instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 213b1988aa4..2914b398470 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -810,12 +810,7 @@ test_path_is_missing () {
 	test "$#" -ne 1 && BUG "1 param"
 	if test -e "$1"
 	then
-		echo "Path exists:"
-		ls -ld "$1"
-		if test $# -ge 1
-		then
-			echo "$*"
-		fi
+		echo "Path $1 exists!"
 		false
 	fi
 }
-- 
2.31.1.734.gdef39492517


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-23  7:29     ` [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-23  7:29       ` [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:29       ` Ævar Arnfjörð Bjarmason
  2021-04-29  3:59         ` Junio C Hamano
  2021-04-29  4:02         ` Felipe Contreras
  2021-04-23  7:29       ` [PATCH v3 3/4] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Ævar Arnfjörð Bjarmason
  2021-04-23  7:29       ` [PATCH v3 4/4] test-helpers: split "file-size" into "file-size(s)" Ævar Arnfjörð Bjarmason
  3 siblings, 2 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

This reverts and amends my my own e7884b353b7 (test-lib-functions:
assert correct parameter count, 2021-02-12) in order to improve the -x
output.

The goal here is to get rid of the verbosity of having e.g. a "test 2
-ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
to intentionally feed the "test" operator too many arguments if the
functions are called with too many arguments, thus piggy-backing on it
to check the number of arguments we get.

Before this for each test_cmp invocation we'd emit:

    + test_cmp expect actual
    + test 2 -ne 2
    + eval diff -u "$@"
    + diff -u expect actual

That "test 2 -ne 2" line is new in my e7884b353b7. As noted in
45a2686441b (test-lib-functions: remove bug-inducing "diagnostics"
helper param, 2021-02-12) we had buggy invocations of some of these
functions with too many parameters.

Now we'll get just:

    + test_cmp expect actual
    + eval diff -u "$@"
    + diff -u expect actual

This does not to the "right" thing in cases like:

    test_path_is_file x -a y

Which will now turn into:

    test -f x -a y

I consider that to be OK given the trade-off that any extra checking
would produce more verbose trace output. As shown in 45a2686441b we
had issues with these functions being invoked with multiple
parameters (e.g. a glob) by accident, we don't need to be paranoid in
guarding against hostile misuse from our own test suite.

While I'm at it change a few functions that relied on a "false" being
the last statement in the function to use an explicit "return 1" like
the other functions in this file.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 59 +++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 2914b398470..0adb9fd124d 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -756,41 +756,43 @@ test_external_without_stderr () {
 }
 
 # debugging-friendly alternatives to "test [-f|-d|-e]"
-# The commands test the existence or non-existence of $1
+# The commands test the existence or non-existence of
+# a given argument.
+#
+# The pattern of using "$@" to "test" instead of "$1" is not a bug. We
+# are counting on "test" to error on too many arguments if more than
+# one is given. Checking "$#" explicitly would lead to overly verbose
+# -x output.
 test_path_is_file () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -f "$1"
+	if ! test -f "$@"
 	then
-		echo "File $1 doesn't exist"
-		false
+		echo "File $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_is_dir () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -d "$1"
+	if ! test -d "$@"
 	then
-		echo "Directory $1 doesn't exist"
-		false
+		echo "Directory $* doesn't exist"
+		return 1
 	fi
 }
 
 test_path_exists () {
-	test "$#" -ne 1 && BUG "1 param"
-	if ! test -e "$1"
+	if ! test -e "$@"
 	then
-		echo "Path $1 doesn't exist"
-		false
+		echo "Path $* doesn't exist"
+		return 1
 	fi
 }
 
 # Check if the directory exists and is empty as expected, barf otherwise.
 test_dir_is_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_dir "$1" &&
-	if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
+	test_path_is_dir "$@" &&
+	if test -n "$(ls -a1 "$@" | egrep -v '^\.\.?$')"
 	then
-		echo "Directory '$1' is not empty, it contains:"
+		echo "Directory '$*' is not empty, it contains:"
 		ls -la "$1"
 		return 1
 	fi
@@ -798,19 +800,17 @@ test_dir_is_empty () {
 
 # Check if the file exists and has a size greater than zero
 test_file_not_empty () {
-	test "$#" = 2 && BUG "2 param"
-	if ! test -s "$1"
+	if ! test -s "$@"
 	then
-		echo "'$1' is not a non-empty file."
-		false
+		echo "'$*' is not a non-empty file."
+		return 1
 	fi
 }
 
 test_path_is_missing () {
-	test "$#" -ne 1 && BUG "1 param"
-	if test -e "$1"
+	if test -e "$@"
 	then
-		echo "Path $1 exists!"
+		echo "Path $* exists!"
 		false
 	fi
 }
@@ -1012,7 +1012,6 @@ test_expect_code () {
 # - not all diff versions understand "-u"
 
 test_cmp () {
-	test "$#" -ne 2 && BUG "2 param"
 	eval "$GIT_TEST_CMP" '"$@"'
 }
 
@@ -1042,7 +1041,6 @@ test_cmp_config () {
 # test_cmp_bin - helper to compare binary files
 
 test_cmp_bin () {
-	test "$#" -ne 2 && BUG "2 param"
 	cmp "$@"
 }
 
@@ -1096,12 +1094,11 @@ verbose () {
 # otherwise.
 
 test_must_be_empty () {
-	test "$#" -ne 1 && BUG "1 param"
-	test_path_is_file "$1" &&
-	if test -s "$1"
+	test_path_is_file "$@" &&
+	if test -s "$@"
 	then
-		echo "'$1' is not empty, it contains:"
-		cat "$1"
+		echo "'$*' is not empty, it contains:"
+		cat "$@"
 		return 1
 	fi
 }
-- 
2.31.1.734.gdef39492517


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 3/4] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths"
  2021-04-23  7:29     ` [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
  2021-04-23  7:29       ` [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
  2021-04-23  7:29       ` [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:29       ` Ævar Arnfjörð Bjarmason
  2021-04-23  7:29       ` [PATCH v3 4/4] test-helpers: split "file-size" into "file-size(s)" Ævar Arnfjörð Bjarmason
  3 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Rename this utility added in d2c84dad1c8 (mingw: refuse to access
paths with trailing spaces or periods, 2019-09-05) to make it clear
that it expects N number of arguments, and for consistency with
dc2d9ba3187 (is_{hfs,ntfs}_dotgitmodules: add tests, 2018-05-12).

Let's also make it a dashed "is-valid-paths" instead of
"is_valid_path*" to make it easier to grep the helper v.s. the C
function it calls.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-path-utils.c | 2 +-
 t/t0060-path-utils.sh      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 313a153209c..eed3068ffb7 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -454,7 +454,7 @@ int cmd__path_utils(int argc, const char **argv)
 	if (argc > 1 && !strcmp(argv[1], "protect_ntfs_hfs"))
 		return !!protect_ntfs_hfs_benchmark(argc - 1, argv + 1);
 
-	if (argc > 1 && !strcmp(argv[1], "is_valid_path")) {
+	if (argc > 1 && !strcmp(argv[1], "is-valid-paths")) {
 		int res = 0, expect = 1, i;
 
 		for (i = 2; i < argc; i++)
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 0ff06b5d1b3..e7fb748b19c 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -469,7 +469,7 @@ test_expect_success 'match .gitmodules' '
 '
 
 test_expect_success MINGW 'is_valid_path() on Windows' '
-	test-tool path-utils is_valid_path \
+	test-tool path-utils is-valid-paths \
 		win32 \
 		"win32 x" \
 		../hello.txt \
-- 
2.31.1.734.gdef39492517


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v3 4/4] test-helpers: split "file-size" into "file-size(s)"
  2021-04-23  7:29     ` [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
                         ` (2 preceding siblings ...)
  2021-04-23  7:29       ` [PATCH v3 3/4] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Ævar Arnfjörð Bjarmason
@ 2021-04-23  7:29       ` Ævar Arnfjörð Bjarmason
  3 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-04-23  7:29 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Split the "file-size" helper into two helpers, one that takes 1
argument, and another one that takes N.

This allows us to remove the "BUG" check in test-lib-functions.sh for
briefer -x output, and more importantly will clearly distinguish those
cases where we expect one argument v.s. many.

The use in t1050-large.sh wants to check just one pack, we used to
check that explicitly before 53b67a801bb (tests: consolidate the
`file_size` function into `test-lib-functions.sh`, 2020-11-07), now we
do so again.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-path-utils.c  | 11 ++++++++++-
 t/t1050-large.sh            |  2 +-
 t/t5319-multi-pack-index.sh |  6 +++---
 t/test-lib-functions.sh     |  3 +--
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index eed3068ffb7..17645da4a1c 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -280,6 +280,8 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)
 
 int cmd__path_utils(int argc, const char **argv)
 {
+	int is_file_size, is_file_sizes;
+
 	if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
 		char *buf = xmallocz(strlen(argv[2]));
 		int rv = normalize_path_copy(buf, argv[2]);
@@ -395,10 +397,17 @@ int cmd__path_utils(int argc, const char **argv)
 		return !!res;
 	}
 
-	if (argc > 2 && !strcmp(argv[1], "file-size")) {
+	is_file_size = !strcmp(argv[1], "file-size");
+	is_file_sizes = !strcmp(argv[1], "file-sizes");
+	if (argc > 2 && (is_file_size || is_file_sizes)) {
 		int res = 0, i;
 		struct stat st;
 
+		if (is_file_size && argc > 3) {
+			res = error("too many arguments to is-file-size, use is-file-sizes?");
+			return res;
+		}
+
 		for (i = 2; i < argc; i++)
 			if (stat(argv[i], &st))
 				res = error_errno("Cannot stat '%s'", argv[i]);
diff --git a/t/t1050-large.sh b/t/t1050-large.sh
index 4bab6a513c5..0b76ab0e3f9 100755
--- a/t/t1050-large.sh
+++ b/t/t1050-large.sh
@@ -23,7 +23,7 @@ do
 	test_expect_success "add with $config" '
 		test_when_finished "rm -f .git/objects/pack/pack-*.* .git/index" &&
 		git $config add large1 &&
-		sz=$(test_file_size .git/objects/pack/pack-*.pack) &&
+		sz=$(test-tool path-utils file-size .git/objects/pack/pack-*.pack) &&
 		case "$expect" in
 		small) test "$sz" -le 100000 ;;
 		large) test "$sz" -ge 100000 ;;
diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh
index 5641d158dfc..baeda407b90 100755
--- a/t/t5319-multi-pack-index.sh
+++ b/t/t5319-multi-pack-index.sh
@@ -648,7 +648,7 @@ test_expect_success 'repack with minimum size does not alter existing packs' '
 		test-tool chmtime =-3 .git/objects/pack/pack-B* &&
 		test-tool chmtime =-2 .git/objects/pack/pack-A* &&
 		ls .git/objects/pack >expect &&
-		MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
+		MINSIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | head -n 1) &&
 		git multi-pack-index repack --batch-size=$MINSIZE &&
 		ls .git/objects/pack >actual &&
 		test_cmp expect actual
@@ -672,7 +672,7 @@ test_expect_success 'repack respects repack.packKeptObjects=false' '
 		test_line_count = 5 idx-list &&
 		test-tool read-midx .git/objects | grep idx >midx-list &&
 		test_line_count = 5 midx-list &&
-		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | sed -n 3p) &&
+		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | sed -n 3p) &&
 		BATCH_SIZE=$((THIRD_SMALLEST_SIZE + 1)) &&
 		git multi-pack-index repack --batch-size=$BATCH_SIZE &&
 		ls .git/objects/pack/*idx >idx-list &&
@@ -687,7 +687,7 @@ test_expect_success 'repack creates a new pack' '
 		cd dup &&
 		ls .git/objects/pack/*idx >idx-list &&
 		test_line_count = 5 idx-list &&
-		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
+		THIRD_SMALLEST_SIZE=$(test-tool path-utils file-sizes .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
 		BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
 		git multi-pack-index repack --batch-size=$BATCH_SIZE &&
 		ls .git/objects/pack/*idx >idx-list &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 0adb9fd124d..602d77dee37 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -839,8 +839,7 @@ test_line_count () {
 }
 
 test_file_size () {
-	test "$#" -ne 1 && BUG "1 param"
-	test-tool path-utils file-size "$1"
+	test-tool path-utils file-size "$@"
 }
 
 # Returns success if a comma separated string of keywords ($1) contains a
-- 
2.31.1.734.gdef39492517


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging
  2021-04-23  7:29       ` [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
@ 2021-04-29  3:49         ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-29  3:49 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Change the test_path_is_missing() to be consistent with related
> functions.

Not very helpful to readers.  It is totally unclear what kind of
consistency is being sought by this patch.

> Since 2caf20c52b7 (test-lib: user-friendly alternatives to
> test [-d|-f|-e], 2010-08-10) we've been ls -ld-ing the bad path and
> echo-ing $* if it exists.

Yes, and it does not explain what's wrong with that behaviour.

If there were something like "... but no invocation of the shell
function passes $2 and subsequent arguments" (I didn't check if that
is the case) after the above, it might have been more
understandable, though.

> Let's just say that it exists instead.

As the earlier parts of the proposed log message are so weak, this
conclusion does not sound convincing.

> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/test-lib-functions.sh | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 213b1988aa4..2914b398470 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -810,12 +810,7 @@ test_path_is_missing () {
>  	test "$#" -ne 1 && BUG "1 param"
>  	if test -e "$1"
>  	then
> -		echo "Path exists:"
> -		ls -ld "$1"
> -		if test $# -ge 1
> -		then
> -			echo "$*"
> -		fi
> +		echo "Path $1 exists!"
>  		false
>  	fi
>  }

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-23  7:29       ` [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
@ 2021-04-29  3:59         ` Junio C Hamano
  2021-04-29  4:02         ` Felipe Contreras
  1 sibling, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-29  3:59 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> The goal here is to get rid of the verbosity of having e.g. a "test 2
> -ne 2" line for every "test_cmp". We use "$@" as an argument to "test"
> to intentionally feed the "test" operator too many arguments if the
> functions are called with too many arguments, thus piggy-backing on it
> to check the number of arguments we get.
>
> Before this for each test_cmp invocation we'd emit:
>
>     + test_cmp expect actual
>     + test 2 -ne 2
>     + eval diff -u "$@"
>     + diff -u expect actual

Quite honestly, I do not see what's bad about that and am not all
that sympathetic to the cause behind this series.

The developer is asking to debug the test script by passing '-x',
and see where the test script is broken.  Especially since ...

> Now we'll get just:
>
>     + test_cmp expect actual
>     + eval diff -u "$@"
>     + diff -u expect actual

... we are not removing the 'eval diff -u "$@"' line, I do not think
how a few extra trace output lines coming from sanity check hurts
all that much.  It is worth paying for to have such basic sanity
checks expressed in a more natural way (than "oh, this hack would
not work when 'one -a two' is used as a path"), I would think.

Thanks.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* RE: [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count"
  2021-04-23  7:29       ` [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
  2021-04-29  3:59         ` Junio C Hamano
@ 2021-04-29  4:02         ` Felipe Contreras
  1 sibling, 0 replies; 175+ messages in thread
From: Felipe Contreras @ 2021-04-29  4:02 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason, git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Ævar Arnfjörð Bjarmason wrote:
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 2914b398470..0adb9fd124d 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -756,41 +756,43 @@ test_external_without_stderr () {
>  }
>  
>  # debugging-friendly alternatives to "test [-f|-d|-e]"
> -# The commands test the existence or non-existence of $1
> +# The commands test the existence or non-existence of
> +# a given argument.
> +#
> +# The pattern of using "$@" to "test" instead of "$1" is not a bug. We
> +# are counting on "test" to error on too many arguments if more than
> +# one is given. Checking "$#" explicitly would lead to overly verbose
> +# -x output.

I would consider adding an extra line. In my mind a comment without a
line is for the next function, one with a line is for the section.

  # function comment
  function_1 ()

Versus:

  # section comment

  function_1 ()
  function_2 ()

But I agree with the other comments that it's better inside the
function. It's an implementation detail.

While I think git tries to follow the self-documenting code style,
sometimes it's better to just write the comment.

>  test_path_is_file () {
> -	test "$#" -ne 1 && BUG "1 param"
> -	if ! test -f "$1"
> +	if ! test -f "$@"

  if ! test -f "$@" # Rely on test to ensure 1 param

>  	then
> -		echo "File $1 doesn't exist"
> -		false
> +		echo "File $* doesn't exist"
> +		return 1
>  	fi
>  }

And yes, I would add that comment to every instance where this trick is
used. That way people reading the second or third function don't have to
scratch their heads, or miraculously read a comment far above.

Cheers.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (10 preceding siblings ...)
  2021-04-23  7:21         ` [PATCH v5 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-04-29  7:23         ` Junio C Hamano
  2021-05-06 15:32         ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
  13 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-04-29  7:23 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Jeff King, Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Changes since v4: Only a commit message change/re-wording per
> <87v98e1oj7.fsf@evledraar.gmail.com>.
>
> Ævar Arnfjörð Bjarmason (11):
>   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()

I wasn't paying much attention to this series, and didn't look at
the last step at all (as I saw somebody else is already deeply
biting into it), but the earlier parts looked good to me.

It was painful to come back to the pile of topics after a week's
interruption, though.  While juggling ~50 topics, it is unfair to
expect the maintainer to remember that a topic that is still going
through iterations are depended on two other topics in flight (it is
easier for contributors, who will be juggling far fewer number of
topics at one time).

But I think I've sorted out the duplicates caused by forgetting that
I had to rebase ab/pickaxe-pcre2 and ab/describe-tests-fix on top of
this topic.  Will be pushing out the result of today's integration
sometime this evening, which is far from complete as I am still in
the "catch up with what happened during my absense" mode.

Thanks.




^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (11 preceding siblings ...)
  2021-04-29  7:23         ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Junio C Hamano
@ 2021-05-06 15:32         ` Ævar Arnfjörð Bjarmason
  2021-05-06 16:21           ` Đoàn Trần Công Danh
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
  13 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-06 15:32 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason


On Fri, Apr 23 2021, Ævar Arnfjörð Bjarmason wrote:

> Changes since v4: Only a commit message change/re-wording per
> <87v98e1oj7.fsf@evledraar.gmail.com>.

SZEDER, Eric, Đoàn et al: does this v5 look good to you? Junio's
suggested in [1] that this needs some final review feedback before
advancing to 'next'. If you could take a look that would be great!

1. https://lore.kernel.org/git/xmqqsg30zdql.fsf@gitster.g/

> Ævar Arnfjörð Bjarmason (11):
>   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/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                       | 40 +++++++++++--------
>  14 files changed, 87 insertions(+), 119 deletions(-)
>
> Range-diff against v4:
>  1:  a76ea749bb6 =  1:  75667f98f3a test-lib: bring $remove_trash out of retirement
>  2:  de7be7844ea =  2:  55c9413f9cd test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
>  3:  709bc773fb0 =  3:  361e34654e9 test-lib-functions: reword "test_commit --append" docs
>  4:  b67654334e6 =  4:  2db68a4ac7c test-lib-functions: document test_commit --no-tag
>  5:  3a166c92063 =  5:  4ceba3d404b test-lib functions: add an --annotated option to "test_commit"
>  6:  981fc43ee69 =  6:  589eaf7a078 describe tests: convert setup to use test_commit
>  7:  15057cdecfe =  7:  a0fe0640148 test-lib functions: add --printf option to test_commit
>  8:  5d437f53ec8 =  8:  7fb8849ce66 submodule tests: use symbolic-ref --short to discover branch name
>  9:  9ee13ee71bc =  9:  f67245ba40d test-lib: reformat argument list in test_create_repo()
> 10:  6ba568df9f4 = 10:  37338c88300 test-lib: do not show advice about init.defaultBranch under --verbose
> 11:  311a9dba36b ! 11:  7793311e5f1 test-lib: split up and deprecate test_create_repo()
>     @@ Commit message
>              from "mkdir .git/hooks" changes various tests needed to re-setup
>              that directory. Now they no longer do.
>      
>     -     5. Since we don't need to move the .git/hooks directory we don't need
>     -        the subshell here either.
>     -
>     -        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.
>     +        This makes us implicitly depend on the default hooks being
>     +        disabled, which is a good thing. If and when we'd have any
>     +        on-by-default hooks (I see no reason we ever would) we'd want to
>     +        see the subtle and not so subtle ways that would break the test
>     +        suite.
>     +
>     +     5. We don't need to "cd" to the "$repo" directory at all anymore.
>     +
>     +        In the code being removed here we both "cd"'d to the repository
>     +        before calling "init", and did so in a subshell.
>     +
>     +        It's not important to do either, so both of those can be
>     +        removed. We cd'd because this code grew from test-lib.sh code
>     +        where we'd have done so already, see eedf8f97e58 (Abstract
>     +        test_create_repo out for use in tests., 2006-02-17), and later
>     +        "cd"'d inside a subshell since 0d314ce834d to avoid having to keep
>     +        track of an "old pwd" variable to cd back after the setup.
>     +
>     +        Being in the repository directory made moving the hooks around
>     +        easier (we wouldn't have to fully qualify the path). Since we're
>     +        not moving the hooks per #4 above we don't need to "cd" for that
>     +        reason either.
>      
>           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


^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v5 01/11] test-lib: bring $remove_trash out of retirement
  2021-04-23  7:21         ` [PATCH v5 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-05-06 15:46           ` Đoàn Trần Công Danh
  0 siblings, 0 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-05-06 15:46 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine, SZEDER Gábor,
	Andreas Schwab

On 2021-04-23 09:21:05+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> There's no point in creating a repository or directory only to decide
> right afterwards that we're skipping all the tests. We can save
> ourselves the redundant "git init" or "mkdir" and "rm -rf" in this
> case.
> 
> We carry around the "$remove_trash" variable because if the directory
> is unexpectedly gone at test_done time we'll hit the error about it
> being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
> can't remove trash directory, 2017-04-20).

s/test_done time/&,/ perhaps?

I guess it maybe only me (I'm not a native speaker of any Indo-European
languages). But "because if" sounds weird to me. In my native tongue,
I would say something like:

	We carry around ... variable because we'll hit the error ...
	if the directory is expectedly gone ...

> So let's partially revert 06478dab4c (test-lib: retire $remove_trash
> variable, 2017-04-23) and move the decision about whether to skip all
> tests earlier.
> 
> Let's also fix a bug that was with us since abc5d372ec (Enable
> parallel tests, 2008-08-08): we would leak $remove_trash from the
> environment. We don't want this to error out, so let's reset it to the
> empty string first:
> 
>      remove_trash=t GIT_SKIP_TESTS=t0001 ./t0001-init.sh
> 
> I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
> under --debug at the end of the test, 2017-04-24) for a bug we don't
> want to re-introduce.
> 
> While I'm at it let's move the HOME assignment to just before

s/at it/&,/ too?

> test_create_repo, it could be lower, but it seems better to set it
> before calling anything in test-lib-functions.sh
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/test-lib.sh | 32 ++++++++++++++++++--------------
>  1 file changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 3dec266221c..105c424bf56 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -1169,7 +1169,7 @@ test_done () {
>  			esac
>  		fi
>  
> -		if test -z "$debug"
> +		if test -z "$debug" && test -n "$remove_trash"
>  		then
>  			test -d "$TRASH_DIRECTORY" ||
>  			error "Tests passed but trash directory already removed before test cleanup; aborting"
> @@ -1334,6 +1334,22 @@ then
>  	exit 1
>  fi
>  
> +# Are we running this test at all?
> +remove_trash=
> +this_test=${0##*/}
> +this_test=${this_test%%-*}
> +if match_pattern_list "$this_test" $GIT_SKIP_TESTS
> +then
> +	say_color info >&3 "skipping test $this_test altogether"
> +	skip_all="skip all tests in $this_test"
> +	test_done
> +fi
> +
> +# Last-minute variable setup
> +HOME="$TRASH_DIRECTORY"
> +GNUPGHOME="$HOME/gnupg-home-not-used"
> +export HOME GNUPGHOME
> +
>  # Test repository
>  rm -fr "$TRASH_DIRECTORY" || {
>  	GIT_EXIT_OK=t
> @@ -1341,10 +1357,7 @@ rm -fr "$TRASH_DIRECTORY" || {
>  	exit 1
>  }
>  
> -HOME="$TRASH_DIRECTORY"
> -GNUPGHOME="$HOME/gnupg-home-not-used"
> -export HOME GNUPGHOME
> -
> +remove_trash=t
>  if test -z "$TEST_NO_CREATE_REPO"
>  then
>  	test_create_repo "$TRASH_DIRECTORY"
> @@ -1356,15 +1369,6 @@ fi
>  # in subprocesses like git equals our $PWD (for pathname comparisons).
>  cd -P "$TRASH_DIRECTORY" || exit 1
>  
> -this_test=${0##*/}
> -this_test=${this_test%%-*}
> -if match_pattern_list "$this_test" $GIT_SKIP_TESTS
> -then
> -	say_color info >&3 "skipping test $this_test altogether"
> -	skip_all="skip all tests in $this_test"
> -	test_done
> -fi
> -
>  if test -n "$write_junit_xml"
>  then
>  	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
> -- 
> 2.31.1.737.g98b508eba36
> 

-- 
Danh

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v5 06/11] describe tests: convert setup to use test_commit
  2021-04-23  7:21         ` [PATCH v5 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
@ 2021-05-06 15:58           ` Đoàn Trần Công Danh
  0 siblings, 0 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-05-06 15:58 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine, SZEDER Gábor,
	Andreas Schwab

On 2021-04-23 09:21:10+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> Convert the setup of the describe tests to use test_commit when
> possible. This makes use of the new --annotated-tag option to

s/--annotated-tag/--annotate/

Otherwise, looks correct.

> test_commit.
> 
> Some of the setup here could simply be removed since the data being
> created wasn't important to any of the subsequent tests, so I've done
> so. E.g. assigning to the "one" variable was always useless, and just
> checking that we can describe HEAD after the first commit wasn't
> useful.
> 
> In the case of the "two" variable we could instead use the tag we just
> created. See 5312ab11fbf (Add describe test., 2007-01-13) for the
> initial version of this code. There's other cases here like redundant
> "test_tick" invocations, or the simplification of not echoing "X" to a
> file we're about to tag as "x", now we just use "x" in both cases.
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

-- 
Danh

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v5 07/11] test-lib functions: add --printf option to test_commit
  2021-04-23  7:21         ` [PATCH v5 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-05-06 16:08           ` Đoàn Trần Công Danh
  0 siblings, 0 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-05-06 16:08 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine, SZEDER Gábor,
	Andreas Schwab

On 2021-04-23 09:21:11+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 827c8502b10..701518f5fd3 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -173,6 +173,10 @@ debug () {
>  #	Do not call test_tick before making a commit
>  #   --append
>  #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
> +#   --printf
> +#       Use "printf" instead of "echo" when writing "<contents>" to
> +#       "<file>". You will need to provide your own trailing "\n". You
> +#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).

This is the second appearance of "You" in this file, and it's the
first in the usage of test_commit
Perhaps:

	Trailing "\n" won't be added automatically. This option
	supports nothing but the FORMAT of printf(1),
	not even its ARGUMENT(s).

Or something along the line.

>  #   --signoff
>  #	Invoke "git commit" with --signoff
>  #   --author <author>

-- 
Danh

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-05-06 15:32         ` Ævar Arnfjörð Bjarmason
@ 2021-05-06 16:21           ` Đoàn Trần Công Danh
  0 siblings, 0 replies; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-05-06 16:21 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine, SZEDER Gábor,
	Andreas Schwab

On 2021-05-06 17:32:01+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> 
> On Fri, Apr 23 2021, Ævar Arnfjörð Bjarmason wrote:
> 
> > Changes since v4: Only a commit message change/re-wording per
> > <87v98e1oj7.fsf@evledraar.gmail.com>.
> 
> SZEDER, Eric, Đoàn et al: does this v5 look good to you? Junio's
> suggested in [1] that this needs some final review feedback before
> advancing to 'next'. If you could take a look that would be great!

I have some minor nit-picks here and there, I didn't look into 11/11.
Otherwise, I think the series is fine, now.

-- 
Danh

^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v6 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
                           ` (12 preceding siblings ...)
  2021-05-06 15:32         ` Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:18         ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
                             ` (11 more replies)
  13 siblings, 12 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:18 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Changes since v5 only trivial commit message / comment fixes suggested
by Đoàn Trần Công Danh. Thanks! Link to v5:
http://lore.kernel.org/git/cover-00.11-00000000000-20210423T072006Z-avarab@gmail.com

Ævar Arnfjörð Bjarmason (11):
  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/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             | 62 ++++++++++++++++++-----------
 t/test-lib.sh                       | 40 ++++++++++++-------
 14 files changed, 89 insertions(+), 119 deletions(-)

Range-diff against v5:
 1:  75667f98f3a !  1:  febf98e87a1 test-lib: bring $remove_trash out of retirement
    @@ Commit message
         case.
     
         We carry around the "$remove_trash" variable because if the directory
    -    is unexpectedly gone at test_done time we'll hit the error about it
    -    being unexpectedly gone added in df4c0d1a792 (test-lib: abort when
    -    can't remove trash directory, 2017-04-20).
    +    is unexpectedly gone at test_done time we'll still want to hit the
    +    "trash directory already removed" error, but not if we never created
    +    the trash directory. See df4c0d1a792 (test-lib: abort when can't
    +    remove trash directory, 2017-04-20) for the addition of that error.
     
         So let's partially revert 06478dab4c (test-lib: retire $remove_trash
         variable, 2017-04-23) and move the decision about whether to skip all
    @@ Commit message
         under --debug at the end of the test, 2017-04-24) for a bug we don't
         want to re-introduce.
     
    -    While I'm at it let's move the HOME assignment to just before
    +    While I'm at it, let's move the HOME assignment to just before
         test_create_repo, it could be lower, but it seems better to set it
         before calling anything in test-lib-functions.sh
     
 2:  55c9413f9cd =  2:  6f360e37e84 test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
 3:  361e34654e9 =  3:  c2a0140fcd9 test-lib-functions: reword "test_commit --append" docs
 4:  2db68a4ac7c =  4:  1a675a6cfe5 test-lib-functions: document test_commit --no-tag
 5:  4ceba3d404b =  5:  2e0d69209e9 test-lib functions: add an --annotated option to "test_commit"
 6:  589eaf7a078 !  6:  07e8b63596b describe tests: convert setup to use test_commit
    @@ Commit message
         describe tests: convert setup to use test_commit
     
         Convert the setup of the describe tests to use test_commit when
    -    possible. This makes use of the new --annotated-tag option to
    -    test_commit.
    +    possible. This makes use of the new --annotate option to test_commit.
     
         Some of the setup here could simply be removed since the data being
         created wasn't important to any of the subsequent tests, so I've done
 7:  a0fe0640148 !  7:  5aaeadf01ff test-lib functions: add --printf option to test_commit
    @@ t/test-lib-functions.sh: debug () {
      #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
     +#   --printf
     +#       Use "printf" instead of "echo" when writing "<contents>" to
    -+#       "<file>". You will need to provide your own trailing "\n". You
    -+#       can only supply the FORMAT for the printf(1), not its ARGUMENT(s).
    ++#       "<file>", use this to write escape sequences such as "\0", a
    ++#       trailing "\n" won't be added automatically. This option
    ++#       supports nothing but the FORMAT of printf(1), i.e. no custom
    ++#       ARGUMENT(s).
      #   --signoff
      #	Invoke "git commit" with --signoff
      #   --author <author>
 8:  7fb8849ce66 =  8:  0b31b1ffeff submodule tests: use symbolic-ref --short to discover branch name
 9:  f67245ba40d =  9:  c806f3888c5 test-lib: reformat argument list in test_create_repo()
10:  37338c88300 = 10:  105a95fb7a0 test-lib: do not show advice about init.defaultBranch under --verbose
11:  7793311e5f1 = 11:  217c5aed491 test-lib: split up and deprecate test_create_repo()
-- 
2.31.1.838.g924d365b763


^ permalink raw reply	[flat|nested] 175+ messages in thread

* [PATCH v6 01/11] test-lib: bring $remove_trash out of retirement
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
                             ` (10 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

There's no point in creating a repository or directory only to decide
right afterwards that we're skipping all the tests. We can save
ourselves the redundant "git init" or "mkdir" and "rm -rf" in this
case.

We carry around the "$remove_trash" variable because if the directory
is unexpectedly gone at test_done time we'll still want to hit the
"trash directory already removed" error, but not if we never created
the trash directory. See df4c0d1a792 (test-lib: abort when can't
remove trash directory, 2017-04-20) for the addition of that error.

So let's partially revert 06478dab4c (test-lib: retire $remove_trash
variable, 2017-04-23) and move the decision about whether to skip all
tests earlier.

Let's also fix a bug that was with us since abc5d372ec (Enable
parallel tests, 2008-08-08): we would leak $remove_trash from the
environment. We don't want this to error out, so let's reset it to the
empty string first:

     remove_trash=t GIT_SKIP_TESTS=t0001 ./t0001-init.sh

I tested this with --debug, see 4d0912a206 (test-lib.sh: do not barf
under --debug at the end of the test, 2017-04-24) for a bug we don't
want to re-introduce.

While I'm at it, let's move the HOME assignment to just before
test_create_repo, it could be lower, but it seems better to set it
before calling anything in test-lib-functions.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib.sh | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index adaa2db6014..7647afcfd0a 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1169,7 +1169,7 @@ test_done () {
 			esac
 		fi
 
-		if test -z "$debug"
+		if test -z "$debug" && test -n "$remove_trash"
 		then
 			test -d "$TRASH_DIRECTORY" ||
 			error "Tests passed but trash directory already removed before test cleanup; aborting"
@@ -1334,6 +1334,22 @@ then
 	exit 1
 fi
 
+# Are we running this test at all?
+remove_trash=
+this_test=${0##*/}
+this_test=${this_test%%-*}
+if match_pattern_list "$this_test" $GIT_SKIP_TESTS
+then
+	say_color info >&3 "skipping test $this_test altogether"
+	skip_all="skip all tests in $this_test"
+	test_done
+fi
+
+# Last-minute variable setup
+HOME="$TRASH_DIRECTORY"
+GNUPGHOME="$HOME/gnupg-home-not-used"
+export HOME GNUPGHOME
+
 # Test repository
 rm -fr "$TRASH_DIRECTORY" || {
 	GIT_EXIT_OK=t
@@ -1341,10 +1357,7 @@ rm -fr "$TRASH_DIRECTORY" || {
 	exit 1
 }
 
-HOME="$TRASH_DIRECTORY"
-GNUPGHOME="$HOME/gnupg-home-not-used"
-export HOME GNUPGHOME
-
+remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
 	test_create_repo "$TRASH_DIRECTORY"
@@ -1356,15 +1369,6 @@ fi
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
 
-this_test=${0##*/}
-this_test=${this_test%%-*}
-if match_pattern_list "$this_test" $GIT_SKIP_TESTS
-then
-	say_color info >&3 "skipping test $this_test altogether"
-	skip_all="skip all tests in $this_test"
-	test_done
-fi
-
 if test -n "$write_junit_xml"
 then
 	junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
                             ` (9 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Stop setting the GIT_TEST_FRAMEWORK_SELFTEST variable. This was originally needed
back in 4231d1ba99 (t0000: do not get self-test disrupted by
environment warnings, 2018-09-20).

It hasn't been needed since I deleted the relevant code in test-lib.sh
in c0eedbc009 (test-lib: remove check_var_migration, 2021-02-09), I
just didn't notice that it was set here.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t0000-basic.sh | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index 705d62cc27a..2c6e34b9478 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -84,10 +84,6 @@ _run_sub_test_lib_test_common () {
 		passing metrics
 		'
 
-		# Tell the framework that we are self-testing to make sure
-		# it yields a stable result.
-		GIT_TEST_FRAMEWORK_SELFTEST=t &&
-
 		# Point to the t/test-lib.sh, which isn't in ../ as usual
 		. "\$TEST_DIRECTORY"/test-lib.sh
 		EOF
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 03/11] test-lib-functions: reword "test_commit --append" docs
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
                             ` (8 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Reword the documentation for "test_commit --append" added in my
3373518cc8 (test-lib functions: add an --append option to test_commit,
2021-01-12).

A follow-up commit will make the "echo" part of this configurable, and
in any case saying "echo >>" rather than ">>" was redundant.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b823c140271..1f787ff0726 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -172,8 +172,7 @@ debug () {
 #   --notick
 #	Do not call test_tick before making a commit
 #   --append
-#	Use "echo >>" instead of "echo >" when writing "<contents>" to
-#	"<file>"
+#	Use ">>" instead of ">" when writing "<contents>" to "<file>"
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 04/11] test-lib-functions: document test_commit --no-tag
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (2 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
                             ` (7 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

In 76b8b8d05c (test-lib functions: document arguments to test_commit,
2021-01-12) I added missing documentation to test_commit, but in less
than a month later in 3803a3a099 (t: add --no-tag option to
test_commit, 2021-02-09) we got another undocumented option. Let's fix
that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 1f787ff0726..c6d07f4ce32 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -177,6 +177,8 @@ debug () {
 #	Invoke "git commit" with --signoff
 #   --author <author>
 #	Invoke "git commit" with --author <author>
+#   --no-tag
+#	Do not tag the resulting commit
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 05/11] test-lib functions: add an --annotated option to "test_commit"
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (3 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
                             ` (6 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Add an --annotated option to test_commit to create annotated tags. The
tag will share the same message as the commit, and we'll call
test_tick before creating it (unless --notick) is provided.

There's quite a few tests that could be simplified with this
construct. I've picked one to convert in this change as a
demonstration.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1403-show-ref.sh     |  6 ++----
 t/test-lib-functions.sh | 27 ++++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 6ce62f878c3..17d3cc14050 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
-	git tag -f -a -m "annotated A" A &&
+	test_commit --annotate A &&
 	git checkout -b side &&
-	test_commit B &&
-	git tag -f -a -m "annotated B" B &&
+	test_commit --annotate B &&
 	git checkout main &&
 	test_commit C &&
 	git branch B A^0
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index c6d07f4ce32..827c8502b10 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -179,6 +179,10 @@ debug () {
 #	Invoke "git commit" with --author <author>
 #   --no-tag
 #	Do not tag the resulting commit
+#   --annotate
+#	Create an annotated tag with "--annotate -m <message>". Calls
+#	test_tick between making the commit and tag, unless --notick
+#	is given.
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
@@ -191,7 +195,7 @@ test_commit () {
 	author= &&
 	signoff= &&
 	indir= &&
-	no_tag= &&
+	tag=light &&
 	while test $# != 0
 	do
 		case "$1" in
@@ -219,7 +223,10 @@ test_commit () {
 			shift
 			;;
 		--no-tag)
-			no_tag=yes
+			tag=none
+			;;
+		--annotate)
+			tag=annotate
 			;;
 		*)
 			break
@@ -243,10 +250,20 @@ test_commit () {
 	git ${indir:+ -C "$indir"} commit \
 	    ${author:+ --author "$author"} \
 	    $signoff -m "$1" &&
-	if test -z "$no_tag"
-	then
+	case "$tag" in
+	none)
+		;;
+	light)
 		git ${indir:+ -C "$indir"} tag "${4:-$1}"
-	fi
+		;;
+	annotate)
+		if test -z "$notick"
+		then
+			test_tick
+		fi &&
+		git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
+		;;
+	esac
 }
 
 # Call test_merge with the arguments "<message> <commit>", where <commit>
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 06/11] describe tests: convert setup to use test_commit
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (4 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
                             ` (5 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Convert the setup of the describe tests to use test_commit when
possible. This makes use of the new --annotate option to test_commit.

Some of the setup here could simply be removed since the data being
created wasn't important to any of the subsequent tests, so I've done
so. E.g. assigning to the "one" variable was always useless, and just
checking that we can describe HEAD after the first commit wasn't
useful.

In the case of the "two" variable we could instead use the tag we just
created. See 5312ab11fbf (Add describe test., 2007-01-13) for the
initial version of this code. There's other cases here like redundant
"test_tick" invocations, or the simplification of not echoing "X" to a
file we're about to tag as "x", now we just use "x" in both cases.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6120-describe.sh | 58 ++++++++++-----------------------------------
 1 file changed, 13 insertions(+), 45 deletions(-)

diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh
index e89b6747bee..88fddc91424 100755
--- a/t/t6120-describe.sh
+++ b/t/t6120-describe.sh
@@ -31,64 +31,32 @@ check_describe () {
 }
 
 test_expect_success setup '
+	test_commit initial file one &&
+	test_commit second file two &&
+	test_commit third file three &&
+	test_commit --annotate A file A &&
+	test_commit c file c &&
 
-	test_tick &&
-	echo one >file && git add file && git commit -m initial &&
-	one=$(git rev-parse HEAD) &&
-
-	git describe --always HEAD &&
-
-	test_tick &&
-	echo two >file && git add file && git commit -m second &&
-	two=$(git rev-parse HEAD) &&
-
-	test_tick &&
-	echo three >file && git add file && git commit -m third &&
-
-	test_tick &&
-	echo A >file && git add file && git commit -m A &&
-	test_tick &&
-	git tag -a -m A A &&
-
-	test_tick &&
-	echo c >file && git add file && git commit -m c &&
-	test_tick &&
-	git tag c &&
-
-	git reset --hard $two &&
-	test_tick &&
-	echo B >side && git add side && git commit -m B &&
-	test_tick &&
-	git tag -a -m B B &&
+	git reset --hard second &&
+	test_commit --annotate B side B &&
 
 	test_tick &&
 	git merge -m Merged c &&
 	merged=$(git rev-parse HEAD) &&
 
-	git reset --hard $two &&
-	test_tick &&
-	echo D >another && git add another && git commit -m D &&
-	test_tick &&
-	git tag -a -m D D &&
-	test_tick &&
-	git tag -a -m R R &&
-
-	test_tick &&
-	echo DD >another && git commit -a -m another &&
+	git reset --hard second &&
+	test_commit --no-tag D another D &&
 
 	test_tick &&
-	git tag e &&
+	git tag -a -m R R &&
 
-	test_tick &&
-	echo DDD >another && git commit -a -m "yet another" &&
+	test_commit e another DD &&
+	test_commit --no-tag "yet another" another DDD &&
 
 	test_tick &&
 	git merge -m Merged $merged &&
 
-	test_tick &&
-	echo X >file && echo X >side && git add file side &&
-	git commit -m x
-
+	test_commit --no-tag x file
 '
 
 check_describe A-* HEAD
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 07/11] test-lib functions: add --printf option to test_commit
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (5 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
                             ` (4 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Add a --printf option to test_commit to allow writing to the file with
"printf" instead of "echo".

This is useful for writing "\n", "\0" etc., in particular in
combination with the --append option added in 3373518cc8 (test-lib
functions: add an --append option to test_commit, 2021-01-12).

I'm converting a few tests to use the new option rather than a manual
printf/add/commit combination to demonstrate its usefulness. While I'm
at it use "test_create_repo" where appropriate, and give the
first/second commit a meaningful/more conventional log message in
cases where no test cared about that message.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1307-config-blob.sh    |  4 +---
 t/t2030-unresolve-info.sh |  3 +--
 t/t4006-diff-mode.sh      |  6 ++----
 t/t4030-diff-textconv.sh  |  8 ++------
 t/t5520-pull.sh           | 10 ++--------
 t/test-lib-functions.sh   | 14 ++++++++++++--
 6 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 002e6d3388e..930dce06f0f 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
 '
 
 test_expect_success 'can parse blob ending with CR' '
-	printf "[some]key = value\\r" >config &&
-	git add config &&
-	git commit -m CR &&
+	test_commit --printf CR config "[some]key = value\\r" &&
 	echo value >expect &&
 	git config --blob=HEAD:config some.key >actual &&
 	test_cmp expect actual
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index be6c84c52a2..f691e6d9032 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
 
 test_expect_success 'rerere forget (binary)' '
 	git checkout -f side &&
-	printf "a\0c" >binary &&
-	git commit -a -m binary &&
+	test_commit --printf binary binary "a\0c" &&
 	test_must_fail git merge second &&
 	git rerere forget binary
 '
diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh
index 275ce5fa15b..6cdee2a2164 100755
--- a/t/t4006-diff-mode.sh
+++ b/t/t4006-diff-mode.sh
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
 '
 
 test_expect_success 'prepare binary file' '
-	git commit -m rezrov &&
-	printf "\00\01\02\03\04\05\06" >binbin &&
-	git add binbin &&
-	git commit -m binbin
+	git commit -m one &&
+	test_commit --printf two binbin "\00\01\02\03\04\05\06"
 '
 
 test_expect_success '--stat output after text chmod' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index c906320b60d..a39a626664d 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -26,12 +26,8 @@ EOF
 chmod +x hexdump
 
 test_expect_success 'setup binary file with history' '
-	printf "\\0\\n" >file &&
-	git add file &&
-	git commit -m one &&
-	printf "\\01\\n" >>file &&
-	git add file &&
-	git commit -m two
+	test_commit --printf one file "\\0\\n" &&
+	test_commit --printf --append two file "\\01\\n"
 '
 
 test_expect_success 'file is considered binary by porcelain' '
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a09411327f9..e2c0c510222 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
 '
 
 test_expect_success 'setup for detecting upstreamed changes' '
-	mkdir src &&
-	(
-		cd src &&
-		git init &&
-		printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
-		git add stuff &&
-		git commit -m "Initial revision"
-	) &&
+	test_create_repo src &&
+	test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
 	git clone src dst &&
 	(
 		cd src &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 827c8502b10..b242ecf5cd2 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -173,6 +173,12 @@ debug () {
 #	Do not call test_tick before making a commit
 #   --append
 #	Use ">>" instead of ">" when writing "<contents>" to "<file>"
+#   --printf
+#       Use "printf" instead of "echo" when writing "<contents>" to
+#       "<file>", use this to write escape sequences such as "\0", a
+#       trailing "\n" won't be added automatically. This option
+#       supports nothing but the FORMAT of printf(1), i.e. no custom
+#       ARGUMENT(s).
 #   --signoff
 #	Invoke "git commit" with --signoff
 #   --author <author>
@@ -191,6 +197,7 @@ debug () {
 
 test_commit () {
 	notick= &&
+	echo=echo &&
 	append= &&
 	author= &&
 	signoff= &&
@@ -202,6 +209,9 @@ test_commit () {
 		--notick)
 			notick=yes
 			;;
+		--printf)
+			echo=printf
+			;;
 		--append)
 			append=yes
 			;;
@@ -238,9 +248,9 @@ test_commit () {
 	file=${2:-"$1.t"} &&
 	if test -n "$append"
 	then
-		echo "${3-$1}" >>"$indir$file"
+		$echo "${3-$1}" >>"$indir$file"
 	else
-		echo "${3-$1}" >"$indir$file"
+		$echo "${3-$1}" >"$indir$file"
 	fi &&
 	git ${indir:+ -C "$indir"} add "$file" &&
 	if test -z "$notick"
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 08/11] submodule tests: use symbolic-ref --short to discover branch name
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (6 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
                             ` (3 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Change a use of $GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME added in
704fed9ea22 (tests: start moving to a different default main branch
name, 2020-10-23) to simply discover the initial branch name of a
repository set up in this function with "symbolic-ref --short".

That's something done in another test in 704fed9ea22, so doing it like
this seems like an omission, or rather an overly eager
search/replacement instead of fixing the test logic.

There are only three uses of the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
variable in the test suite, this gets rid of one of those.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/lib-submodule-update.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 4b714e93083..f7c7df0ca42 100644
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -63,6 +63,7 @@ create_lib_submodule_repo () {
 	git init submodule_update_repo &&
 	(
 		cd submodule_update_repo &&
+		branch=$(git symbolic-ref --short HEAD) &&
 		echo "expect" >>.gitignore &&
 		echo "actual" >>.gitignore &&
 		echo "x" >file1 &&
@@ -144,7 +145,7 @@ create_lib_submodule_repo () {
 		git checkout -b valid_sub1 &&
 		git revert HEAD &&
 
-		git checkout "${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}"
+		git checkout "$branch"
 	)
 }
 
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 09/11] test-lib: reformat argument list in test_create_repo()
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (7 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
                             ` (2 subsequent siblings)
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Reformat an argument list changed in 675704c74dd (init: provide useful
advice about init.defaultBranch, 2020-12-11) to have the "-c" on the
same line as the argument it sets. This whitespace-only change makes
it easier to review a subsequent commit.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b242ecf5cd2..661597e9192 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1252,8 +1252,8 @@ test_create_repo () {
 	mkdir -p "$repo"
 	(
 		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" -c \
-			init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
+		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
+			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 10/11] test-lib: do not show advice about init.defaultBranch under --verbose
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (8 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-10 14:19           ` [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
  2021-05-12 12:19           ` [PATCH v6 00/11] test-lib.sh: new test_commit args, simplification & fixes Đoàn Trần Công Danh
  11 siblings, 0 replies; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Arrange for the advice about naming the initial branch not to be shown
in the --verbose output of the test suite.

Since 675704c74dd (init: provide useful advice about
init.defaultBranch, 2020-12-11) some tests have been very chatty with
repeated occurrences of this multi-line advice. Having it be this
verbose isn't helpful for anyone in the context of git's own test
suite, and it makes debugging tests that use their own "git init"
invocations needlessly distracting.

By setting the GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME variable early in
test-lib.sh itself we'll squash the warning not only for
test_create_repo(), as 675704c74dd explicitly intended, but also for
other "git init" invocations.

And once we'd like to have this configuration set for all "git init"
invocations in the test suite we can get rid of the init.defaultBranch
configuration setting in test_create_repo(), as
repo_default_branch_name() in refs.c will take the GIT_TEST_* variable
over it being set.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/test-lib-functions.sh | 1 -
 t/test-lib.sh           | 5 +++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 661597e9192..669645a812f 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1253,7 +1253,6 @@ test_create_repo () {
 	(
 		cd "$repo" || error "Cannot setup test environment"
 		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			-c init.defaultBranch="${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME-master}" \
 			init \
 			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
 		error "cannot run git init -- have you built things yet?"
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7647afcfd0a..f3671b1766d 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -64,6 +64,11 @@ then
 	export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
 fi
 
+# Explicitly set the default branch name for testing, to avoid the
+# transitory "git init" warning under --verbose.
+: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
 ################################################################
 # It appears that people try to run tests without building...
 "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo()
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (9 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
@ 2021-05-10 14:19           ` Ævar Arnfjörð Bjarmason
  2021-05-13  6:45             ` Felipe Contreras
  2021-05-12 12:19           ` [PATCH v6 00/11] test-lib.sh: new test_commit args, simplification & fixes Đoàn Trần Công Danh
  11 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-10 14:19 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

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.

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.

 2. Since we're now a simple wrapper for "git init" we don't need to
    check that we have only one argument. If someone wants to run
    "test_create_repo --bare x" that's OK.

 3. We won't ever hit that "Cannot setup test environment"
    error.

    Checking the test environment sanity when doing "git init" dates
    back to eea420693be (t0000: catch trivial pilot errors.,
    2005-12-10) and 2ccd2027b01 (trivial: check, if t/trash directory
    was successfully created, 2006-01-05).

    We can also see it in another form a bit later in my own
    0d314ce834d (test-lib: use subshell instead of cd $new && .. && cd
    $old, 2010-08-30).

    But since 2006f0adaee (t/test-lib: make sure Git has already been
    built, 2012-09-17) we already check if we have a built git
    earlier.

    The one thing this was testing after that 2012 change was that
    we'd just built "git", but not "git-init", but since
    3af4c7156c4 (tests: respect GIT_TEST_INSTALLED when initializing
    repositories, 2018-11-12) we invoke "git", not "git-init".

    So all of that's been checked already, and we don't need to
    re-check it here.

 4. We don't need to move .git/hooks out of the way.

    That dates back to c09a69a83e3 (Disable hooks during tests.,
    2005-10-16), since then hooks became disabled by default in
    f98f8cbac01 (Ship sample hooks with .sample suffix, 2008-06-24).

    So the hooks were already disabled by default, but as can be seen
    from "mkdir .git/hooks" changes various tests needed to re-setup
    that directory. Now they no longer do.

    This makes us implicitly depend on the default hooks being
    disabled, which is a good thing. If and when we'd have any
    on-by-default hooks (I see no reason we ever would) we'd want to
    see the subtle and not so subtle ways that would break the test
    suite.

 5. We don't need to "cd" to the "$repo" directory at all anymore.

    In the code being removed here we both "cd"'d to the repository
    before calling "init", and did so in a subshell.

    It's not important to do either, so both of those can be
    removed. We cd'd because this code grew from test-lib.sh code
    where we'd have done so already, see eedf8f97e58 (Abstract
    test_create_repo out for use in tests., 2006-02-17), and later
    "cd"'d inside a subshell since 0d314ce834d to avoid having to keep
    track of an "old pwd" variable to cd back after the setup.

    Being in the repository directory made moving the hooks around
    easier (we wouldn't have to fully qualify the path). Since we're
    not moving the hooks per #4 above we don't need to "cd" for that
    reason either.

 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.

    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.

 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

    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/t5406-remote-rejects.sh           |  1 -
 t/t5407-post-rewrite-hook.sh        |  2 --
 t/t5409-colorize-remote-messages.sh |  1 -
 t/test-lib-functions.sh             | 15 ++-------------
 t/test-lib.sh                       |  3 ++-
 5 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/t/t5406-remote-rejects.sh b/t/t5406-remote-rejects.sh
index ff06f99649e..5c509db6fc3 100755
--- a/t/t5406-remote-rejects.sh
+++ b/t/t5406-remote-rejects.sh
@@ -5,7 +5,6 @@ test_description='remote push rejects are reported by client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	exit 1
 	EOF
diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh
index 5bb23cc3a4e..6da8d760e28 100755
--- a/t/t5407-post-rewrite-hook.sh
+++ b/t/t5407-post-rewrite-hook.sh
@@ -20,8 +20,6 @@ test_expect_success 'setup' '
 	git checkout main
 '
 
-mkdir .git/hooks
-
 cat >.git/hooks/post-rewrite <<EOF
 #!/bin/sh
 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
diff --git a/t/t5409-colorize-remote-messages.sh b/t/t5409-colorize-remote-messages.sh
index 5d8f401d8ec..9f1a483f426 100755
--- a/t/t5409-colorize-remote-messages.sh
+++ b/t/t5409-colorize-remote-messages.sh
@@ -5,7 +5,6 @@ test_description='remote messages are colorized on the client'
 . ./test-lib.sh
 
 test_expect_success 'setup' '
-	mkdir .git/hooks &&
 	write_script .git/hooks/update <<-\EOF &&
 	echo error: error
 	echo ERROR: also highlighted
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 669645a812f..f0448daa74b 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1243,21 +1243,10 @@ test_atexit () {
 		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
 }
 
-# Most tests can use the created repository, but some may need to create more.
+# Deprecated wrapper for "git init", use "git init" directly instead
 # Usage: test_create_repo <directory>
 test_create_repo () {
-	test "$#" = 1 ||
-	BUG "not 1 parameter to test-create-repo"
-	repo="$1"
-	mkdir -p "$repo"
-	(
-		cd "$repo" || error "Cannot setup test environment"
-		"${GIT_TEST_INSTALLED:-$GIT_EXEC_PATH}/git$X" \
-			init \
-			"--template=$GIT_BUILD_DIR/templates/blt/" >&3 2>&4 ||
-		error "cannot run git init -- have you built things yet?"
-		mv .git/hooks .git/hooks-disabled
-	) || exit
+	git init "$@"
 }
 
 # This function helps on symlink challenged file systems when it is not
diff --git a/t/test-lib.sh b/t/test-lib.sh
index f3671b1766d..e6ca7a22826 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1365,7 +1365,8 @@ rm -fr "$TRASH_DIRECTORY" || {
 remove_trash=t
 if test -z "$TEST_NO_CREATE_REPO"
 then
-	test_create_repo "$TRASH_DIRECTORY"
+	git init "$TRASH_DIRECTORY" >&3 2>&4 ||
+	error "cannot run git init"
 else
 	mkdir -p "$TRASH_DIRECTORY"
 fi
-- 
2.31.1.838.g924d365b763


^ permalink raw reply related	[flat|nested] 175+ messages in thread

* Re: [PATCH v6 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
                             ` (10 preceding siblings ...)
  2021-05-10 14:19           ` [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-05-12 12:19           ` Đoàn Trần Công Danh
  2021-05-12 23:24             ` Junio C Hamano
  11 siblings, 1 reply; 175+ messages in thread
From: Đoàn Trần Công Danh @ 2021-05-12 12:19 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine, SZEDER Gábor,
	Andreas Schwab

On 2021-05-10 16:18:59+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> Changes since v5 only trivial commit message / comment fixes suggested
> by Đoàn Trần Công Danh. Thanks! Link to v5:
> http://lore.kernel.org/git/cover-00.11-00000000000-20210423T072006Z-avarab@gmail.com

I skimmed over this series and I think it's in a good shape now.
So, FWIW.

Acked-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>

-- 
Danh

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v6 00/11] test-lib.sh: new test_commit args, simplification & fixes
  2021-05-12 12:19           ` [PATCH v6 00/11] test-lib.sh: new test_commit args, simplification & fixes Đoàn Trần Công Danh
@ 2021-05-12 23:24             ` Junio C Hamano
  0 siblings, 0 replies; 175+ messages in thread
From: Junio C Hamano @ 2021-05-12 23:24 UTC (permalink / raw)
  To: Đoàn Trần Công Danh
  Cc: Ævar Arnfjörð Bjarmason, git, Jeff King,
	Matthieu Moy, Johannes Schindelin, Eric Sunshine,
	SZEDER Gábor, Andreas Schwab

Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:

> On 2021-05-10 16:18:59+0200, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> Changes since v5 only trivial commit message / comment fixes suggested
>> by Đoàn Trần Công Danh. Thanks! Link to v5:
>> http://lore.kernel.org/git/cover-00.11-00000000000-20210423T072006Z-avarab@gmail.com
>
> I skimmed over this series and I think it's in a good shape now.
> So, FWIW.
>
> Acked-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>

Thanks.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* RE: [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo()
  2021-05-10 14:19           ` [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
@ 2021-05-13  6:45             ` Felipe Contreras
  2021-05-13  7:45               ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: Felipe Contreras @ 2021-05-13  6:45 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason, git
  Cc: Junio C Hamano, Jeff King, Matthieu Moy, Johannes Schindelin,
	Eric Sunshine, Đoàn Trần Công Danh,
	SZEDER Gábor, Andreas Schwab,
	Ævar Arnfjörð Bjarmason

Ævar Arnfjörð Bjarmason wrote:
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1243,21 +1243,10 @@ test_atexit () {
>  		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
>  }
>  
> -# Most tests can use the created repository, but some may need to create more.
> +# Deprecated wrapper for "git init", use "git init" directly instead
>  # Usage: test_create_repo <directory>
>  test_create_repo () {

If this is deprecated why not add a warning?

  echo "warning: test_create_repo is deprecated in favor of git init" >&2

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo()
  2021-05-13  6:45             ` Felipe Contreras
@ 2021-05-13  7:45               ` Ævar Arnfjörð Bjarmason
  2021-05-13  8:23                 ` Felipe Contreras
  0 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-13  7:45 UTC (permalink / raw)
  To: Felipe Contreras
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab


On Thu, May 13 2021, Felipe Contreras wrote:

> Ævar Arnfjörð Bjarmason wrote:
>> --- a/t/test-lib-functions.sh
>> +++ b/t/test-lib-functions.sh
>> @@ -1243,21 +1243,10 @@ test_atexit () {
>>  		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
>>  }
>>  
>> -# Most tests can use the created repository, but some may need to create more.
>> +# Deprecated wrapper for "git init", use "git init" directly instead
>>  # Usage: test_create_repo <directory>
>>  test_create_repo () {
>
> If this is deprecated why not add a warning?
>
>   echo "warning: test_create_repo is deprecated in favor of git init" >&2

Because like test_i18ncmp, test_i18ngrep or whatever this is in the
state of "don't use this for new code", but annoying everyone who runs
the test suite with loads of this output under -v would be too
distracting.

The attention of the developer community is much better spent on one
person doing a s/test_create_repo/git init/ patch than having everyone
see this warning until somebody does that.

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo()
  2021-05-13  7:45               ` Ævar Arnfjörð Bjarmason
@ 2021-05-13  8:23                 ` Felipe Contreras
  2021-05-13 12:05                   ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 175+ messages in thread
From: Felipe Contreras @ 2021-05-13  8:23 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason, Felipe Contreras
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab

Ævar Arnfjörð Bjarmason wrote:
> 
> On Thu, May 13 2021, Felipe Contreras wrote:
> 
> > Ævar Arnfjörð Bjarmason wrote:
> >> --- a/t/test-lib-functions.sh
> >> +++ b/t/test-lib-functions.sh
> >> @@ -1243,21 +1243,10 @@ test_atexit () {
> >>  		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
> >>  }
> >>  
> >> -# Most tests can use the created repository, but some may need to create more.
> >> +# Deprecated wrapper for "git init", use "git init" directly instead
> >>  # Usage: test_create_repo <directory>
> >>  test_create_repo () {
> >
> > If this is deprecated why not add a warning?
> >
> >   echo "warning: test_create_repo is deprecated in favor of git init" >&2
> 
> Because like test_i18ncmp, test_i18ngrep or whatever this is in the
> state of "don't use this for new code", but annoying everyone who runs
> the test suite with loads of this output under -v would be too
> distracting.
> 
> The attention of the developer community is much better spent on one
> person doing a s/test_create_repo/git init/ patch than having everyone
> see this warning until somebody does that.

Then it's not really deprecated; it's merely disfavored.

To deprecate means to express disapproval of. If we are not going to
express disapproval (i.e. annoy the users of the test suite), then it's
not really deprecated. You can't eat your cake and have it too.

I agree we shouldn't throw a warning right now, but at some point in the
future we should, *then* it will be deprecated.

Cheers.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo()
  2021-05-13  8:23                 ` Felipe Contreras
@ 2021-05-13 12:05                   ` Ævar Arnfjörð Bjarmason
  2021-05-13 20:11                     ` Felipe Contreras
  0 siblings, 1 reply; 175+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-05-13 12:05 UTC (permalink / raw)
  To: Felipe Contreras
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab


On Thu, May 13 2021, Felipe Contreras wrote:

> Ævar Arnfjörð Bjarmason wrote:
>> 
>> On Thu, May 13 2021, Felipe Contreras wrote:
>> 
>> > Ævar Arnfjörð Bjarmason wrote:
>> >> --- a/t/test-lib-functions.sh
>> >> +++ b/t/test-lib-functions.sh
>> >> @@ -1243,21 +1243,10 @@ test_atexit () {
>> >>  		} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_atexit_cleanup"
>> >>  }
>> >>  
>> >> -# Most tests can use the created repository, but some may need to create more.
>> >> +# Deprecated wrapper for "git init", use "git init" directly instead
>> >>  # Usage: test_create_repo <directory>
>> >>  test_create_repo () {
>> >
>> > If this is deprecated why not add a warning?
>> >
>> >   echo "warning: test_create_repo is deprecated in favor of git init" >&2
>> 
>> Because like test_i18ncmp, test_i18ngrep or whatever this is in the
>> state of "don't use this for new code", but annoying everyone who runs
>> the test suite with loads of this output under -v would be too
>> distracting.
>> 
>> The attention of the developer community is much better spent on one
>> person doing a s/test_create_repo/git init/ patch than having everyone
>> see this warning until somebody does that.
>
> Then it's not really deprecated; it's merely disfavored.
>
> To deprecate means to express disapproval of. If we are not going to
> express disapproval (i.e. annoy the users of the test suite), then it's
> not really deprecated. You can't eat your cake and have it too.
>
> I agree we shouldn't throw a warning right now, but at some point in the
> future we should, *then* it will be deprecated.

I don't feel strongly about either term, as long as it's consistent.

I do think that "deprecated" is consistent in the way I'm using it
within the git project. If you grep various things we've "deprecated" we
usually just do so by noting so in the docs. In this case the docs are
the comments in test-lib.sh.

We do also have things like git rebase --preserve-merges which emit a
warning, but we use "deprecated" for both. By contrast we don't have a
single git for "git grep -i disfavor".

Anyway, for now I'd prefer to just have this land as-is and sort out
such minor things later, given the v6 and having two other topics
waiting on this...

^ permalink raw reply	[flat|nested] 175+ messages in thread

* Re: [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo()
  2021-05-13 12:05                   ` Ævar Arnfjörð Bjarmason
@ 2021-05-13 20:11                     ` Felipe Contreras
  0 siblings, 0 replies; 175+ messages in thread
From: Felipe Contreras @ 2021-05-13 20:11 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason, Felipe Contreras
  Cc: git, Junio C Hamano, Jeff King, Matthieu Moy,
	Johannes Schindelin, Eric Sunshine,
	Đoàn Trần Công Danh, SZEDER Gábor,
	Andreas Schwab

Ævar Arnfjörð Bjarmason wrote:
> On Thu, May 13 2021, Felipe Contreras wrote:

> > Then it's not really deprecated; it's merely disfavored.
> >
> > To deprecate means to express disapproval of. If we are not going to
> > express disapproval (i.e. annoy the users of the test suite), then it's
> > not really deprecated. You can't eat your cake and have it too.
> >
> > I agree we shouldn't throw a warning right now, but at some point in the
> > future we should, *then* it will be deprecated.
> 
> I don't feel strongly about either term, as long as it's consistent.
> 
> I do think that "deprecated" is consistent in the way I'm using it
> within the git project. If you grep various things we've "deprecated" we
> usually just do so by noting so in the docs. In this case the docs are
> the comments in test-lib.sh.
> 
> We do also have things like git rebase --preserve-merges which emit a
> warning, but we use "deprecated" for both. By contrast we don't have a
> single git for "git grep -i disfavor".
> 
> Anyway, for now I'd prefer to just have this land as-is and sort out
> such minor things later, given the v6 and having two other topics
> waiting on this...

Fair enough.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 175+ messages in thread

end of thread, other threads:[~2021-05-13 20:11 UTC | newest]

Thread overview: 175+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12 11:08 [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
2021-04-12 11:08 ` [PATCH 01/16] check-non-portable-shell: complain about "test" a/-o instead of &&/|| Ævar Arnfjörð Bjarmason
2021-04-12 17:00   ` Eric Sunshine
2021-04-12 17:13     ` Matthieu Moy
2021-04-12 18:36       ` Junio C Hamano
2021-04-12 18:38     ` Junio C Hamano
2021-04-12 18:48       ` Eric Sunshine
2021-04-12 11:08 ` [PATCH 02/16] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
2021-04-12 19:06   ` Junio C Hamano
2021-04-12 21:22     ` Junio C Hamano
2021-04-12 11:08 ` [PATCH 03/16] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
2021-04-12 11:08 ` [PATCH 04/16] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
2021-04-12 11:08 ` [PATCH 05/16] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
2021-04-12 17:07   ` Eric Sunshine
2021-04-12 11:08 ` [PATCH 06/16] test-lib functions: add an --annotated-tag option to "test_commit" Ævar Arnfjörð Bjarmason
2021-04-15 15:33   ` Đoàn Trần Công Danh
2021-04-12 11:08 ` [PATCH 07/16] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
2021-04-12 11:08 ` [PATCH 08/16] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
2021-04-12 19:05   ` Eric Sunshine
2021-04-12 21:27     ` Junio C Hamano
2021-04-12 23:04       ` Eric Sunshine
2021-04-12 23:12         ` Junio C Hamano
2021-04-15 11:33           ` Ævar Arnfjörð Bjarmason
2021-04-15 14:52             ` Eric Sunshine
2021-04-15 18:37               ` Junio C Hamano
2021-04-12 11:08 ` [PATCH 09/16] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
2021-04-12 11:08 ` [PATCH 10/16] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-12 11:09 ` [PATCH 11/16] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
2021-04-15 19:07   ` SZEDER Gábor
2021-04-12 11:09 ` [PATCH 12/16] test-lib: modernize test_create_repo() function Ævar Arnfjörð Bjarmason
2021-04-12 19:27   ` Junio C Hamano
2021-04-15 11:40     ` Ævar Arnfjörð Bjarmason
2021-04-15 21:10   ` SZEDER Gábor
2021-04-16 21:22     ` SZEDER Gábor
2021-04-16 23:38     ` Ævar Arnfjörð Bjarmason
2021-04-12 11:09 ` [PATCH 13/16] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
2021-04-12 11:09 ` [PATCH 14/16] test-lib-functions: use "return 1" instead of "false" Ævar Arnfjörð Bjarmason
2021-04-12 19:31   ` Junio C Hamano
2021-04-12 11:09 ` [PATCH 15/16] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
2021-04-12 19:37   ` Junio C Hamano
2021-04-15 11:32     ` Ævar Arnfjörð Bjarmason
2021-04-15 12:31       ` Andreas Schwab
2021-04-15 18:35       ` Junio C Hamano
2021-04-16 21:06         ` Ævar Arnfjörð Bjarmason
2021-04-15 22:05   ` SZEDER Gábor
2021-04-15 22:24     ` Junio C Hamano
2021-04-16 23:48     ` Ævar Arnfjörð Bjarmason
2021-04-12 11:09 ` [PATCH 16/16] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
2021-04-12 19:40   ` Junio C Hamano
2021-04-12 18:18 ` [PATCH 00/16] test-lib.sh: new test_commit args, simplification & fixes Junio C Hamano
2021-04-17 12:52 ` [PATCH v2 00/12] " Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 02/12] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 04/12] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 05/12] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 06/12] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 07/12] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 08/12] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 09/12] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 10/12] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 11/12] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
2021-04-17 12:52   ` [PATCH v2 12/12] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-17 15:42     ` SZEDER Gábor
2021-04-17 21:45       ` Ævar Arnfjörð Bjarmason
2021-04-20 21:27         ` SZEDER Gábor
2021-04-17 12:58   ` [PATCH 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
2021-04-17 12:58     ` [PATCH 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
2021-04-17 12:58     ` [PATCH 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
2021-04-18  5:11       ` Eric Sunshine
2021-04-20 12:25         ` Ævar Arnfjörð Bjarmason
2021-04-17 12:58     ` [PATCH 3/3] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
2021-04-20 12:21   ` [PATCH v3 00/12] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
2021-04-20 12:21     ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
2021-04-20 22:25       ` Junio C Hamano
2021-04-21  8:46         ` Ævar Arnfjörð Bjarmason
2021-04-21 10:39           ` Đoàn Trần Công Danh
2021-04-21 10:41             ` [PATCH 1/2] t6400: check exit status of ls-files Đoàn Trần Công Danh
2021-04-21 10:41               ` [PATCH 2/2] t6402: " Đoàn Trần Công Danh
2021-04-21 16:55                 ` Eric Sunshine
2021-04-21 17:32                   ` Eric Sunshine
2021-04-21 23:32                     ` Junio C Hamano
2021-04-22 13:49                       ` Đoàn Trần Công Danh
2021-04-22 15:04                         ` Ævar Arnfjörð Bjarmason
2021-04-22 15:30                           ` Eric Sunshine
2021-04-22 15:07                         ` Đoàn Trần Công Danh
2021-04-22 12:45                   ` Ævar Arnfjörð Bjarmason
2021-04-21 14:18             ` [PATCH v3 01/12] check-non-portable-shell: check for "test <cond> -a/-o <cond>" Ævar Arnfjörð Bjarmason
2021-04-21 16:32               ` Junio C Hamano
2021-04-21 18:56           ` Junio C Hamano
2021-04-20 12:21     ` [PATCH v3 02/12] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
2021-04-20 22:28       ` Junio C Hamano
2021-04-20 12:21     ` [PATCH v3 03/12] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
2021-04-20 12:21     ` [PATCH v3 04/12] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
2021-04-20 12:21     ` [PATCH v3 05/12] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
2021-04-20 12:21     ` [PATCH v3 06/12] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
2021-04-20 12:21     ` [PATCH v3 07/12] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
2021-04-20 12:21     ` [PATCH v3 08/12] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
2021-04-20 12:22     ` [PATCH v3 09/12] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
2021-04-20 12:22     ` [PATCH v3 10/12] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-20 12:22     ` [PATCH v3 11/12] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
2021-04-20 12:22     ` [PATCH v3 12/12] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-21 10:15     ` [PATCH v4 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
2021-04-21 10:15       ` [PATCH v4 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-21 16:43         ` SZEDER Gábor
2021-04-22 12:39           ` Ævar Arnfjörð Bjarmason
2021-04-23  7:21       ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
2021-05-06 15:46           ` Đoàn Trần Công Danh
2021-04-23  7:21         ` [PATCH v5 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
2021-05-06 15:58           ` Đoàn Trần Công Danh
2021-04-23  7:21         ` [PATCH v5 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
2021-05-06 16:08           ` Đoàn Trần Công Danh
2021-04-23  7:21         ` [PATCH v5 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
2021-04-23  7:21         ` [PATCH v5 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
2021-04-29  7:23         ` [PATCH v5 00/11] test-lib.sh: new test_commit args, simplification & fixes Junio C Hamano
2021-05-06 15:32         ` Ævar Arnfjörð Bjarmason
2021-05-06 16:21           ` Đoàn Trần Công Danh
2021-05-10 14:18         ` [PATCH v6 " Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 01/11] test-lib: bring $remove_trash out of retirement Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 02/11] test-lib tests: remove dead GIT_TEST_FRAMEWORK_SELFTEST variable Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 03/11] test-lib-functions: reword "test_commit --append" docs Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 04/11] test-lib-functions: document test_commit --no-tag Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 05/11] test-lib functions: add an --annotated option to "test_commit" Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 06/11] describe tests: convert setup to use test_commit Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 07/11] test-lib functions: add --printf option to test_commit Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 08/11] submodule tests: use symbolic-ref --short to discover branch name Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 09/11] test-lib: reformat argument list in test_create_repo() Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 10/11] test-lib: do not show advice about init.defaultBranch under --verbose Ævar Arnfjörð Bjarmason
2021-05-10 14:19           ` [PATCH v6 11/11] test-lib: split up and deprecate test_create_repo() Ævar Arnfjörð Bjarmason
2021-05-13  6:45             ` Felipe Contreras
2021-05-13  7:45               ` Ævar Arnfjörð Bjarmason
2021-05-13  8:23                 ` Felipe Contreras
2021-05-13 12:05                   ` Ævar Arnfjörð Bjarmason
2021-05-13 20:11                     ` Felipe Contreras
2021-05-12 12:19           ` [PATCH v6 00/11] test-lib.sh: new test_commit args, simplification & fixes Đoàn Trần Công Danh
2021-05-12 23:24             ` Junio C Hamano
2021-04-20 12:29 ` [PATCH v2 0/3] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
2021-04-20 12:29   ` [PATCH v2 1/3] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
2021-04-20 12:29   ` [PATCH v2 2/3] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
2021-04-20 15:07     ` Eric Sunshine
2021-04-21  8:22       ` Ævar Arnfjörð Bjarmason
2021-04-20 12:29   ` [PATCH v2 3/3] test-lib-functions: remove last two parameter count assertions Ævar Arnfjörð Bjarmason
2021-04-20 21:15     ` Junio C Hamano
2021-04-21 14:58   ` [PATCH v2 0/5] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
2021-04-21 14:58     ` [PATCH v2 1/5] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
2021-04-21 14:58     ` [PATCH v2 2/5] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
2021-04-21 14:58     ` [PATCH v2 3/5] test helpers: remove unused test-tool path-utils slice-tests Ævar Arnfjörð Bjarmason
2021-04-21 18:02       ` Ævar Arnfjörð Bjarmason
2021-04-21 14:58     ` [PATCH v2 4/5] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Ævar Arnfjörð Bjarmason
2021-04-21 14:58     ` [PATCH v2 5/5] test-helpers: split "file-size" into "file-size(s)" Ævar Arnfjörð Bjarmason
2021-04-23  7:29     ` [PATCH v3 0/4] test-lib-functions.sh: trickery to make -x less verbose Ævar Arnfjörð Bjarmason
2021-04-23  7:29       ` [PATCH v3 1/4] test-lib-functions: normalize test_path_is_missing() debugging Ævar Arnfjörð Bjarmason
2021-04-29  3:49         ` Junio C Hamano
2021-04-23  7:29       ` [PATCH v3 2/4] Revert and amend "test-lib-functions: assert correct parameter count" Ævar Arnfjörð Bjarmason
2021-04-29  3:59         ` Junio C Hamano
2021-04-29  4:02         ` Felipe Contreras
2021-04-23  7:29       ` [PATCH v3 3/4] test-helpers: rename "path-utils is_valid_path" to "is-valid-paths" Ævar Arnfjörð Bjarmason
2021-04-23  7:29       ` [PATCH v3 4/4] test-helpers: split "file-size" into "file-size(s)" Ævar Arnfjörð Bjarmason

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.