Test-More / Test2-Harness

Alternative to Test::Harness
Other
23 stars 26 forks source link

`-w` sometimes is set when it shouldn't #266

Closed dakkar closed 1 year ago

dakkar commented 1 year ago

Given these two small test files:

a.t:

#!perl -w
use Test2::V0;
ok($^W,'-w should be honoured');
done_testing;

b.t:

#!perl
use Test2::V0;
ok(!$^W,'-w should not leak');
done_testing;

and yath from Test2::Harness 1.000150, this happens:

running verbosely, I can see that, only in the last case, b.t is run under perl -w (a.t is always run under perl -w, as expected)

removing the shebang from b.t makes the problem disappear.

-j1 / -j2 doesn't make any difference, nor does running under a persistent runner.

dakkar commented 1 year ago

turns out that the source of the problem was the line my @switches = grep { m/\S/ } split /\s+/, $1 if defined $1 in TestFile.pm, which caused the @switches array to be shared between invocations of the sub, thus leaking between test files

dakkar commented 1 year ago

see also https://github.com/Perl/perl5/issues/21154

atoomic commented 1 year ago

nice state variable for free :-)