| 1 |
use Test2::V0 -no_srand => 1; |
| 2 |
use Test2::Require::EnvVar 'FFI_PLATYPUS_TEST_EXAMPLES'; |
| 3 |
|
| 4 |
BEGIN { |
| 5 |
eval { |
| 6 |
require FFI::Platypus; |
| 7 |
FFI::Platypus->VERSION('2.00'); |
| 8 |
require Convert::Binary::C; |
| 9 |
require YAML; |
| 10 |
require Capture::Tiny; |
| 11 |
Capture::Tiny->import('capture_merged'); |
| 12 |
require Path::Tiny; |
| 13 |
Path::Tiny->import('path'); |
| 14 |
require File::chdir; |
| 15 |
File::chdir->import(); |
| 16 |
require Test::Script; |
| 17 |
Test::Script->import('script_compiles'); |
| 18 |
require FFI::C; |
| 19 |
}; |
| 20 |
|
| 21 |
if($@) |
| 22 |
{ |
| 23 |
note "error = $@"; |
| 24 |
skip_all 'Test requires FFI::Platypus 2.00, Capture::Tiny, Test::Script, Path::Tiny, Convert::Binary::C, File::chdir, FFI:C and YAML'; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
my @skipped; |
| 29 |
|
| 30 |
foreach my $dir (qw( examples )) |
| 31 |
{ |
| 32 |
subtest "$dir" => sub { |
| 33 |
|
| 34 |
local $CWD = $dir; |
| 35 |
|
| 36 |
my @c_source = grep { $_->basename =~ /\.c$/ } path('.')->children; |
| 37 |
|
| 38 |
if(@c_source) |
| 39 |
{ |
| 40 |
subtest 'Compile C' => sub { |
| 41 |
foreach my $c_source (@c_source) |
| 42 |
{ |
| 43 |
my $so_file = $c_source->parent->child(do { |
| 44 |
my $basename = $c_source->basename; |
| 45 |
$basename =~ s/\.c$/.so/; |
| 46 |
$basename; |
| 47 |
}); |
| 48 |
my @cmd = ('cc', '-fPIC', '-shared', -o => "$so_file", "$c_source"); |
| 49 |
my($out, $ret) = capture_merged { |
| 50 |
system @cmd; |
| 51 |
}; |
| 52 |
|
| 53 |
ok $ret == 0, "@cmd"; |
| 54 |
if($ret == 0) |
| 55 |
{ |
| 56 |
note $out if $out ne ''; |
| 57 |
} |
| 58 |
else |
| 59 |
{ |
| 60 |
diag $out if $out ne ''; |
| 61 |
} |
| 62 |
} |
| 63 |
}; |
| 64 |
} |
| 65 |
|
| 66 |
my @pl_source = grep { $_->basename =~ /\.pl$/ } path('.')->children; |
| 67 |
|
| 68 |
if(@pl_source) |
| 69 |
{ |
| 70 |
subtest 'Run Perl' => sub { |
| 71 |
|
| 72 |
foreach my $pl_source (@pl_source) |
| 73 |
{ |
| 74 |
subtest "$pl_source" => sub { |
| 75 |
|
| 76 |
script_compiles "$pl_source"; |
| 77 |
|
| 78 |
my $key = join '/', $dir, $pl_source->basename; |
| 79 |
|
| 80 |
if($^O ne 'MSWin32' && $pl_source->basename =~ /^win32_/) |
| 81 |
{ |
| 82 |
push @skipped, [$key, 'Microsoft Windows Only']; |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
my @cmd = ($^X, $pl_source); |
| 87 |
my($out, $ret) = capture_merged { |
| 88 |
system @cmd; |
| 89 |
}; |
| 90 |
|
| 91 |
ok $ret == 0, "@cmd"; |
| 92 |
if($ret == 0) |
| 93 |
{ |
| 94 |
note $out if $out ne ''; |
| 95 |
} |
| 96 |
else |
| 97 |
{ |
| 98 |
diag $out if $out ne ''; |
| 99 |
} |
| 100 |
}; |
| 101 |
} |
| 102 |
|
| 103 |
}; |
| 104 |
} |
| 105 |
|
| 106 |
unlink $_ for grep { $_->basename =~ /\.so$/ || $_->basename =~ /^zmq-ffi-/ } path('.')->children; |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
|
| 112 |
foreach my $bundle (grep { -d $_ && $_->basename =~ /^bundle-/ } path('examples')->children) |
| 113 |
{ |
| 114 |
if($bundle->basename eq 'bundle-bzip2' && !eval { require Alien::Libbz2; 1 }) |
| 115 |
{ |
| 116 |
push @skipped, [$bundle->basename, 'Alien::Libbz2 is not installed']; |
| 117 |
next; |
| 118 |
} |
| 119 |
|
| 120 |
subtest $bundle->basename => sub { |
| 121 |
|
| 122 |
local $CWD = $bundle; |
| 123 |
|
| 124 |
my @cmd = ('prove', '-lvm'); |
| 125 |
my($out, $ret) = capture_merged { |
| 126 |
system @cmd; |
| 127 |
}; |
| 128 |
|
| 129 |
ok $ret == 0, "@cmd"; |
| 130 |
if($ret == 0) |
| 131 |
{ |
| 132 |
note $out if $out ne ''; |
| 133 |
} |
| 134 |
else |
| 135 |
{ |
| 136 |
diag $out if $out ne ''; |
| 137 |
} |
| 138 |
}; |
| 139 |
} |
| 140 |
|
| 141 |
if(@skipped) |
| 142 |
{ |
| 143 |
diag ''; |
| 144 |
diag ''; |
| 145 |
diag ''; |
| 146 |
|
| 147 |
my $max = 5; |
| 148 |
foreach my $skip (@skipped) |
| 149 |
{ |
| 150 |
$max = length($skip->[0]) |
| 151 |
if $max < length($skip->[0]); |
| 152 |
} |
| 153 |
|
| 154 |
diag 'Skipped these examples:'; |
| 155 |
|
| 156 |
foreach my $skip (@skipped) |
| 157 |
{ |
| 158 |
diag sprintf "%-${max}s %s", $skip->[0], $skip->[1]; |
| 159 |
} |
| 160 |
|
| 161 |
diag ''; |
| 162 |
diag ''; |
| 163 |
} |
| 164 |
|
| 165 |
done_testing; |