| 1 | #!/usr/bin/perl -w | ||||||||||
| 2 | # rocco // vim: ts=2 sw=2 expandtab | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use File::Path; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.2
| |||||||||||
| 9 | 1 | eval "require POE::Test::Loops"; | |||||||||
| 10 | 1 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 11 | 0 | warn "Could not load POE::Test::Loops. Skipping loop tests"; | |||||||||
| 12 | 0 | exit; | |||||||||
| 13 | } | ||||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 1 | my $test_base = "t"; | |||||||||
| 17 | |||||||||||
| 18 | ### Resources, and their perl and XS implementations. | ||||||||||
| 19 | |||||||||||
| 20 | { | ||||||||||
| 21 | 1 | my $base_dir = File::Spec->catfile($test_base, "20_resources"); | |||||||||
| 22 | 1 | my $base_lib = File::Spec->catfile($base_dir, "00_base"); | |||||||||
| 23 | |||||||||||
| 24 | 1 | my %derived_conf = ( | |||||||||
| 25 | "10_perl" => { implementation => "perl" }, | ||||||||||
| 26 | # TODO - Enable when an XS implementation arrives. | ||||||||||
| 27 | # "20_xs" => { implementation => "xs" }, | ||||||||||
| 28 | ); | ||||||||||
| 29 | |||||||||||
| 30 | 1 | my $source = ( | |||||||||
| 31 | "#!/usr/bin/perl -w\n" . | ||||||||||
| 32 | "\n" . | ||||||||||
| 33 | "use strict;\n" . | ||||||||||
| 34 | "use lib qw(--base_lib--);\n" . | ||||||||||
| 35 | "use Test::More;\n" . | ||||||||||
| 36 | "\n" . | ||||||||||
| 37 | "\$ENV{POE_IMPLEMENTATION} = '--implementation--';\n" . | ||||||||||
| 38 | "\n" . | ||||||||||
| 39 | "require '--base_file--';\n" . | ||||||||||
| 40 | "\n" . | ||||||||||
| 41 | "CORE::exit 0;\n" | ||||||||||
| 42 | ); | ||||||||||
| 43 | |||||||||||
| 44 | 1 | derive_files( | |||||||||
| 45 | base_dir => $base_dir, | ||||||||||
| 46 | base_lib => $base_lib, | ||||||||||
| 47 | derived_conf => \%derived_conf, | ||||||||||
| 48 | src_template => $source, | ||||||||||
| 49 | ); | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | ### Event loops and the tests that love them. | ||||||||||
| 53 | |||||||||||
| 54 | { | ||||||||||
| 55 | 1 | my $base_dir = File::Spec->catfile($test_base, "30_loops"); | |||||||||
| 56 | |||||||||||
| 57 | 1 | my @loops = qw(Select IO::Poll); | |||||||||
| 58 | 1 | POE::Test::Loops::generate($base_dir, \@loops); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | exit 0; | |||||||||
| 62 | |||||||||||
| 63 | 1 | ▶ | sub derive_files { | ||||||||
|
Subroutine
derive_files: called CC=7 SCAR=19.5
| |||||||||||
| 64 | 1 | my %conf = @_; | |||||||||
| 65 | |||||||||||
| 66 | 1 | my $base_dir = $conf{base_dir}; | |||||||||
| 67 | |||||||||||
| 68 | # Gather the list of base files. Each will be used to generate a | ||||||||||
| 69 | # real test file. | ||||||||||
| 70 | |||||||||||
| 71 | 1 | ▶ | opendir BASE, $conf{base_lib} or die $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 1 | my @base_files = grep /\.pm$/, readdir(BASE); | |||||||||
| 73 | 1 | closedir BASE; | |||||||||
| 74 | |||||||||||
| 75 | # Generate a set of test files for each configuration. | ||||||||||
| 76 | |||||||||||
| 77 | 1 | foreach my $dst_dir (keys %{$conf{derived_conf}}) { | |||||||||
| 78 | 1 | my $full_dst = File::Spec->catfile($base_dir, $dst_dir); | |||||||||
| 79 | 1 | $full_dst =~ tr[/][/]s; | |||||||||
| 80 | 1 | $full_dst =~ s{/+$}{}; | |||||||||
| 81 | |||||||||||
| 82 | 1 | my %template_conf = %{$conf{derived_conf}{$dst_dir}}; | |||||||||
| 83 | |||||||||||
| 84 | # Blow away any previously generated test files. | ||||||||||
| 85 | |||||||||||
| 86 | 1 | rmtree($full_dst); | |||||||||
| 87 | 1 | mkpath($full_dst, 0, 0755); | |||||||||
| 88 | |||||||||||
| 89 | # For each base file, generate a corresponding one in the | ||||||||||
| 90 | # configured destination directory. Expand various bits to | ||||||||||
| 91 | # customize the test. | ||||||||||
| 92 | |||||||||||
| 93 | 1 | foreach my $base_file (@base_files) { | |||||||||
| 94 | 9 | my $full_file = File::Spec->catfile($full_dst, $base_file); | |||||||||
| 95 | 9 | $full_file =~ s/\.pm$/.t/; | |||||||||
| 96 | |||||||||||
| 97 | # These hardcoded expansions are for the base file to be | ||||||||||
| 98 | # required, and the base library directory where it'll be found. | ||||||||||
| 99 | |||||||||||
| 100 | 9 | my $expanded_src = $conf{src_template}; | |||||||||
| 101 | 9 | $expanded_src =~ s/--base_file--/$base_file/g; | |||||||||
| 102 | 9 | $expanded_src =~ s/--base_lib--/$conf{base_lib}/g; | |||||||||
| 103 | |||||||||||
| 104 | # The others are plugged in from the directory configuration. | ||||||||||
| 105 | |||||||||||
| 106 | 9 | ▶ | while (my ($key, $val) = each %template_conf) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | 9 | $expanded_src =~ s/--\Q$key\E--/$val/g; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | # Write with lots of error checking. | ||||||||||
| 111 | |||||||||||
| 112 | 9 | ▶ | open EXPANDED, ">$full_file" or die $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 9 | print EXPANDED $expanded_src; | |||||||||
| 114 | 9 | ▶ | close EXPANDED or die $!; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | } | ||||||||||
| 116 | } | ||||||||||
| 117 | } | ||||||||||