This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow merging typemaps from file
[perl5.git] / dist / ExtUtils-ParseXS / t / 513-t-merge.t
CommitLineData
297f4492
S
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5use Test::More tests => 5;
7320491e 6use ExtUtils::Typemaps;
297f4492
S
7use File::Spec;
8use File::Temp;
9
10my $datadir = -d 't' ? File::Spec->catdir(qw/t data/) : 'data';
11
12sub slurp {
13 my $file = shift;
14 open my $fh, '<', $file
15 or die "Cannot open file '$file' for reading: $!";
16 local $/ = undef;
17 return <$fh>;
18}
19
20my $first_typemap_file = File::Spec->catfile($datadir, 'simple.typemap');
21my $second_typemap_file = File::Spec->catfile($datadir, 'other.typemap');
22my $combined_typemap_file = File::Spec->catfile($datadir, 'combined.typemap');
23
24
25SCOPE: {
7320491e
S
26 my $first = ExtUtils::Typemaps->new(file => $first_typemap_file);
27 isa_ok($first, 'ExtUtils::Typemaps');
28 my $second = ExtUtils::Typemaps->new(file => $second_typemap_file);
29 isa_ok($second, 'ExtUtils::Typemaps');
297f4492
S
30
31 $first->merge(typemap => $second);
32
33 is($first->as_string(), slurp($combined_typemap_file), "merging produces expected output");
34}
35
36SCOPE: {
7320491e
S
37 my $first = ExtUtils::Typemaps->new(file => $first_typemap_file);
38 isa_ok($first, 'ExtUtils::Typemaps');
297f4492
S
39 my $second_str = slurp($second_typemap_file);
40
41 $first->add_string(string => $second_str);
42
43 is($first->as_string(), slurp($combined_typemap_file), "merging (string) produces expected output");
44}