File: example.t

package info (click to toggle)
libffi-platypus-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,860 kB
  • sloc: perl: 7,388; ansic: 6,862; cpp: 53; sh: 19; makefile: 14
file content (159 lines) | stat: -rw-r--r-- 3,272 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use Test2::V0 -no_srand => 1;
use Test2::Require::EnvVar 'FFI_PLATYPUS_TEST_EXAMPLES';

BEGIN {
  eval {
    require FFI::Platypus;
    FFI::Platypus->VERSION('2.00');
    require Convert::Binary::C;
    require YAML;
    require Capture::Tiny;
    Capture::Tiny->import('capture_merged');
    require Path::Tiny;
    Path::Tiny->import('path');
    require File::chdir;
    File::chdir->import();
    require Test::Script;
    Test::Script->import('script_compiles');
    require FFI::C;
  };

  if($@)
  {
    note "error = $@";
    skip_all 'Test requires FFI::Platypus 2.00, Capture::Tiny, Test::Script, Path::Tiny, Convert::Binary::C, File::chdir, FFI:C and YAML';
  }
}

my @skipped;

foreach my $dir (qw( examples ))
{
  subtest "$dir" => sub {

    local $CWD = $dir;

    my @c_source = grep { $_->basename =~ /\.c$/ } path('.')->children;

    if(@c_source)
    {
      subtest 'Compile C' => sub {
        foreach my $c_source (@c_source)
        {
          my $so_file = $c_source->parent->child(do {
            my $basename = $c_source->basename;
            $basename =~ s/\.c$/.so/;
            $basename;
          });
          my @cmd = ('cc', '-fPIC', '-shared', -o => "$so_file", "$c_source");
          my($out, $ret) = capture_merged {
            system @cmd;
          };

          ok $ret == 0, "@cmd";
          if($ret == 0)
          {
            note $out if $out ne '';
          }
          else
          {
            diag $out if $out ne '';
          }
        }
      };
    }

    my @pl_source = grep { $_->basename =~ /\.pl$/ } path('.')->children;

    if(@pl_source)
    {
      subtest 'Run Perl' => sub {

        foreach my $pl_source (@pl_source)
        {
          subtest "$pl_source" => sub {

            script_compiles "$pl_source";

            my $key = join '/', $dir, $pl_source->basename;

            if($^O ne 'MSWin32' && $pl_source->basename =~ /^win32_/)
            {
              push @skipped, [$key, 'Microsoft Windows Only'];
              return;
            }

            my @cmd = ($^X, $pl_source);
            my($out, $ret) = capture_merged {
              system @cmd;
            };

            ok $ret == 0, "@cmd";
            if($ret == 0)
            {
              note $out if $out ne '';
            }
            else
            {
              diag $out if $out ne '';
            }
          };
        }

      };
    }

    unlink $_ for grep { $_->basename =~ /\.so$/ || $_->basename =~ /^zmq-ffi-/ } path('.')->children;

  }

}

foreach my $bundle (grep { -d $_ && $_->basename =~ /^bundle-/ } path('examples')->children)
{
  subtest $bundle->basename => sub {

    local $CWD = $bundle;

    my @cmd = ('prove', '-lvm');
    my($out, $ret) = capture_merged {
      system @cmd;
    };

    ok $ret == 0, "@cmd";
    if($ret == 0)
    {
      note $out if $out ne '';
    }
    else
    {
      diag $out if $out ne '';
    }
  };
}

if(@skipped)
{
  diag '';
  diag '';
  diag '';

  my $max = 5;
  foreach my $skip (@skipped)
  {
    $max = length($skip->[0])
      if $max < length($skip->[0]);
  }

  diag 'Skipped these examples:';

  foreach my $skip (@skipped)
  {
    diag sprintf "%-${max}s %s", $skip->[0], $skip->[1];
  }

  diag '';
  diag '';
}

done_testing;