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 committed Dec 15, 2023 at 07:42 UTC 647b5e09987ac74e158d66ac2fd0036f2c9c99fe
27 files changed +90 -74
t/Makefile
+3 -11
@@ -90,20 +90,12 @@ check-chainlint:
90 echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \
91 for i in $(CHAINLINTTESTS); do \
92 echo "# chainlint: $$i" && \
93 - sed -e '/^[ ]*$$/d' chainlint/$$i.expect; \
93 + cat chainlint/$$i.expect; \
94 done \
95 } >'$(CHAINLINTTMP_SQ)'/expect && \
96 $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
97 - sed -e 's/^[1-9][0-9]* //;/^[ ]*$$/d' >'$(CHAINLINTTMP_SQ)'/actual && \
98 - if test -f ../GIT-BUILD-OPTIONS; then \
99 - . ../GIT-BUILD-OPTIONS; \
100 - fi && \
101 - if test -x ../git$$X; then \
102 - DIFFW="../git$$X --no-pager diff -w --no-index"; \
103 - else \
104 - DIFFW="diff -w -u"; \
105 - fi && \
106 - $$DIFFW '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
97 + sed -e 's/^[1-9][0-9]* //' >'$(CHAINLINTTMP_SQ)'/actual && \
98 + diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
99
100 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
101 test-lint-filenames
t/chainlint/blank-line-before-esac.expect
+4 -4
@@ -1,11 +1,11 @@
1 -test_done ( ) {
1 +test_done () {
2 case "$test_failure" in
3 - 0 )
3 + 0)
4 test_at_end_hook_
5
6 exit 0 ;;
7
8 - * )
8 + *)
9 if test $test_external_has_tap -eq 0
10 then
11 say_color error "# failed $test_failure among $msg"
@@ -14,5 +14,5 @@ test_done ( ) {
14
15 exit 1 ;;
16
17 - esac
17 + esac
18 }
t/chainlint/blank-line.expect
+4
@@ -1,4 +1,8 @@
1 (
2 +
3 nothing &&
4 +
5 something
6 +
7 +
8 )
t/chainlint/block.expect
+2 -2
@@ -12,9 +12,9 @@
12 ) &&
13
14 {
15 - echo a ; ?!AMP?! echo b
15 + echo a; ?!AMP?! echo b
16 } &&
17 -{ echo a ; ?!AMP?! echo b ; } &&
17 +{ echo a; ?!AMP?! echo b; } &&
18
19 {
20 echo "${var}9" &&
t/chainlint/chain-break-background.expect
+2 -2
@@ -1,9 +1,9 @@
1 JGIT_DAEMON_PID= &&
2 git init --bare empty.git &&
3 -> empty.git/git-daemon-export-ok &&
3 +>empty.git/git-daemon-export-ok &&
4 mkfifo jgit_daemon_output &&
5 {
6 - jgit daemon --port="$JGIT_DAEMON_PORT" . > jgit_daemon_output &
6 + jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
7 JGIT_DAEMON_PID=$!
8 } &&
9 test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
t/chainlint/chain-break-return-exit.expect
+7 -7
@@ -1,16 +1,16 @@
1 case "$(git ls-files)" in
2 -one ) echo pass one ;;
3 -* ) echo bad one ; return 1 ;;
2 +one) echo pass one ;;
3 +*) echo bad one; return 1 ;;
4 esac &&
5 (
6 case "$(git ls-files)" in
7 - two ) echo pass two ;;
8 - * ) echo bad two ; exit 1 ;;
9 -esac
7 + two) echo pass two ;;
8 + *) echo bad two; exit 1 ;;
9 + esac
10 ) &&
11 case "$(git ls-files)" in
12 -dir/two"$LF"one ) echo pass both ;;
13 -* ) echo bad ; return 1 ;;
12 +dir/two"$LF"one) echo pass both ;;
13 +*) echo bad; return 1 ;;
14 esac &&
15
16 for i in 1 2 3 4 ; do
t/chainlint/chain-break-status.expect
+2 -2
@@ -1,7 +1,7 @@
1 -OUT=$(( ( large_git ; echo $? 1 >& 3 ) | : ) 3 >& 1) &&
1 +OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
2 test_match_signal 13 "$OUT" &&
3
4 -{ test-tool sigchain > actual ; ret=$? ; } &&
4 +{ test-tool sigchain >actual; ret=$?; } &&
5 {
6 test_match_signal 15 "$ret" ||
7 test "$ret" = 3
t/chainlint/chained-subshell.expect
+2 -2
@@ -4,7 +4,7 @@ mkdir sub && (
4 nuff said
5 ) &&
6
7 -cut "-d " -f actual | ( read s1 s2 s3 &&
7 +cut "-d " -f actual | (read s1 s2 s3 &&
8 test -f $s1 ?!AMP?!
9 test $(cat $s2) = tree2path1 &&
10 -test $(cat $s3) = tree3path1 )
10 +test $(cat $s3) = tree3path1)
t/chainlint/command-substitution-subsubshell.expect
+1 -1
@@ -1,2 +1,2 @@
1 -OUT=$(( ( large_git 1 >& 3 ) | : ) 3 >& 1) &&
1 +OUT=$( ((large_git 1>&3) | :) 3>&1 ) &&
2 test_match_signal 13 "$OUT"
t/chainlint/dqstring-line-splice.expect
+4 -2
@@ -1,3 +1,5 @@
1 -echo 'fatal: reword option of --fixup is mutually exclusive with' '--patch/--interactive/--all/--include/--only' > expect &&
2 -test_must_fail git commit --fixup=reword:HEAD~ $1 2 > actual &&
1 +
2 +echo 'fatal: reword option of --fixup is mutually exclusive with' '--patch/--interactive/--all/--include/--only' >expect &&
3 +test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual &&
4 test_cmp expect actual
5 +
t/chainlint/dqstring-no-interpolate.expect
+3 -2
@@ -6,6 +6,7 @@ grep "^\.git$" output.txt &&
6 (
7 cd client$version &&
8 GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. $(cat ../input)
9 -) > output &&
10 - cut -d ' ' -f 2 < output | sort > actual &&
9 +) >output &&
10 + cut -d ' ' -f 2 <output | sort >actual &&
11 test_cmp expect actual
12 +
t/chainlint/empty-here-doc.expect
+2 -2
@@ -1,4 +1,4 @@
1 -git ls-tree $tree path > current &&
2 -cat > expected <<\EOF &&
1 +git ls-tree $tree path >current &&
2 +cat >expected <<\EOF &&
3 EOF
4 test_output
t/chainlint/exclamation.expect
+1 -1
@@ -1,4 +1,4 @@
1 -if ! condition ; then echo nope ; else yep ; fi &&
1 +if ! condition; then echo nope; else yep; fi &&
2 test_prerequisite !MINGW &&
3 mail uucp!address &&
4 echo !whatever!
t/chainlint/for-loop-abbreviated.expect
+1 -1
@@ -1,5 +1,5 @@
1 for it
2 do
3 - path=$(expr "$it" : ( [^:]*) ) &&
3 + path=$(expr "$it" : ([^:]*)) &&
4 git update-index --add "$path" || exit
5 done
t/chainlint/for-loop.expect
+1
@@ -6,6 +6,7 @@
6 bar
7 EOF
8 done ?!AMP?!
9 +
10 for i in a b c; do
11 echo $i &&
12 cat $i ?!LOOP?!
t/chainlint/function.expect
+2 -2
@@ -1,8 +1,8 @@
1 -sha1_file ( ) {
1 +sha1_file() {
2 echo "$*" | sed "s#..#.git/objects/&/#"
3 } &&
4
5 -remove_object ( ) {
5 +remove_object() {
6 file=$(sha1_file "$*") &&
7 test -e "$file" ?!AMP?!
8 rm -f "$file"
t/chainlint/here-doc.expect
+2 -2
@@ -1,6 +1,6 @@
1 boodle wobba \
2 - gorgo snoot \
3 - wafta snurb <<EOF &&
2 + gorgo snoot \
3 + wafta snurb <<EOF &&
4 quoth the raven,
5 nevermore...
6 EOF
t/chainlint/loop-detect-status.expect
+10 -10
@@ -1,18 +1,18 @@
1 -( while test $i -le $blobcount
2 -do
3 - printf "Generating blob $i/$blobcount\r" >& 2 &&
1 +(while test $i -le $blobcount
2 + do
3 + printf "Generating blob $i/$blobcount\r" >&2 &&
4 printf "blob\nmark :$i\ndata $blobsize\n" &&
5 #test-tool genrandom $i $blobsize &&
6 printf "%-${blobsize}s" $i &&
7 echo "M 100644 :$i $i" >> commit &&
8 i=$(($i+1)) ||
9 echo $? > exit-status
10 -done &&
11 -echo "commit refs/heads/main" &&
12 -echo "author A U Thor <author@email.com> 123456789 +0000" &&
13 -echo "committer C O Mitter <committer@email.com> 123456789 +0000" &&
14 -echo "data 5" &&
15 -echo ">2gb" &&
16 -cat commit ) |
10 + done &&
11 + echo "commit refs/heads/main" &&
12 + echo "author A U Thor <author@email.com> 123456789 +0000" &&
13 + echo "committer C O Mitter <committer@email.com> 123456789 +0000" &&
14 + echo "data 5" &&
15 + echo ">2gb" &&
16 + cat commit) |
17 git fast-import --big-file-threshold=2 &&
18 test ! -f exit-status
t/chainlint/nested-cuddled-subshell.expect
+6
@@ -2,18 +2,24 @@
2 (cd foo &&
3 bar
4 ) &&
5 +
6 (cd foo &&
7 bar
8 ) ?!AMP?!
9 +
10 (
11 cd foo &&
12 bar) &&
13 +
14 (
15 cd foo &&
16 bar) ?!AMP?!
17 +
18 (cd foo &&
19 bar) &&
20 +
21 (cd foo &&
22 bar) ?!AMP?!
23 +
24 foobar
25 )
t/chainlint/nested-loop-detect-failure.expect
+12 -12
@@ -1,31 +1,31 @@
1 -for i in 0 1 2 3 4 5 6 7 8 9 ;
1 +for i in 0 1 2 3 4 5 6 7 8 9;
2 do
3 - for j in 0 1 2 3 4 5 6 7 8 9 ;
3 + for j in 0 1 2 3 4 5 6 7 8 9;
4 do
5 - echo "$i$j" > "path$i$j" ?!LOOP?!
5 + echo "$i$j" >"path$i$j" ?!LOOP?!
6 done ?!LOOP?!
7 done &&
8
9 -for i in 0 1 2 3 4 5 6 7 8 9 ;
9 +for i in 0 1 2 3 4 5 6 7 8 9;
10 do
11 - for j in 0 1 2 3 4 5 6 7 8 9 ;
11 + for j in 0 1 2 3 4 5 6 7 8 9;
12 do
13 - echo "$i$j" > "path$i$j" || return 1
13 + echo "$i$j" >"path$i$j" || return 1
14 done
15 done &&
16
17 -for i in 0 1 2 3 4 5 6 7 8 9 ;
17 +for i in 0 1 2 3 4 5 6 7 8 9;
18 do
19 - for j in 0 1 2 3 4 5 6 7 8 9 ;
19 + for j in 0 1 2 3 4 5 6 7 8 9;
20 do
21 - echo "$i$j" > "path$i$j" ?!LOOP?!
21 + echo "$i$j" >"path$i$j" ?!LOOP?!
22 done || return 1
23 done &&
24
25 -for i in 0 1 2 3 4 5 6 7 8 9 ;
25 +for i in 0 1 2 3 4 5 6 7 8 9;
26 do
27 - for j in 0 1 2 3 4 5 6 7 8 9 ;
27 + for j in 0 1 2 3 4 5 6 7 8 9;
28 do
29 - echo "$i$j" > "path$i$j" || return 1
29 + echo "$i$j" >"path$i$j" || return 1
30 done || return 1
31 done
t/chainlint/nested-subshell.expect
+1
@@ -4,6 +4,7 @@
4 echo a &&
5 echo b
6 ) >file &&
7 +
8 cd foo &&
9 (
10 echo a ?!AMP?!
t/chainlint/pipe.expect
+2
@@ -2,7 +2,9 @@
2 foo |
3 bar |
4 baz &&
5 +
6 fish |
7 cow ?!AMP?!
8 +
9 sunder
10 )
t/chainlint/subshell-here-doc.expect
+2 -2
@@ -1,7 +1,7 @@
1 (
2 echo wobba \
3 - gorgo snoot \
4 - wafta snurb <<-EOF &&
3 + gorgo snoot \
4 + wafta snurb <<-EOF &&
5 quoth the raven,
6 nevermore...
7 EOF
t/chainlint/subshell-one-liner.expect
+5
@@ -2,13 +2,18 @@
2 (foo && bar) &&
3 (foo && bar) |
4 (foo && bar) >baz &&
5 +
6 (foo; ?!AMP?! bar) &&
7 (foo; ?!AMP?! bar) |
8 (foo; ?!AMP?! bar) >baz &&
9 +
10 (foo || exit 1) &&
11 (foo || exit 1) |
12 (foo || exit 1) >baz &&
13 +
14 (foo && bar) ?!AMP?!
15 +
16 (foo && bar; ?!AMP?! baz) ?!AMP?!
17 +
18 foobar
19 )
t/chainlint/t7900-subtree.expect
+1
@@ -15,6 +15,7 @@ main-sub4" &&
15 $chkms
16 TXT
17 ) &&
18 +
19 subfiles=$(git ls-files) &&
20 check_equal "$subfiles" "$chkms
21 $chks"
t/chainlint/token-pasting.expect
+7 -7
@@ -4,22 +4,22 @@ git config filter.rot13.clean ./rot13.sh &&
4 {
5 echo "*.t filter=rot13" ?!AMP?!
6 echo "*.i ident"
7 -} > .gitattributes &&
7 +} >.gitattributes &&
8
9 {
10 echo a b c d e f g h i j k l m ?!AMP?!
11 echo n o p q r s t u v w x y z ?!AMP?!
12 echo '$Id$'
13 -} > test &&
14 -cat test > test.t &&
15 -cat test > test.o &&
16 -cat test > test.i &&
13 +} >test &&
14 +cat test >test.t &&
15 +cat test >test.o &&
16 +cat test >test.i &&
17 git add test test.t test.i &&
18 rm -f test test.t test.i &&
19 git checkout -- test test.t test.i &&
20
21 -echo "content-test2" > test2.o &&
22 -echo "content-test3 - filename with special characters" > "test3 'sq',$x=.o" ?!AMP?!
21 +echo "content-test2" >test2.o &&
22 +echo "content-test3 - filename with special characters" >"test3 'sq',$x=.o" ?!AMP?!
23
24 downstream_url_for_sed=$(
25 printf "%sn" "$downstream_url" |
t/chainlint/while-loop.expect
+1
@@ -6,6 +6,7 @@
6 bar
7 EOF
8 done ?!AMP?!
9 +
10 while true; do
11 echo foo &&
12 cat bar ?!LOOP?!