This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
28e7f5fbe3317bfc7a50262e4007497584df208d
[perl5.git] / dist / ExtUtils-ParseXS / t / 513-t-merge.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 5;
6 use ExtUtils::Typemaps;
7 use File::Spec;
8 use File::Temp;
9
10 my $datadir = -d 't' ? File::Spec->catdir(qw/t data/) : 'data';
11
12 sub 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
20 my $first_typemap_file = File::Spec->catfile($datadir, 'simple.typemap');
21 my $second_typemap_file = File::Spec->catfile($datadir, 'other.typemap');
22 my $combined_typemap_file = File::Spec->catfile($datadir, 'combined.typemap');
23
24
25 SCOPE: {
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');
30
31   $first->merge(typemap => $second);
32
33   is($first->as_string(), slurp($combined_typemap_file), "merging produces expected output");
34 }
35
36 SCOPE: {
37   my $first = ExtUtils::Typemaps->new(file => $first_typemap_file);
38   isa_ok($first, 'ExtUtils::Typemaps');
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 }