This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade HTTP::Tiny to 0.017.
[perl5.git] / cpan / HTTP-Tiny / t / 00-compile.t
CommitLineData
a3ab329f 1#!perl
a3ab329f
DG
2
3use strict;
4use warnings;
5
6use Test::More;
7
8
9
10use File::Find;
11use File::Temp qw{ tempdir };
12
13my @modules;
14find(
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
4984624c
A
27sub _find_scripts {
28 my $dir = shift @_;
29
30 my @found_scripts = ();
77ccfaeb
DG
31 find(
32 sub {
33 return unless -f;
34 my $found = $File::Find::name;
35 # nothing to skip
4984624c
A
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;
77ccfaeb 43 },
4984624c 44 $dir,
77ccfaeb 45 );
4984624c
A
46
47 return @found_scripts;
77ccfaeb 48}
a3ab329f 49
4984624c
A
50my @scripts;
51do { push @scripts, _find_scripts($_) if -d $_ }
52 for qw{ bin script scripts };
53
a3ab329f
DG
54my $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 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}