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>
maint
Patrick Steinhardt 2023-12-15 07:42:47 +01:00 committed by Junio C Hamano
parent fb7d80edca
commit 647b5e0998
27 changed files with 90 additions and 74 deletions

View File

@ -90,20 +90,12 @@ check-chainlint:
echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \ echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \
for i in $(CHAINLINTTESTS); do \ for i in $(CHAINLINTTESTS); do \
echo "# chainlint: $$i" && \ echo "# chainlint: $$i" && \
sed -e '/^[ ]*$$/d' chainlint/$$i.expect; \ cat chainlint/$$i.expect; \
done \ done \
} >'$(CHAINLINTTMP_SQ)'/expect && \ } >'$(CHAINLINTTMP_SQ)'/expect && \
$(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \ $(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
sed -e 's/^[1-9][0-9]* //;/^[ ]*$$/d' >'$(CHAINLINTTMP_SQ)'/actual && \ sed -e 's/^[1-9][0-9]* //' >'$(CHAINLINTTMP_SQ)'/actual && \
if test -f ../GIT-BUILD-OPTIONS; then \ diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual
. ../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


test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \ test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
test-lint-filenames test-lint-filenames

View File

@ -1,11 +1,11 @@
test_done ( ) { test_done () {
case "$test_failure" in case "$test_failure" in
0 ) 0)
test_at_end_hook_ test_at_end_hook_


exit 0 ;; exit 0 ;;


* ) *)
if test $test_external_has_tap -eq 0 if test $test_external_has_tap -eq 0
then then
say_color error "# failed $test_failure among $msg" say_color error "# failed $test_failure among $msg"
@ -14,5 +14,5 @@ test_done ( ) {


exit 1 ;; exit 1 ;;


esac esac
} }

View File

@ -1,4 +1,8 @@
( (

nothing && nothing &&

something something


) )

View File

@ -12,9 +12,9 @@
) && ) &&


{ {
echo a ; ?!AMP?! echo b echo a; ?!AMP?! echo b
} && } &&
{ echo a ; ?!AMP?! echo b ; } && { echo a; ?!AMP?! echo b; } &&


{ {
echo "${var}9" && echo "${var}9" &&

View File

@ -1,9 +1,9 @@
JGIT_DAEMON_PID= && JGIT_DAEMON_PID= &&
git init --bare empty.git && git init --bare empty.git &&
> empty.git/git-daemon-export-ok && >empty.git/git-daemon-export-ok &&
mkfifo jgit_daemon_output && mkfifo jgit_daemon_output &&
{ {
jgit daemon --port="$JGIT_DAEMON_PORT" . > jgit_daemon_output & jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
JGIT_DAEMON_PID=$! JGIT_DAEMON_PID=$!
} && } &&
test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git

View File

@ -1,16 +1,16 @@
case "$(git ls-files)" in case "$(git ls-files)" in
one ) echo pass one ;; one) echo pass one ;;
* ) echo bad one ; return 1 ;; *) echo bad one; return 1 ;;
esac && esac &&
( (
case "$(git ls-files)" in case "$(git ls-files)" in
two ) echo pass two ;; two) echo pass two ;;
* ) echo bad two ; exit 1 ;; *) echo bad two; exit 1 ;;
esac esac
) && ) &&
case "$(git ls-files)" in case "$(git ls-files)" in
dir/two"$LF"one ) echo pass both ;; dir/two"$LF"one) echo pass both ;;
* ) echo bad ; return 1 ;; *) echo bad; return 1 ;;
esac && esac &&


for i in 1 2 3 4 ; do for i in 1 2 3 4 ; do

View File

@ -1,7 +1,7 @@
OUT=$(( ( large_git ; echo $? 1 >& 3 ) | : ) 3 >& 1) && OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
test_match_signal 13 "$OUT" && test_match_signal 13 "$OUT" &&


