File: prove-prereqs.pl

package info (click to toggle)
libcgi-application-plugin-anytemplate-perl 0.18-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 772 kB
  • sloc: perl: 1,073; sh: 8; makefile: 2
file content (101 lines) | stat: -rwxr-xr-x 2,845 bytes parent folder | download | duplicates (4)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/perl

=pod

This script allows you to run the test suite, simulating the absense of
a particular set of Perl modules, even if they are installed on your
system.

To run the test suite multiple times in a row (each with a different 
selection of absent modules), run:

    $ perl misc/prove_prereqs.pl t/prereq_scenarios -Ilib t/

To add a new set of absent modules, make a subdir under t/prereq_scenarios, 
and add a dummy perl module for every module you want to skip.  This file
should be empty.  For instance if you wanted to simulate the absense of
Text::Template and Text::TagTemplate, you would do the following:

    $ mkdir t/prereq_scenarios/skip_tt+ttt
    $ mkdir t/prereq_scenarios/skip_tt+ttt/Text
    $ touch t/prereq_scenarios/skip_tt+ttt/Text/Template.pm
    $ touch t/prereq_scenarios/skip_tt+ttt/Text/TagTemplate.pm

Note that this technique only works because of how AnyTemplate and its
test suite are written.  The AnyTemplate drivers each provide a method
returning the list of modules they depend on.  Each test script gets the
list of modules and attempts to load them:

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

If any of the modules fail to load, then the test script skips the tests
associated with that module.

=cut

use strict;
use warnings;

use File::Find;

unless (@ARGV > 1) {
    die "Usage: $0 [prereq_scenarios_dir] [args to prove]\n";
}

my $scenarios_dir = shift;

my %scenario_modules;
my $errors;

my @scenarios = grep { -d } <$scenarios_dir/*>;
foreach my $lib_dir (@scenarios) {
    if (!-d $lib_dir) {
        $errors = 1;
        warn "lib dir does not exist: $lib_dir\n";
        next;
    }
    my @modules;
    find(sub {
        return unless -f;
        my $dir = "$File::Find::dir/$_";
        $dir =~ s/^\Q$lib_dir\E//;
        $dir =~ s/\.pm$//;
        $dir =~ s{^/}{};
        $dir =~ s{/}{::}g;
        push @modules, $dir;
    }, $lib_dir);
    $scenario_modules{$lib_dir} = \@modules;
}
die "Terminating." if $errors;

foreach my $lib_dir (@scenarios) {
    my $modules = join ', ', sort @{ $scenario_modules{$lib_dir} };
    $modules ||= 'none';
    print "\n##############################################################\n";
    print "Running tests.  Old (or absent) modules in this scenario:\n";
    print "$modules\n";
    my @prove_command = ('prove', '-Ilib', "-I$lib_dir", @ARGV);
    system(@prove_command) && do {
        die <<EOF;
##############################################################
One or more tests failed in scenario $lib_dir.
The old or absent modules were:
    $modules

The command was:
    @prove_command

Terminating.
##############################################################
EOF
    };
}