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"
This commit is contained in:
Junio C Hamano 2023-04-06 13:38:31 -07:00
commit 0b94009649
7 changed files with 50 additions and 18 deletions

View File

@ -44,8 +44,8 @@ CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
# `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
# checks all tests in all scripts via a single invocation, so tell individual
# scripts not to "chainlint" themselves
CHAINLINTSUPPRESS = GIT_TEST_CHAIN_LINT=0 && export GIT_TEST_CHAIN_LINT &&
# scripts not to run the external "chainlint.pl" script themselves
CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT &&
all: $(DEFAULT_TEST_TARGET)

View File

@ -80,7 +80,8 @@ sub scan_heredoc_tag {
return "<<$indented" unless $token;
my $tag = $token->[0];
$tag =~ s/['"\\]//g;
push(@{$self->{heretags}}, $indented ? "\t$tag" : "$tag");
$$token[0] = $indented ? "\t$tag" : "$tag";
push(@{$self->{heretags}}, $token);
return "<<$indented$tag";
}
@ -169,10 +170,18 @@ sub swallow_heredocs {
my $tags = $self->{heretags};
while (my $tag = shift @$tags) {
my $start = pos($$b);
my $indent = $tag =~ s/^\t// ? '\\s*' : '';
$$b =~ /(?:\G|\n)$indent\Q$tag\E(?:\n|\z)/gc;
my $indent = $$tag[0] =~ s/^\t// ? '\\s*' : '';
$$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc;
if (pos($$b) > $start) {
my $body = substr($$b, $start, pos($$b) - $start);
$self->{lineno} += () = $body =~ /\n/sg;
next;
}
push(@{$self->{parser}->{problems}}, ['UNCLOSED-HEREDOC', $tag]);
$$b =~ /(?:\G|\n).*\z/gc; # consume rest of input
my $body = substr($$b, $start, pos($$b) - $start);
$self->{lineno} += () = $body =~ /\n/sg;
last;
}
}

View File

@ -0,0 +1,4 @@
command_which_is_run &&
cat >expect <<-\EOF ?!UNCLOSED-HEREDOC?! &&
we forget to end the here-doc
command_which_is_gobbled

View File

@ -0,0 +1,4 @@
command_which_is_run &&
cat >expect <<-\EOF &&
we forget to end the here-doc
command_which_is_gobbled

View File

@ -0,0 +1,7 @@
command_which_is_run &&
cat >expect <<\EOF ?!UNCLOSED-HEREDOC?! &&
we try to end the here-doc below,
but the indentation throws us off
since the operator is not "<<-".
EOF
command_which_is_gobbled

View File

@ -0,0 +1,7 @@
command_which_is_run &&
cat >expect <<\EOF &&
we try to end the here-doc below,
but the indentation throws us off
since the operator is not "<<-".
EOF
command_which_is_gobbled

View File

@ -1041,10 +1041,7 @@ want_trace () {
# (and we want to make sure we run any cleanup like
# "set +x").
test_eval_inner_ () {
# Do not add anything extra (including LF) after '$*'
eval "
want_trace && trace_level_=$(($trace_level_+1)) && set -x
$*"
eval "$*"
}
test_eval_ () {
@ -1069,7 +1066,10 @@ test_eval_ () {
# be _inside_ the block to avoid polluting the "set -x" output
#
test_eval_inner_ "$@" </dev/null >&3 2>&4
# Do not add anything extra (including LF) after '$*'
test_eval_inner_ </dev/null >&3 2>&4 "
want_trace && trace_level_=$(($trace_level_+1)) && set -x
$*"
{
test_eval_ret_=$?
if want_trace
@ -1086,22 +1086,22 @@ test_eval_ () {
return $test_eval_ret_
}
fail_117 () {
return 117
}
test_run_ () {
test_cleanup=:
expecting_failure=$2
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then
# turn off tracing for this test-eval, as it simply creates
# confusing noise in the "-x" output
trace_tmp=$trace
trace=
# 117 is magic because it is unlikely to match the exit
# code of other programs
if test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)"
test_eval_inner_ "fail_117 && $1" </dev/null >&3 2>&4
if test $? != 117
then
BUG "broken &&-chain or run-away HERE-DOC: $1"
BUG "broken &&-chain: $1"
fi
trace=$trace_tmp
fi
setup_malloc_check
@ -1593,7 +1593,8 @@ then
BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK "GIT_TEST_SANITIZE_LEAK_LOG=true"
fi
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0 &&
test "${GIT_TEST_EXT_CHAIN_LINT:-1}" != 0
then
"$PERL_PATH" "$TEST_DIRECTORY/chainlint.pl" "$0" ||
BUG "lint error (see '?!...!? annotations above)"