{ test-tool sigchain > actual ; ret=$? ; } && { test-tool sigchain >actual; ret=$?; } &&
{ {
test_match_signal 15 "$ret" || test_match_signal 15 "$ret" ||
test "$ret" = 3 test "$ret" = 3

View File

@ -4,7 +4,7 @@ mkdir sub && (
nuff said nuff said
) && ) &&


cut "-d " -f actual | ( read s1 s2 s3 && cut "-d " -f actual | (read s1 s2 s3 &&
test -f $s1 ?!AMP?! test -f $s1 ?!AMP?!
test $(cat $s2) = tree2path1 && test $(cat $s2) = tree2path1 &&
test $(cat $s3) = tree3path1 ) test $(cat $s3) = tree3path1)

View File

@ -1,2 +1,2 @@
OUT=$(( ( large_git 1 >& 3 ) | : ) 3 >& 1) && OUT=$( ((large_git 1>&3) | :) 3>&1 ) &&
test_match_signal 13 "$OUT" test_match_signal 13 "$OUT"

View File

@ -1,3 +1,5 @@
echo 'fatal: reword option of --fixup is mutually exclusive with' '--patch/--interactive/--all/--include/--only' > expect &&
test_must_fail git commit --fixup=reword:HEAD~ $1 2 > actual && echo 'fatal: reword option of --fixup is mutually exclusive with' '--patch/--interactive/--all/--include/--only' >expect &&
test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual &&
test_cmp expect actual test_cmp expect actual


View File

@ -6,6 +6,7 @@ grep "^\.git$" output.txt &&
( (
cd client$version && cd client$version &&
GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. $(cat ../input) GIT_TEST_PROTOCOL_VERSION=$version git fetch-pack --no-progress .. $(cat ../input)
) > output && ) >output &&
cut -d ' ' -f 2 < output | sort > actual && cut -d ' ' -f 2 <output | sort >actual &&
test_cmp expect actual test_cmp expect actual


View File

@ -1,4 +1,4 @@
git ls-tree $tree path > current && git ls-tree $tree path >current &&
cat > expected <<\EOF && cat >expected <<\EOF &&
EOF EOF
test_output test_output

View File

@ -1,4 +1,4 @@
if ! condition ; then echo nope ; else yep ; fi && if ! condition; then echo nope; else yep; fi &&
test_prerequisite !MINGW && test_prerequisite !MINGW &&
mail uucp!address && mail uucp!address &&
echo !whatever! echo !whatever!

View File

@ -1,5 +1,5 @@
for it for it
do do
path=$(expr "$it" : ( [^:]*) ) && path=$(expr "$it" : ([^:]*)) &&
git update-index --add "$path" || exit git update-index --add "$path" || exit
done done

View File

@ -6,6 +6,7 @@
bar bar
EOF EOF
done ?!AMP?! done ?!AMP?!

for i in a b c; do for i in a b c; do
echo $i && echo $i &&
cat $i ?!LOOP?! cat $i ?!LOOP?!

View File

@ -1,8 +1,8 @@
sha1_file ( ) { sha1_file() {
echo "$*" | sed "s#..#.git/objects/&/#" echo "$*" | sed "s#..#.git/objects/&/#"
} && } &&


remove_object ( ) { remove_object() {
file=$(sha1_file "$*") && file=$(sha1_file "$*") &&
test -e "$file" ?!AMP?! test -e "$file" ?!AMP?!
rm -f "$file" rm -f "$file"

View File

@ -1,6 +1,6 @@
boodle wobba \ boodle wobba \
gorgo snoot \ gorgo snoot \
wafta snurb <<EOF && wafta snurb <<EOF &&
quoth the raven, quoth the raven,
nevermore... nevermore...
EOF EOF

View File

@ -1,18 +1,18 @@
( while test $i -le $blobcount (while test $i -le $blobcount
do do
printf "Generating blob $i/$blobcount\r" >& 2 && printf "Generating blob $i/$blobcount\r" >&2 &&
printf "blob\nmark :$i\ndata $blobsize\n" && printf "blob\nmark :$i\ndata $blobsize\n" &&
#test-tool genrandom $i $blobsize && #test-tool genrandom $i $blobsize &&
printf "%-${blobsize}s" $i && printf "%-${blobsize}s" $i &&
echo "M 100644 :$i $i" >> commit && echo "M 100644 :$i $i" >> commit &&
i=$(($i+1)) || i=$(($i+1)) ||
echo $? > exit-status echo $? > exit-status
done && done &&
echo "commit refs/heads/main" && echo "commit refs/heads/main" &&
echo "author A U Thor <author@email.com> 123456789 +0000" && echo "author A U Thor <author@email.com> 123456789 +0000" &&
echo "committer C O Mitter <committer@email.com> 123456789 +0000" && echo "committer C O Mitter <committer@email.com> 123456789 +0000" &&
echo "data 5" && echo "data 5" &&
echo ">2gb" && echo ">2gb" &&
cat commit ) | cat commit) |
git fast-import --big-file-threshold=2 && git fast-import --big-file-threshold=2 &&
test ! -f exit-status test ! -f exit-status

View File

@ -2,18 +2,24 @@
(cd foo && (cd foo &&
bar bar
) && ) &&

(cd foo && (cd foo &&
bar bar
) ?!AMP?! ) ?!AMP?!

( (
cd foo && cd foo &&
bar) && bar) &&

( (
cd foo && cd foo &&
bar) ?!AMP?! bar) ?!AMP?!

(cd foo && (cd foo &&
bar) && bar) &&

(cd foo && (cd foo &&
bar) ?!AMP?! bar) ?!AMP?!

foobar foobar
) )

View File

@ -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 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 do
echo "$i$j" > "path$i$j" ?!LOOP?! echo "$i$j" >"path$i$j" ?!LOOP?!
done ?!LOOP?! done ?!LOOP?!
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 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 do
echo "$i$j" > "path$i$j" || return 1 echo "$i$j" >"path$i$j" || return 1
done done
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 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 do
echo "$i$j" > "path$i$j" ?!LOOP?! echo "$i$j" >"path$i$j" ?!LOOP?!
done || return 1 done || 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 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 do
echo "$i$j" > "path$i$j" || return 1 echo "$i$j" >"path$i$j" || return 1
done || return 1 done || return 1
done done

View File

@ -4,6 +4,7 @@
echo a && echo a &&
echo b echo b
) >file && ) >file &&

