This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update to MakeMaker 6.30
[perl5.git] / t / lib / MakeMaker / Test / Setup / PL_FILES.pm
CommitLineData
7292dc67
RGS
1package MakeMaker::Test::Setup::PL_FILES;
2
3@ISA = qw(Exporter);
4require Exporter;
5@EXPORT = qw(setup teardown);
6
7use strict;
8use File::Path;
9use File::Basename;
10use File::Spec;
11use MakeMaker::Test::Utils;
12
13my %Files = (
14 'PL_FILES-Module/Makefile.PL' => <<'END',
15use ExtUtils::MakeMaker;
16
17# A module for testing PL_FILES
18WriteMakefile(
19 NAME => 'PL_FILES::Module',
20 PL_FILES => { 'single.PL' => 'single.out',
4325052d
RGS
21 'multi.PL' => [qw(1.out 2.out)],
22 'Bar_pm.PL' => '$(INST_LIB)/PL/Bar.pm',
7292dc67
RGS
23 }
24);
25END
26
4325052d
RGS
27 'PL_FILES-Module/single.PL' => _gen_pl_files(),
28 'PL_FILES-Module/multi.PL' => _gen_pl_files(),
29 'PL_FILES-Module/Bar_pm.PL' => _gen_pm_files(),
30 'PL_FILES-Module/lib/PL/Foo.pm' => <<'END',
31# Module to load to ensure PL_FILES have blib in @INC.
32package PL::Foo;
33sub bar { 42 }
341;
35END
36
7292dc67
RGS
37);
38
39
40sub _gen_pl_files {
41 my $test = <<'END';
42#!/usr/bin/perl -w
43
4325052d
RGS
44# Ensure we have blib in @INC
45use PL::Foo;
46die unless PL::Foo::bar() == 42;
47
48# Had a bug where PL_FILES weren't sent the file to generate
49die "argv empty\n" unless @ARGV;
50die "too many in argv: @ARGV\n" unless @ARGV == 1;
51
52my $file = $ARGV[0];
53open OUT, ">$file" or die $!;
54
55print OUT "Testing\n";
56close OUT
57END
58
59 $test =~ s/^\n//;
60
61 return $test;
62}
63
64
65sub _gen_pm_files {
66 my $test = <<'END';
67#!/usr/bin/perl -w
68
69# Ensure we do NOT have blib in @INC when building a module
70eval { require PL::Foo; };
71#die $@ unless $@ =~ m{^Can't locate PL/Foo.pm in \@INC };
72
7292dc67
RGS
73# Had a bug where PL_FILES weren't sent the file to generate
74die "argv empty\n" unless @ARGV;
75die "too many in argv: @ARGV\n" unless @ARGV == 1;
76
77my $file = $ARGV[0];
78open OUT, ">$file" or die $!;
79
80print OUT "Testing\n";
81close OUT
82END
83
84 $test =~ s/^\n//;
85
86 return $test;
87}
88
89
90sub setup {
91 setup_mm_test_root();
92 chdir 'MM_TEST_ROOT:[t]' if $^O eq 'VMS';
93
94 while(my($file, $text) = each %Files) {
95 # Convert to a relative, native file path.
96 $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file);
97
98 my $dir = dirname($file);
99 mkpath $dir;
100 open(FILE, ">$file") || die "Can't create $file: $!";
101 print FILE $text;
102 close FILE;
103 }
104
105 return 1;
106}
107
108sub teardown {
109 foreach my $file (keys %Files) {
110 my $dir = dirname($file);
111 if( -e $dir ) {
112 rmtree($dir) || return;
113 }
114 }
115 return 1;
116}