File: 00-compile.t

package info (click to toggle)
libdist-zilla-plugin-requiresexternal-perl 1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 220 kB
  • ctags: 6
  • sloc: perl: 712; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,562 bytes parent folder | download
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
#!perl

use strict;
use warnings;

use Test::More;

use File::Find;
use File::Temp qw{ tempdir };

my @modules;
find(
    sub {
        return if $File::Find::name !~ /\.pm\z/;
        my $found = $File::Find::name;
        $found =~ s{^lib/}{};
        $found =~ s{[/\\]}{::}g;
        $found =~ s/\.pm$//;

        # nothing to skip
        push @modules, $found;
    },
    'lib',
);

my @scripts;
if ( -d 'bin' ) {
    find(
        sub {
            return unless -f;
            my $found = $File::Find::name;

            # nothing to skip
            open my $FH, '<', $_ or do {
                note("Unable to open $found in ( $! ), skipping");
                return;
            };
            my $shebang = <$FH>;
            return unless $shebang =~ /^#!.*?\bperl\b\s*$/;
            push @scripts, $found;
        },
        'bin',
    );
}

my $plan = scalar(@modules) + scalar(@scripts);
$plan ? ( plan tests => $plan ) : ( plan skip_all => "no tests to run" );

{

    # fake home for cpan-testers
    # no fake requested ## local $ENV{HOME} = tempdir( CLEANUP => 1 );

    like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" },
        qr/^\s*$_ ok/s, "$_ loaded ok" )
        for sort @modules;

SKIP: {
        eval "use Test::Script 1.05; 1;";
        skip "Test::Script needed to test script compilation",
            scalar(@scripts)
            if $@;
        foreach my $file (@scripts) {
            my $script = $file;
            $script =~ s!.*/!!;
            script_compiles( $file, "$script script compiles" );
        }
    }
}