cd foo && cd foo &&
( (
echo a ?!AMP?! echo a ?!AMP?!

View File

@ -2,7 +2,9 @@
foo | foo |
bar | bar |
baz && baz &&

fish | fish |
cow ?!AMP?! cow ?!AMP?!

sunder sunder
) )

View File

@ -1,7 +1,7 @@
( (
echo wobba \ echo wobba \
gorgo snoot \ gorgo snoot \
wafta snurb <<-EOF && wafta snurb <<-EOF &&
quoth the raven, quoth the raven,
nevermore... nevermore...
EOF EOF

View File

@ -2,13 +2,18 @@
(foo && bar) && (foo && bar) &&
(foo && bar) | (foo && bar) |
(foo && bar) >baz && (foo && bar) >baz &&

(foo; ?!AMP?! bar) && (foo; ?!AMP?! bar) &&
(foo; ?!AMP?! bar) | (foo; ?!AMP?! bar) |
(foo; ?!AMP?! bar) >baz && (foo; ?!AMP?! bar) >baz &&

(foo || exit 1) && (foo || exit 1) &&
(foo || exit 1) | (foo || exit 1) |
(foo || exit 1) >baz && (foo || exit 1) >baz &&

(foo && bar) ?!AMP?! (foo && bar) ?!AMP?!

(foo && bar; ?!AMP?! baz) ?!AMP?! (foo && bar; ?!AMP?! baz) ?!AMP?!

foobar foobar
) )

View File

@ -15,6 +15,7 @@ main-sub4" &&
$chkms $chkms
TXT TXT
) && ) &&

subfiles=$(git ls-files) && subfiles=$(git ls-files) &&
check_equal "$subfiles" "$chkms check_equal "$subfiles" "$chkms
$chks" $chks"

View File

@ -4,22 +4,22 @@ git config filter.rot13.clean ./rot13.sh &&
{ {
echo "*.t filter=rot13" ?!AMP?! echo "*.t filter=rot13" ?!AMP?!
echo "*.i ident" echo "*.i ident"
} > .gitattributes && } >.gitattributes &&


{ {
echo a b c d e f g h i j k l m ?!AMP?! 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 n o p q r s t u v w x y z ?!AMP?!
echo '$Id$' echo '$Id$'
} > test && } >test &&
cat test > test.t && cat test >test.t &&
cat test > test.o && cat test >test.o &&
cat test > test.i && cat test >test.i &&
git add test test.t test.i && git add test test.t test.i &&
rm -f test test.t test.i && rm -f test test.t test.i &&
git checkout -- test test.t test.i && git checkout -- test test.t test.i &&


echo "content-test2" > test2.o && echo "content-test2" >test2.o &&
echo "content-test3 - filename with special characters" > "test3 'sq',$x=.o" ?!AMP?! echo "content-test3 - filename with special characters" >"test3 'sq',$x=.o" ?!AMP?!


downstream_url_for_sed=$( downstream_url_for_sed=$(
printf "%sn" "$downstream_url" | printf "%sn" "$downstream_url" |

View File

@ -6,6 +6,7 @@
bar bar
EOF EOF
done ?!AMP?! done ?!AMP?!

while true; do while true; do
echo foo && echo foo &&
cat bar ?!LOOP?! cat bar ?!LOOP?!