summaryrefslogtreecommitdiffstats
path: root/t/scripts/01-critic/runner.pl
blob: 27f7b8374f9be9112f268dbc6ad86b2c371d18a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl

# Simple critic test runner that guesses it task from $0.
# NB: If you change anything in this script, consider if
# others.t need an update as well.

use strict;
use warnings;

use Const::Fast;
use IPC::Run3;
use POSIX qw(ENOENT);

use
  if $ENV{'LINTIAN_COVERAGE'}, 'Test::More',
  'skip_all' => 'Not needed for coverage of Lintian';

use Test::Lintian;
use Test::More;

plan skip_all => 'Only UNRELEASED versions are criticised'
  if should_skip();

eval 'use Test::Perl::Critic 1.00';
plan skip_all => 'Test::Perl::Critic 1.00 required to run this test' if $@;

eval 'use Perl::Tidy 20181120';
# Actually we could just disable the perltidy check, but I am not
# sure how to do that without making it ignore our perlcriticrc file.
plan skip_all => 'Perl::Tidy 20180220 required to run this test' if $@;

eval 'use PPIx::Regexp';
diag('libppix-regexp-perl is needed to enable some checks') if $@;

const my $DOT => q{.};

my @test_paths = program_name_to_perl_paths($0);
$ENV{'LINTIAN_BASE'} //= $DOT;
my $critic_profile = "$ENV{'LINTIAN_BASE'}/.perlcriticrc";
Test::Perl::Critic->import(-profile => $critic_profile);

run_critic(@test_paths);

exit(0);

sub run_critic {
    my (@args) = @_;

    all_critic_ok(@args);

    # For some reason, perltidy has started to leave behind a
    # "perltidy.LOG" which is rather annoying.  Lets have the tests
    # unconditionally kill those.
    my $err = unlink('perltidy.LOG');
    if ($err) {
        # Since this test is run in parallel, there is an
        # race-condition between checking for the file and actually
        # deleting.  So just remove the file and ignore ENOENT
        # problems.
        die($err) if $err->errno != ENOENT;
    }
    return 1;
}

sub should_skip {
    my $skip = 1;

    my @command = qw{dpkg-parsechangelog -c0};
    my $output;

    run3(\@command, \undef, \$output);

    $skip = 0
      if $output =~ /^Distribution: UNRELEASED$/m;

    return $skip;
}

# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et