This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to ExtUtils::MakeMaker 6.27,
[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',
21 'multi.PL' => [qw(1.out 2.out)]
22 }
23);
24END
25
26 'PL_FILES-Module/single.PL' => _gen_pl_files(),
27 'PL_FILES-Module/multi.PL' => _gen_pl_files(),
28);
29
30
31sub _gen_pl_files {
32 my $test = <<'END';
33#!/usr/bin/perl -w
34
35# Had a bug where PL_FILES weren't sent the file to generate
36die "argv empty\n" unless @ARGV;
37die "too many in argv: @ARGV\n" unless @ARGV == 1;
38
39my $file = $ARGV[0];
40open OUT, ">$file" or die $!;
41
42print OUT "Testing\n";
43close OUT
44END
45
46 $test =~ s/^\n//;
47
48 return $test;
49}
50
51
52sub setup {
53 setup_mm_test_root();
54 chdir 'MM_TEST_ROOT:[t]' if $^O eq 'VMS';
55
56 while(my($file, $text) = each %Files) {
57 # Convert to a relative, native file path.
58 $file = File::Spec->catfile(File::Spec->curdir, split m{\/}, $file);
59
60 my $dir = dirname($file);
61 mkpath $dir;
62 open(FILE, ">$file") || die "Can't create $file: $!";
63 print FILE $text;
64 close FILE;
65 }
66
67 return 1;
68}
69
70sub teardown {
71 foreach my $file (keys %Files) {
72 my $dir = dirname($file);
73 if( -e $dir ) {
74 rmtree($dir) || return;
75 }
76 }
77 return 1;
78}