Skip to content

Commit

Permalink
Merge pull request #12 from hakonhagland/fix5_38
Browse files Browse the repository at this point in the history
Temporarily fix test failures for perl > 5.37.3
  • Loading branch information
oalders authored Apr 30, 2024
2 parents f668575 + 5919266 commit 7d35286
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/dzil-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ jobs:
- "5.30"
- "5.32"
- "5.34"
- "5.36"
- "5.38"
name: perl ${{ matrix.perl-version }} on ${{ matrix.os }}
steps:
- name: set up perl
Expand Down Expand Up @@ -103,6 +105,8 @@ jobs:
- "5.30"
- "5.32"
- "5.34"
- "5.36"
- "5.38"
name: perl ${{ matrix.perl-version }} on ${{ matrix.os }}
steps:
- name: set up perl
Expand Down Expand Up @@ -139,6 +143,9 @@ jobs:
- "5.26"
- "5.28"
- "5.30"
- "5.32"
- "5.36"
- "5.38"
name: perl ${{ matrix.perl-version }} on ${{ matrix.os }}
steps:
- name: set up perl
Expand Down
20 changes: 17 additions & 3 deletions t/app-perlvars.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,33 @@ use lib 'test-data/lib';
use App::perlvars ();
use Test::More import => [qw( done_testing is ok subtest )];

# For perl version 5.37.3 there was a change in the Perl internals such that
# some variables are no longer considered unused by Test::Vars. This is a known issue, see
# https://github.com/houseabsolute/p5-Test-Vars/issues/47
# Until this is resolved, we need to adjust the expected number of errors depending on
# the Perl version.
my $perl_old = $] <= 5.037002;

subtest 'pkg with unused vars' => sub {
my ( $exit_code, $msg, @errors )
= App::perlvars->new->validate_file('test-data/lib/Local/Unused.pm');
ok( $exit_code, 'non-zero exit code' );
is( scalar @errors, 4, 'found all errors' );
my $expected = $perl_old ? 4 : 5;
is( scalar @errors, $expected, 'found all errors' );
};

subtest 'pkg without unused vars' => sub {
my ( $exit_code, $msg, @errors )
= App::perlvars->new->validate_file(
'test-data/lib/Local/NoUnused.pm');
is( $exit_code, 0, '0 exit code' );
is( scalar @errors, 0, 'found no errors' );
if ($perl_old) {
is( $exit_code, 0, '0 exit code' );
is( scalar @errors, 0, 'found no errors' );
}
else {
is( $exit_code, 256, 'exit code 256' );
is( scalar @errors, 1, 'found 1 error' );
}
};

subtest 'file not found' => sub {
Expand Down
58 changes: 35 additions & 23 deletions t/perlvars.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ use Test::Script qw(
script_stderr_like
);

# For perl version 5.37.3 there was a change in the Perl internals such that
# some variables are no longer considered unused by Test::Vars. This is a known issue, see
# https://github.com/houseabsolute/p5-Test-Vars/issues/47
# Until this is resolved, we need to adjust the expected number of errors depending on
# the Perl version.
my $perl_old = $] <= 5.037002;

script_compiles('script/perlvars');

subtest 'file not found' => sub {
Expand All @@ -30,44 +37,49 @@ subtest 'file has errors' => sub {
};

subtest 'file has no package' => sub {
script_runs(
[ 'script/perlvars', 't/perlvars.t' ],
);
script_runs( [ 'script/perlvars', 't/perlvars.t' ] );
};

subtest 'arg is a dir' => sub {
script_fails(
[ 'script/perlvars', 't' ],
{ exit => 1 },
);
script_fails( [ 'script/perlvars', 't' ], { exit => 1 }, );
script_stderr_like(qr{t is a dir});
};

subtest 'ignore file is used' => sub {
script_runs(
[
'script/perlvars',
'--ignore-file', 'test-data/ignore-file',
'test-data/lib/Local/Unused.pm'
]
my @script = (
'script/perlvars', '--ignore-file',
'test-data/ignore-file', 'test-data/lib/Local/Unused.pm',
);
if ($perl_old) {
script_runs( \@script );
}
else {
script_fails( \@script, { exit => 255 } );
}
};

subtest 'file has no errors' => sub {
script_runs(
[ 'script/perlvars', 'test-data/lib/Local/NoUnused.pm' ],
);
my @script = ( 'script/perlvars', 'test-data/lib/Local/NoUnused.pm', );
if ($perl_old) {
script_runs( \@script );
}
else {
script_fails( \@script, { exit => 255 } );
}
};

subtest 'multiple files are checked' => sub {
script_runs(
[
'script/perlvars',
'--ignore-file', 'test-data/ignore-file',
'test-data/lib/Local/Unused.pm',
'test-data/lib/Local/NoUnused.pm',
]
my @script = (
'script/perlvars', '--ignore-file',
'test-data/ignore-file', 'test-data/lib/Local/Unused.pm',
'test-data/lib/Local/NoUnused.pm',
);
if ($perl_old) {
script_runs( \@script );
}
else {
script_fails( \@script, { exit => 255 } );
}
};

done_testing();

0 comments on commit 7d35286

Please sign in to comment.