File: ffi_build_mm.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 (153 lines) | stat: -rw-r--r-- 3,570 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
use Test2::V0 -no_srand => 1;
use 5.008004;
use FFI::Build::MM;
use Capture::Tiny qw( capture_merged );
use File::Glob qw( bsd_glob );
use lib 't/lib';
use Test::Platypus;

sub dont_save_prop (&)
{
   my($code) = @_;
   sub {
    my $save = \&FFI::Build::MM::save_prop;
    {
      no warnings 'redefine';
      *FFI::Build::MM::save_prop = sub {};
    };
    my $ret = eval { $code->() };
    my $error = $@;
    {
      no warnings 'redefine';
      *FFI::Build::MM::save_prop = $save;
    }
    die $error if $error;
    $ret;
  };
}

sub slurp ($)
{
  my $fn = shift;
  open my $fh, '<', $fn;
  my $content = do { local $/; <$fh> };
  close $fh;
  $content;
}

subtest 'basic' => dont_save_prop {

  my $mm = FFI::Build::MM->new;
  isa_ok $mm, 'FFI::Build::MM';

  $mm->mm_args( DISTNAME => 'Foo-Bar-Baz' );

  is( $mm->distname, 'Foo-Bar-Baz' );
  is( $mm->sharedir, 'blib/lib/auto/share/dist/Foo-Bar-Baz' );
  is( $mm->archdir,  'blib/arch/auto/Foo/Bar/Baz' );

  subtest 'build with fbx file' => sub {
    my $build = $mm->load_build('corpus/ffi_build_mm/lb1', undef, undef);
    isa_ok $build, 'FFI::Build';
    is [sort map { $_->basename } $build->source], ['hello1.c','hello2.c']
  };

  subtest 'build with fbx file with errors' => sub {
      eval { $mm->load_build('corpus/ffi_build_mm/lb1bad', undef, undef) };
      like ( $@, qr/skootch/, "caught compile error in fbx file" );

  };

  subtest 'build with default' => sub {
    my $build = $mm->load_build('corpus/ffi_build_mm/lb2', undef, undef);
    isa_ok $build, 'FFI::Build';
    is [sort map { $_->basename } $build->source], ['hello1.c','hello2.c']
  };

  my $postamble = $mm->mm_postamble;
  ok $postamble;
  note "[postamble]\n$postamble\n";

  $mm->sharedir('share');
  is( $mm->sharedir, 'share' );

  $mm->archdir(0);
  ok( !$mm->archdir );
};

subtest 'with a build!' => sub {

  chdir 'corpus/ffi_build_mm/project1';

  unlink 'fbx.json' if -f 'fbx.json';

  subtest 'namespace is clean' => sub {
    ok( ! main->can($_), "$_ not imported yet" ) for qw( fbx_build fbx_test fbx_clean );
  };

  subtest 'do not save on request' => sub {

    my $mm = FFI::Build::MM->new( save => 0 );
    $mm->mm_args( DISTNAME => 'Crock-O-Stimpy' );
    ok !-f 'fbx.json';

  };

  subtest 'perl Makefile.PL' => sub {

    my $mm = FFI::Build::MM->new;
    $mm->mm_args( DISTNAME => 'Crock-O-Stimpy' );
    ok -f 'fbx.json';

  };

  subtest 'import' => sub {
    FFI::Build::MM->import('cmd');
    ok( main->can($_), "$_ not imported yet" ) for qw( fbx_build fbx_test fbx_clean );
  };

  subtest 'make' => sub {
    my($out, $err) = capture_merged {
      eval { fbx_build() };
      $@;
    };
    note $out;
    is $err, '';

    is slurp 'blib/arch/auto/Crock/O/Stimpy/Stimpy.txt', "FFI::Build\@auto/share/dist/Crock-O-Stimpy/lib/@{[ FFI::Build::Platform->library_prefix ]}Crock-O-Stimpy@{[ scalar FFI::Build::Platform->library_suffix]}\n";

    platypus 1 => sub {
      my $ffi = shift;
      $ffi->lib(grep !/\.pdb$/, bsd_glob 'blib/lib/auto/share/dist/Crock-O-Stimpy/lib/*');
      note "lib=$_" for $ffi->lib;
      is(
        $ffi->function('frooble_runtime' => [] => 'int')->call,
        47,
      );
    };
  };

  subtest 'make test' => sub {
    my($out, $err) = capture_merged {
      eval { fbx_test() };
      $@;
    };
    note $out;
    is $err, '';
  };

  subtest 'make clean' => sub {
    fbx_clean();
    ok !-f 'fbx.json';
  };
  File::Path::rmtree('blib', 0, oct(755));

  chdir(File::Spec->updir) for 1..3;

};

subtest 'alien' => sub {
  skip_all 'todo';
};

done_testing;