Skip to content

Commit 647b5e0

Browse files
pks-tgitster
authored andcommitted
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 fb41727 (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 <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d80e commit 647b5e0

27 files changed

+90
-74
lines changed

t/Makefile

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,12 @@ check-chainlint:
9090
echo "# chainlint: $(CHAINLINTTMP_SQ)/tests" && \
9191
for i in $(CHAINLINTTESTS); do \
9292
echo "# chainlint: $$i" && \
93-
sed -e '/^[ ]*$$/d' chainlint/$$i.expect; \
93+
cat chainlint/$$i.expect; \
9494
done \
9595
} >'$(CHAINLINTTMP_SQ)'/expect && \
9696
$(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
10799

108100
test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
109101
test-lint-filenames
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
test_done ( ) {
1+
test_done () {
22
case "$test_failure" in
3-
0 )
3+
0)
44
test_at_end_hook_
55

66
exit 0 ;;
77

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

1515
exit 1 ;;
1616

17-
esac
17+
esac
1818
}

t/chainlint/blank-line.expect

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
(
2+
23
nothing &&
4+
35
something
6+
7+
48
)

t/chainlint/block.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
) &&
1313

1414
{
15-
echo a ; ?!AMP?! echo b
15+
echo a; ?!AMP?! echo b
1616
} &&
17-
{ echo a ; ?!AMP?! echo b ; } &&
17+
{ echo a; ?!AMP?! echo b; } &&
1818

1919
{
2020
echo "${var}9" &&
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
JGIT_DAEMON_PID= &&
22
git init --bare empty.git &&
3-
> empty.git/git-daemon-export-ok &&
3+
>empty.git/git-daemon-export-ok &&
44
mkfifo jgit_daemon_output &&
55
{
6-
jgit daemon --port="$JGIT_DAEMON_PORT" . > jgit_daemon_output &
6+
jgit daemon --port="$JGIT_DAEMON_PORT" . >jgit_daemon_output &
77
JGIT_DAEMON_PID=$!
88
} &&
99
test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git

t/chainlint/chain-break-return-exit.expect

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
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 ;;
44
esac &&
55
(
66
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
1010
) &&
1111
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 ;;
1414
esac &&
1515

1616
for i in 1 2 3 4 ; do

t/chainlint/chain-break-status.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
OUT=$(( ( large_git ; echo $? 1 >& 3 ) | : ) 3 >& 1) &&
1+
OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
22
test_match_signal 13 "$OUT" &&
33

4-
{ test-tool sigchain > actual ; ret=$? ; } &&
4+
{ test-tool sigchain >actual; ret=$?; } &&
55
{
66
test_match_signal 15 "$ret" ||
77
test "$ret" = 3

t/chainlint/chained-subshell.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mkdir sub && (
44
nuff said
55
) &&
66

7-
cut "-d " -f actual | ( read s1 s2 s3 &&
7+
cut "-d " -f actual | (read s1 s2 s3 &&
88
test -f $s1 ?!AMP?!
99
test $(cat $s2) = tree2path1 &&
10-
test $(cat $s3) = tree3path1 )
10+
test $(cat $s3) = tree3path1)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
OUT=$(( ( large_git 1 >& 3 ) | : ) 3 >& 1) &&
1+
OUT=$( ((large_git 1>&3) | :) 3>&1 ) &&
22
test_match_signal 13 "$OUT"
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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 &&
34
test_cmp expect actual
5+

0 commit comments

Comments
 (0)