]> git.donarmstrong.com Git - liborg-parser-perl.git/blob - t/00-compile.t
Import original source of Org-Parser 0.23
[liborg-parser-perl.git] / t / 00-compile.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8
9
10 use File::Find;
11 use File::Temp qw{ tempdir };
12
13 my @modules;
14 find(
15   sub {
16     return if $File::Find::name !~ /\.pm\z/;
17     my $found = $File::Find::name;
18     $found =~ s{^lib/}{};
19     $found =~ s{[/\\]}{::}g;
20     $found =~ s/\.pm$//;
21     # nothing to skip
22     push @modules, $found;
23   },
24   'lib',
25 );
26
27 sub _find_scripts {
28     my $dir = shift @_;
29
30     my @found_scripts = ();
31     find(
32       sub {
33         return unless -f;
34         my $found = $File::Find::name;
35         # nothing to skip
36         open my $FH, '<', $_ or do {
37           note( "Unable to open $found in ( $! ), skipping" );
38           return;
39         };
40         my $shebang = <$FH>;
41         return unless $shebang =~ /^#!.*?\bperl\b\s*$/;
42         push @found_scripts, $found;
43       },
44       $dir,
45     );
46
47     return @found_scripts;
48 }
49
50 my @scripts;
51 do { push @scripts, _find_scripts($_) if -d $_ }
52     for qw{ bin script scripts };
53
54 my $plan = scalar(@modules) + scalar(@scripts);
55 $plan ? (plan tests => $plan) : (plan skip_all => "no tests to run");
56
57 {
58     # fake home for cpan-testers
59     # no fake requested ## local $ENV{HOME} = tempdir( CLEANUP => 1 );
60
61     like( qx{ $^X -Ilib -e "require $_; print '$_ ok'" }, qr/^\s*$_ ok/s, "$_ loaded ok" )
62         for sort @modules;
63
64     SKIP: {
65         eval "use Test::Script 1.05; 1;";
66         skip "Test::Script needed to test script compilation", scalar(@scripts) if $@;
67         foreach my $file ( @scripts ) {
68             my $script = $file;
69             $script =~ s!.*/!!;
70             script_compiles( $file, "$script script compiles" );
71         }
72     }
73 }