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
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 19;
use ExtUtils::Typemaps;
use File::Spec;
use File::Temp;
my $datadir = -d 't' ? File::Spec->catdir(qw/t data/) : 'data';
sub slurp {
my $file = shift;
open my $fh, '<', $file
or die "Cannot open file '$file' for reading: $!";
local $/ = undef;
return <$fh>;
}
my $first_typemap_file = File::Spec->catfile($datadir, 'simple.typemap');
my $second_typemap_file = File::Spec->catfile($datadir, 'other.typemap');
my $combined_typemap_file = File::Spec->catfile($datadir, 'combined.typemap');
my $conflicting_typemap_file = File::Spec->catfile($datadir, 'conflicting.typemap');
my $confl_replace_typemap_file = File::Spec->catfile($datadir, 'confl_repl.typemap');
my $confl_skip_typemap_file = File::Spec->catfile($datadir, 'confl_skip.typemap');
# test merging two typemaps
SCOPE: {
my $first = ExtUtils::Typemaps->new(file => $first_typemap_file);
isa_ok($first, 'ExtUtils::Typemaps');
my $second = ExtUtils::Typemaps->new(file => $second_typemap_file);
isa_ok($second, 'ExtUtils::Typemaps');
$first->merge(typemap => $second);
is($first->as_string(), slurp($combined_typemap_file), "merging produces expected output");
}
# test merging a typemap from file
SCOPE: {
my $first = ExtUtils::Typemaps->new(file => $first_typemap_file);
isa_ok($first, 'ExtUtils::Typemaps');
$first->merge(file => $second_typemap_file);
is($first->as_string(), slurp($combined_typemap_file), "merging produces expected output");
}
# test merging a typemap as string
SCOPE: {
my $first = ExtUtils::Typemaps->new(file => $first_typemap_file);
isa_ok($first, 'ExtUtils::Typemaps');
my $second_str = slurp($second_typemap_file);
$first->add_string(string => $second_str);
is($first->as_string(), slurp($combined_typemap_file), "merging (string) produces expected output");
}
# test merging a conflicting typemap without "replace"
SCOPE: {
my $second = ExtUtils::Typemaps->new(file => $second_typemap_file);
isa_ok($second, 'ExtUtils::Typemaps');
my $conflict = ExtUtils::Typemaps->new(file => $conflicting_typemap_file);
isa_ok($conflict, 'ExtUtils::Typemaps');
ok(
!eval {
$second->merge(typemap => $conflict);
1;
},
"Merging conflicting typemap croaks"
);
ok(
$@ =~ /Multiple definition/,
"Conflicting typemap error as expected"
);
}
# test merging a conflicting typemap with "replace"
SCOPE: {
my $second = ExtUtils::Typemaps->new(file => $second_typemap_file);
isa_ok($second, 'ExtUtils::Typemaps');
my $conflict = ExtUtils::Typemaps->new(file => $conflicting_typemap_file);
isa_ok($conflict, 'ExtUtils::Typemaps');
ok(
eval {
$second->merge(typemap => $conflict, replace => 1);
1;
},
"Conflicting typemap merge with 'replace' doesn't croak"
);
is($second->as_string(), slurp($confl_replace_typemap_file), "merging (string) produces expected output");
}
# test merging a conflicting typemap file with "skip"
SCOPE: {
my $second = ExtUtils::Typemaps->new(file => $second_typemap_file);
isa_ok($second, 'ExtUtils::Typemaps');
my $conflict = ExtUtils::Typemaps->new(file => $conflicting_typemap_file);
isa_ok($conflict, 'ExtUtils::Typemaps');
ok(
eval {
$second->merge(typemap => $conflict, skip => 1);
1;
},
"Conflicting typemap merge with 'skip' doesn't croak"
);
is($second->as_string(), slurp($confl_skip_typemap_file), "merging (string) produces expected output");
}
|