File: examples.t

package info (click to toggle)
libffi-c-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 484 kB
  • sloc: perl: 1,517; ansic: 57; sh: 19; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,492 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
use Test2::V0 -no_srand => 1;
use Test2::Require::Module 'Test::Script';
use Test::Script;
use Path::Tiny qw( path );
use File::Glob qw( bsd_glob );
use Capture::Tiny qw( capture_merged );

skip_all 'not tested with ciperl:static' if defined $ENV{CIPSTATIC} && $ENV{CIPSTATIC} eq 'true';

$ENV{PERL5LIB} = path('corpus/examples/lib')->absolute;

my @dirs = qw( examples examples/synopsis );

is(
  do {
    my $lib;
    my($out) = capture_merged {
      require FFI::Build;
      my $build = FFI::Build->new(
        'main',
        dir => 'corpus/examples/arch/auto/main',
        verbose => 2,
      );
      $build->source(map { bsd_glob "$_/*.c" } @dirs);
      $lib = eval { $build->build };
    };
    note $out if $out ne '';

    my $txt = path('corpus/examples/arch/auto/main/main.txt');
    $txt->parent->mkpath;
    $txt->spew("FFI::Build\@" . path($lib->path)->relative('corpus/examples/lib')->stringify);

    $lib;
  },
  object {
    call [ isa => 'FFI::Build::File::Library' ] => T();
  },
  'build c example files',
);

foreach my $example (map { bsd_glob "$_/*.pl" } @dirs)
{
  my $basename = path($example)->basename;
  subtest $basename => sub {
    skip_all 'test requires Perl 5.14 or better'
      unless $basename ne 'c.pl' || $] >= 5.014;
    my $out = '';
    my $err = '';
    script_compiles $example;
    script_runs $example, { stdout => \$out, stderr => \$err };
    note "[out]\n$out" if $out ne '';
    note "[err]\n$err" if $err ne '';
  };
}

done_testing;