Skip to content

Commit 0b94009

Browse files
committed
Merge branch 'jk/chainlint-fixes'
Test framework fix. * jk/chainlint-fixes: tests: skip test_eval_ in internal chain-lint tests: drop here-doc check from internal chain-linter tests: diagnose unclosed here-doc in chainlint.pl tests: replace chainlint subshell with a function tests: run internal chain-linter under "make test"
2 parents 6047b28 + cc48ddd commit 0b94009

File tree

7 files changed

+50
-18
lines changed

7 files changed

+50
-18
lines changed

t/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
4444

4545
# `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
4646
# checks all tests in all scripts via a single invocation, so tell individual
47-
# scripts not to "chainlint" themselves
48-
CHAINLINTSUPPRESS = GIT_TEST_CHAIN_LINT=0 && export GIT_TEST_CHAIN_LINT &&
47+
# scripts not to run the external "chainlint.pl" script themselves
48+
CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT &&
4949

5050
all: $(DEFAULT_TEST_TARGET)
5151

t/chainlint.pl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ sub scan_heredoc_tag {
8080
return "<<$indented" unless $token;
8181
my $tag = $token->[0];
8282
$tag =~ s/['"\\]//g;
83-
push(@{$self->{heretags}}, $indented ? "\t$tag" : "$tag");
83+
$$token[0] = $indented ? "\t$tag" : "$tag";
84+
push(@{$self->{heretags}}, $token);
8485
return "<<$indented$tag";
8586
}
8687

@@ -169,10 +170,18 @@ sub swallow_heredocs {
169170
my $tags = $self->{heretags};
170171
while (my $tag = shift @$tags) {
171172
my $start = pos($$b);
172-
my $indent = $tag =~ s/^\t// ? '\\s*' : '';
173-
$$b =~ /(?:\G|\n)$indent\Q$tag\E(?:\n|\z)/gc;
173+
my $indent = $$tag[0] =~ s/^\t// ? '\\s*' : '';
174+
$$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc;
175+
if (pos($$b) > $start) {
176+
my $body = substr($$b, $start, pos($$b) - $start);
177+
$self->{lineno} += () = $body =~ /\n/sg;
178+
next;
179+
}
180+
push(@{$self->{parser}->{problems}}, ['UNCLOSED-HEREDOC', $tag]);
181+
$$b =~ /(?:\G|\n).*\z/gc; # consume rest of input
174182
my $body = substr($$b, $start, pos($$b) - $start);
175183
$self->{lineno} += () = $body =~ /\n/sg;
184+
last;
176185
}
177186
}
178187

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
command_which_is_run &&
2+
cat >expect <<-\EOF ?!UNCLOSED-HEREDOC?! &&
3+
we forget to end the here-doc
4+
command_which_is_gobbled
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
command_which_is_run &&
2+
cat >expect <<-\EOF &&
3+
we forget to end the here-doc
4+
command_which_is_gobbled

t/chainlint/unclosed-here-doc.expect

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
command_which_is_run &&
2+
cat >expect <<\EOF ?!UNCLOSED-HEREDOC?! &&
3+
we try to end the here-doc below,
4+
but the indentation throws us off
5+
since the operator is not "<<-".
6+
EOF
7+
command_which_is_gobbled

t/chainlint/unclosed-here-doc.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
command_which_is_run &&
2+
cat >expect <<\EOF &&
3+
we try to end the here-doc below,
4+
but the indentation throws us off
5+
since the operator is not "<<-".
6+
EOF
7+
command_which_is_gobbled

t/test-lib.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,7 @@ want_trace () {
10411041
# (and we want to make sure we run any cleanup like
10421042
# "set +x").
10431043
test_eval_inner_ () {
1044-
# Do not add anything extra (including LF) after '$*'
1045-
eval "
1046-
want_trace && trace_level_=$(($trace_level_+1)) && set -x
1047-
$*"
1044+
eval "$*"
10481045
}
10491046

10501047
test_eval_ () {
@@ -1069,7 +1066,10 @@ test_eval_ () {
10691066
# be _inside_ the block to avoid polluting the "set -x" output
10701067
#
10711068

1072-
test_eval_inner_ "$@" </dev/null >&3 2>&4
1069+
# Do not add anything extra (including LF) after '$*'
1070+
test_eval_inner_ </dev/null >&3 2>&4 "
1071+
want_trace && trace_level_=$(($trace_level_+1)) && set -x
1072+
$*"
10731073
{
10741074
test_eval_ret_=$?
10751075
if want_trace
@@ -1086,22 +1086,22 @@ test_eval_ () {
10861086
return $test_eval_ret_
10871087
}
10881088

1089+
fail_117 () {
1090+
return 117
1091+
}
1092+
10891093
test_run_ () {
10901094
test_cleanup=:
10911095
expecting_failure=$2
10921096

10931097
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then
1094-
# turn off tracing for this test-eval, as it simply creates
1095-
# confusing noise in the "-x" output
1096-
trace_tmp=$trace
1097-
trace=
10981098
# 117 is magic because it is unlikely to match the exit
10991099
# code of other programs
1100-
if test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)"
1100+
test_eval_inner_ "fail_117 && $1" </dev/null >&3 2>&4
1101+
if test $? != 117
11011102
then
1102-
BUG "broken &&-chain or run-away HERE-DOC: $1"
1103+
BUG "broken &&-chain: $1"
11031104
fi
1104-
trace=$trace_tmp
11051105
fi
11061106

11071107
setup_malloc_check
@@ -1593,7 +1593,8 @@ then
15931593
BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK "GIT_TEST_SANITIZE_LEAK_LOG=true"
15941594
fi
15951595

1596-
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0
1596+
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0 &&
1597+
test "${GIT_TEST_EXT_CHAIN_LINT:-1}" != 0
15971598
then
15981599
"$PERL_PATH" "$TEST_DIRECTORY/chainlint.pl" "$0" ||
15991600
BUG "lint error (see '?!...!? annotations above)"

0 commit comments

Comments
 (0)