tests: adjust whitespace in chainlint expectations
The "check-chainlint" target runs automatically when running tests and
performs self-checks to verify that the chainlinter itself produces the
expected output. Originally, the chainlinter was implemented via sed,
but the infrastructure has been rewritten in fb41727b7e (t: retire
unused chainlint.sed, 2022-09-01) to use a Perl script instead.
The rewrite caused some slight whitespace changes in the output that are
ultimately not of much importance. In order to be able to assert that
the actual chainlinter errors match our expectations we thus have to
ignore whitespace characters when diffing them. As the `-w` flag is not
in POSIX we try to use `git diff -w --no-index` before we fall back to
`diff -w -u`.
To accomodate for cases where the host system has no Git installation we
use the locally-compiled version of Git. This can result in problems
though when the Git project's repository is using extensions that the
locally-compiled version of Git doesn't understand. It will refuse to
run and thus cause the checks to fail.
Instead of improving the detection logic, fix our ".expect" files so
that we do not need any post-processing at all anymore. This allows us
to drop the `-w` flag when diffing so that we can always use diff(1)
now.
Note that we keep some of the post-processing of `chainlint.pl` output
intact to strip leading line numbers generated by the script. Having
these would cause a rippling effect whenever we add a new test that
sorts into the middle of existing tests and would require us to
renumerate all subsequent lines, which seems rather pointless.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committedDec 15, 2023 at 07:42 UTC647b5e09987ac74e158d66ac2fd0036f2c9c99fe
27 files changed+90-74
t/Makefile
+3-11
index 3e00cdd801..fae301248f 100644--- a/t/Makefile+++ b/t/Makefile@@ -90,20 +90,12 @@ check-chainlint: echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \ for i in $(CHAINLINTTESTS); do \ echo "# chainlint: $$i" && \- sed -e '/^[ ]*$$/d' chainlint/$$i.expect; \+ cat chainlint/$$i.expect; \ done \ } >'$(CHAINLINTTMP_SQ)'/expect && \ $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \- sed -e 's/^[1-9][0-9]* //;/^[ ]*$$/d' >'$(CHAINLINTTMP_SQ)'/actual && \- if test -f ../GIT-BUILD-OPTIONS; then \- . ../GIT-BUILD-OPTIONS; \- fi && \- if test -x ../git$$X; then \- DIFFW="../git$$X --no-pager diff -w --no-index"; \- else \- DIFFW="diff -w -u"; \- fi && \- $$DIFFW '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual+ sed -e 's/^[1-9][0-9]* //' >'$(CHAINLINTTMP_SQ)'/actual && \+ diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \ test-lint-filenames
t/chainlint/blank-line-before-esac.expect
+4-4
index 48ed4eb124..056e03003d 100644--- a/t/chainlint/blank-line-before-esac.expect+++ b/t/chainlint/blank-line-before-esac.expect@@ -1,11 +1,11 @@-test_done ( ) {+test_done () { case "$test_failure" in- 0 )+ 0) test_at_end_hook_ exit 0 ;;- * )+ *) if test $test_external_has_tap -eq 0 then say_color error "# failed $test_failure among $msg"@@ -14,5 +14,5 @@ test_done ( ) { exit 1 ;;- esac+ esac }
index 1732d221c3..4cd18e2edf 100644--- a/t/chainlint/chain-break-return-exit.expect+++ b/t/chainlint/chain-break-return-exit.expect@@ -1,16 +1,16 @@ case "$(git ls-files)" in-one ) echo pass one ;;-* ) echo bad one ; return 1 ;;+one) echo pass one ;;+*) echo bad one; return 1 ;; esac && ( case "$(git ls-files)" in- two ) echo pass two ;;- * ) echo bad two ; exit 1 ;;-esac+ two) echo pass two ;;+ *) echo bad two; exit 1 ;;+ esac ) && case "$(git ls-files)" in-dir/two"$LF"one ) echo pass both ;;-* ) echo bad ; return 1 ;;+dir/two"$LF"one) echo pass both ;;+*) echo bad; return 1 ;; esac && for i in 1 2 3 4 ; do
index 2d961a58c6..765a35bb4c 100644--- a/t/chainlint/exclamation.expect+++ b/t/chainlint/exclamation.expect@@ -1,4 +1,4 @@-if ! condition ; then echo nope ; else yep ; fi &&+if ! condition; then echo nope; else yep; fi && test_prerequisite !MINGW && mail uucp!address && echo !whatever!
t/chainlint/for-loop-abbreviated.expect
+1-1
index a21007a63f..02c0d15cca 100644--- a/t/chainlint/for-loop-abbreviated.expect+++ b/t/chainlint/for-loop-abbreviated.expect@@ -1,5 +1,5 @@ for it do- path=$(expr "$it" : ( [^:]*) ) &&+ path=$(expr "$it" : ([^:]*)) && git update-index --add "$path" || exit done
t/chainlint/for-loop.expect
+1
index d65c82129a..d2237f1e38 100644--- a/t/chainlint/for-loop.expect+++ b/t/chainlint/for-loop.expect@@ -6,6 +6,7 @@ bar EOF done ?!AMP?!+ for i in a b c; do echo $i && cat $i ?!LOOP?!
index 24da9e86d5..7ce3a34806 100644--- a/t/chainlint/loop-detect-status.expect+++ b/t/chainlint/loop-detect-status.expect@@ -1,18 +1,18 @@-( while test $i -le $blobcount-do- printf "Generating blob $i/$blobcount\r" >& 2 &&+(while test $i -le $blobcount+ do+ printf "Generating blob $i/$blobcount\r" >&2 && printf "blob\nmark :$i\ndata $blobsize\n" && #test-tool genrandom $i $blobsize && printf "%-${blobsize}s" $i && echo "M 100644 :$i $i" >> commit && i=$(($i+1)) || echo $? > exit-status-done &&-echo "commit refs/heads/main" &&-echo "author A U Thor <author@email.com> 123456789 +0000" &&-echo "committer C O Mitter <committer@email.com> 123456789 +0000" &&-echo "data 5" &&-echo ">2gb" &&-cat commit ) |+ done &&+ echo "commit refs/heads/main" &&+ echo "author A U Thor <author@email.com> 123456789 +0000" &&+ echo "committer C O Mitter <committer@email.com> 123456789 +0000" &&+ echo "data 5" &&+ echo ">2gb" &&+ cat commit) | git fast-import --big-file-threshold=2 && test ! -f exit-status
t/chainlint/nested-cuddled-subshell.expect
+6
index 2a86885ee6..3836049cc4 100644--- a/t/chainlint/nested-cuddled-subshell.expect+++ b/t/chainlint/nested-cuddled-subshell.expect@@ -2,18 +2,24 @@ (cd foo && bar ) &&+ (cd foo && bar ) ?!AMP?!+ ( cd foo && bar) &&+ ( cd foo && bar) ?!AMP?!+ (cd foo && bar) &&+ (cd foo && bar) ?!AMP?!+ foobar )
t/chainlint/nested-loop-detect-failure.expect
+12-12
index 4793a0e8e1..3461df40e5 100644--- a/t/chainlint/nested-loop-detect-failure.expect+++ b/t/chainlint/nested-loop-detect-failure.expect@@ -1,31 +1,31 @@-for i in 0 1 2 3 4 5 6 7 8 9 ;+for i in 0 1 2 3 4 5 6 7 8 9; do- for j in 0 1 2 3 4 5 6 7 8 9 ;+ for j in 0 1 2 3 4 5 6 7 8 9; do- echo "$i$j" > "path$i$j" ?!LOOP?!+ echo "$i$j" >"path$i$j" ?!LOOP?! done ?!LOOP?! done &&-for i in 0 1 2 3 4 5 6 7 8 9 ;+for i in 0 1 2 3 4 5 6 7 8 9; do- for j in 0 1 2 3 4 5 6 7 8 9 ;+ for j in 0 1 2 3 4 5 6 7 8 9; do- echo "$i$j" > "path$i$j" || return 1+ echo "$i$j" >"path$i$j" || return 1 done done &&-for i in 0 1 2 3 4 5 6 7 8 9 ;+for i in 0 1 2 3 4 5 6 7 8 9; do- for j in 0 1 2 3 4 5 6 7 8 9 ;+ for j in 0 1 2 3 4 5 6 7 8 9; do- echo "$i$j" > "path$i$j" ?!LOOP?!+ echo "$i$j" >"path$i$j" ?!LOOP?! done || return 1 done &&-for i in 0 1 2 3 4 5 6 7 8 9 ;+for i in 0 1 2 3 4 5 6 7 8 9; do- for j in 0 1 2 3 4 5 6 7 8 9 ;+ for j in 0 1 2 3 4 5 6 7 8 9; do- echo "$i$j" > "path$i$j" || return 1+ echo "$i$j" >"path$i$j" || return 1 done || return 1 done
t/chainlint/nested-subshell.expect
+1
index 02e0a9f1bb..73ff28546a 100644--- a/t/chainlint/nested-subshell.expect+++ b/t/chainlint/nested-subshell.expect@@ -4,6 +4,7 @@ echo a && echo b ) >file &&+ cd foo && ( echo a ?!AMP?!
t/chainlint/pipe.expect
+2
index 2cfc028297..811971b1a3 100644--- a/t/chainlint/pipe.expect+++ b/t/chainlint/pipe.expect@@ -2,7 +2,9 @@ foo | bar | baz &&+ fish | cow ?!AMP?!+ sunder )
index 342360bcd0..6a387917a7 100644--- a/t/chainlint/token-pasting.expect+++ b/t/chainlint/token-pasting.expect@@ -4,22 +4,22 @@ git config filter.rot13.clean ./rot13.sh && { echo "*.t filter=rot13" ?!AMP?! echo "*.i ident"-} > .gitattributes &&+} >.gitattributes && { echo a b c d e f g h i j k l m ?!AMP?! echo n o p q r s t u v w x y z ?!AMP?! echo '$Id$'-} > test &&-cat test > test.t &&-cat test > test.o &&-cat test > test.i &&+} >test &&+cat test >test.t &&+cat test >test.o &&+cat test >test.i && git add test test.t test.i && rm -f test test.t test.i && git checkout -- test test.t test.i &&-echo "content-test2" > test2.o &&-echo "content-test3 - filename with special characters" > "test3 'sq',$x=.o" ?!AMP?!+echo "content-test2" >test2.o &&+echo "content-test3 - filename with special characters" >"test3 'sq',$x=.o" ?!AMP?! downstream_url_for_sed=$( printf "%sn" "$downstream_url" |
t/chainlint/while-loop.expect
+1
index 1f5eaea0fd..06c1567f48 100644--- a/t/chainlint/while-loop.expect+++ b/t/chainlint/while-loop.expect@@ -6,6 +6,7 @@ bar EOF done ?!AMP?!+ while true; do echo foo && cat bar ?!LOOP?!