This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
A typemap is a file, not a directory.
[perl5.git] / dist / ExtUtils-ParseXS / t / 106-process_typemaps.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Carp;
5 use Cwd;
6 use File::Spec;
7 use File::Temp qw( tempdir );
8 use Test::More tests =>  2;
9 use lib qw( lib );
10 use ExtUtils::ParseXS::Utilities qw(
11   process_typemaps
12 );
13
14 my $startdir  = cwd();
15 {
16     my ($type_kind_ref, $proto_letter_ref, $input_expr_ref, $output_expr_ref);
17     my $typemap = 'typemap';
18     my $tdir = tempdir( CLEANUP => 1 );
19     chdir $tdir or croak "Unable to change to tempdir for testing";
20     eval {
21         ($type_kind_ref, $proto_letter_ref, $input_expr_ref, $output_expr_ref)
22             = process_typemaps( $typemap, $tdir );
23     };
24     like( $@, qr/Can't find \Q$typemap\E in \Q$tdir\E/, #'
25         "Got expected result for no typemap in current directory" );
26     chdir $startdir;
27 }
28
29 {
30     my ($type_kind_ref, $proto_letter_ref, $input_expr_ref, $output_expr_ref);
31     my $typemap = [ qw( pseudo typemap ) ];
32     my $tdir = tempdir( CLEANUP => 1 );
33     chdir $tdir or croak "Unable to change to tempdir for testing";
34     open my $IN, '>', 'typemap' or croak "Cannot open for writing";
35     print $IN "\n";
36     close $IN or croak "Cannot close after writing";
37     eval {
38         ($type_kind_ref, $proto_letter_ref, $input_expr_ref, $output_expr_ref)
39             = process_typemaps( $typemap, $tdir );
40     };
41     like( $@, qr/Can't find pseudo in \Q$tdir\E/, #'
42         "Got expected result for no typemap in current directory" );
43     chdir $startdir;
44 }
45