Debian Codegraph @

dist/ExtUtils-ParseXS/t/515-t-cmd.t

raw
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 # tests for the quick-n-dirty interface for XS inclusion
6
7 use Test::More tests => 6;
8 use File::Spec;
9 use ExtUtils::Typemaps::Cmd;
10
11 my $datadir = -d 't' ? File::Spec->catdir(qw/t data/) : 'data';
12 my $libdir = -d 't' ? File::Spec->catdir(qw/t lib/) : 'lib';
13
14 unshift @INC, $libdir;
15
16 sub slurp {
17 my $file = shift;
18 open my $fh, '<', $file
19 or die "Cannot open file '$file' for reading: $!";
20 local $/ = undef;
21 return <$fh>;
22 }
23
24 sub permute (&@) {
25 my $code = shift;
26 my @idx = 0..$#_;
27 while ( $code->(@_[@idx]) ) {
28 my $p = $#idx;
29 --$p while $idx[$p-1] > $idx[$p];
30 my $q = $p or return;
31 push @idx, reverse splice @idx, $p;
32 ++$q while $idx[$p-1] > $idx[$q];
33 @idx[$p-1,$q]=@idx[$q,$p-1];
34 }
35 }
36
37
38 SCOPE: {
39 no warnings 'once';
40 ok(defined(*embeddable_typemap{CODE}), "function exported");
41 }
42
43 my $start = "TYPEMAP: <<END_TYPEMAP;\n";
44 my $end = "\nEND_TYPEMAP\n";
45 is(
46 embeddable_typemap(),
47 "${start}TYPEMAP\n$end",
48 "empty call to embeddable_typemap"
49 );
50
51 my $typemap_file = File::Spec->catfile($datadir, "simple.typemap");
52 is(
53 embeddable_typemap($typemap_file),
54 $start . slurp($typemap_file) . $end,
55 "embeddable typemap from file"
56 );
57
58 my $foo_content = <<HERE;
59 TYPEMAP
60 myfoo* T_PV
61 HERE
62 is(
63 embeddable_typemap("TypemapTest::Foo"),
64 "$start$foo_content$end",
65 "embeddable typemap from full module name"
66 );
67
68
69 my $test_content = <<HERE;
70 TYPEMAP
71 mytype* T_SV
72 HERE
73 is(
74 embeddable_typemap("Test"),
75 "$start$test_content$end",
76 "embeddable typemap from relative module name"
77 );
78
79 SCOPE: {
80 my $combined = embeddable_typemap("Test", "TypemapTest::Foo");
81 my @lines = (
82 'myfoo* T_PV',
83 'mytype* T_SV',
84 );
85 my @exp = map {"TYPEMAP\n" . join("\n", @$_) . "\n"}
86 (\@lines, [reverse @lines]);
87 ok(scalar(grep "$start$_$end" eq $combined, @exp), "combined both modules")
88 or note("Actual output: '$combined'");
89 }
90
91 # in theory, we should test
92 # embeddable_typemap($typemap_file, "Test", "TypemapTest::Foo"),
93 # but I can't be bothered.