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:
commit
0b94009649
@ -44,8 +44,8 @@ CHAINLINT = '$(PERL_PATH_SQ)' chainlint.pl
|
|||||||
|
|
||||||
# `test-chainlint` (which is a dependency of `test-lint`, `test` and `prove`)
|
# `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
|
# checks all tests in all scripts via a single invocation, so tell individual
|
||||||
# scripts not to "chainlint" themselves
|
# scripts not to run the external "chainlint.pl" script themselves
|
||||||
CHAINLINTSUPPRESS = GIT_TEST_CHAIN_LINT=0 && export GIT_TEST_CHAIN_LINT &&
|
CHAINLINTSUPPRESS = GIT_TEST_EXT_CHAIN_LINT=0 && export GIT_TEST_EXT_CHAIN_LINT &&
|
||||||
|
|
||||||
all: $(DEFAULT_TEST_TARGET)
|
all: $(DEFAULT_TEST_TARGET)
|
||||||
|
|
||||||
|
@ -80,7 +80,8 @@ sub scan_heredoc_tag {
|
|||||||
return "<<$indented" unless $token;
|
return "<<$indented" unless $token;
|
||||||
my $tag = $token->[0];
|
my $tag = $token->[0];
|
||||||
$tag =~ s/['"\\]//g;
|
$tag =~ s/['"\\]//g;
|
||||||
push(@{$self->{heretags}}, $indented ? "\t$tag" : "$tag");
|
$$token[0] = $indented ? "\t$tag" : "$tag";
|
||||||
|
push(@{$self->{heretags}}, $token);
|
||||||
return "<<$indented$tag";
|
return "<<$indented$tag";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,10 +170,18 @@ sub swallow_heredocs {
|
|||||||
my $tags = $self->{heretags};
|
my $tags = $self->{heretags};
|
||||||
while (my $tag = shift @$tags) {
|
while (my $tag = shift @$tags) {
|
||||||
my $start = pos($$b);
|
my $start = pos($$b);
|
||||||
my $indent = $tag =~ s/^\t// ? '\\s*' : '';
|
my $indent = $$tag[0] =~ s/^\t// ? '\\s*' : '';
|
||||||
$$b =~ /(?:\G|\n)$indent\Q$tag\E(?:\n|\z)/gc;
|
$$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);
|
my $body = substr($$b, $start, pos($$b) - $start);
|
||||||
$self->{lineno} += () = $body =~ /\n/sg;
|
$self->{lineno} += () = $body =~ /\n/sg;
|
||||||
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
t/chainlint/unclosed-here-doc-indent.expect
Normal file
4
t/chainlint/unclosed-here-doc-indent.expect
Normal 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
|
4
t/chainlint/unclosed-here-doc-indent.test
Normal file
4
t/chainlint/unclosed-here-doc-indent.test
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
command_which_is_run &&
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
we forget to end the here-doc
|
||||||
|
command_which_is_gobbled
|
7
t/chainlint/unclosed-here-doc.expect
Normal file
7
t/chainlint/unclosed-here-doc.expect
Normal 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
|
7
t/chainlint/unclosed-here-doc.test
Normal file
7
t/chainlint/unclosed-here-doc.test
Normal 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
|
@ -1041,10 +1041,7 @@ want_trace () {
|
|||||||
# (and we want to make sure we run any cleanup like
|
# (and we want to make sure we run any cleanup like
|
||||||
# "set +x").
|
# "set +x").
|
||||||
test_eval_inner_ () {
|
test_eval_inner_ () {
|
||||||
# Do not add anything extra (including LF) after '$*'
|
eval "$*"
|
||||||
eval "
|
|
||||||
want_trace && trace_level_=$(($trace_level_+1)) && set -x
|
|
||||||
$*"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_eval_ () {
|
test_eval_ () {
|
||||||
@ -1069,7 +1066,10 @@ test_eval_ () {
|
|||||||
# be _inside_ the block to avoid polluting the "set -x" output
|
# 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_=$?
|
test_eval_ret_=$?
|
||||||
if want_trace
|
if want_trace
|
||||||
@ -1086,22 +1086,22 @@ test_eval_ () {
|
|||||||
return $test_eval_ret_
|
return $test_eval_ret_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail_117 () {
|
||||||
|
return 117
|
||||||
|
}
|
||||||
|
|
||||||
test_run_ () {
|
test_run_ () {
|
||||||
test_cleanup=:
|
test_cleanup=:
|
||||||
expecting_failure=$2
|
expecting_failure=$2
|
||||||
|
|
||||||
if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then
|
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
|
# 117 is magic because it is unlikely to match the exit
|
||||||
# code of other programs
|
# 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
|
then
|
||||||
BUG "broken &&-chain or run-away HERE-DOC: $1"
|
BUG "broken &&-chain: $1"
|
||||||
fi
|
fi
|
||||||
trace=$trace_tmp
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setup_malloc_check
|
setup_malloc_check
|
||||||
@ -1593,7 +1593,8 @@ then
|
|||||||
BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK "GIT_TEST_SANITIZE_LEAK_LOG=true"
|
BAIL_OUT_ENV_NEEDS_SANITIZE_LEAK "GIT_TEST_SANITIZE_LEAK_LOG=true"
|
||||||
fi
|
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
|
then
|
||||||
"$PERL_PATH" "$TEST_DIRECTORY/chainlint.pl" "$0" ||
|
"$PERL_PATH" "$TEST_DIRECTORY/chainlint.pl" "$0" ||
|
||||||
BUG "lint error (see '?!...!? annotations above)"
|
BUG "lint error (see '?!...!? annotations above)"
|
||||||
|
Loading…
Reference in New Issue
Block a user