@@ -8,8 +8,10 @@ chdir 't';
8
8
9
9
use Config;
10
10
use MakeMaker::Test::Utils;
11
- use Test::More tests => 16;
11
+ use Test::More;
12
+ use File::Temp qw[ tempdir] ;
12
13
use File::Spec;
14
+ use Cwd;
13
15
14
16
my $TB = Test::More-> builder;
15
17
my $perl = which_perl;
@@ -20,24 +22,21 @@ my $mm = bless { NAME => "Foo", MAKE => $Config{make} }, 'MM';
20
22
isa_ok($mm , ' ExtUtils::MakeMaker' );
21
23
isa_ok($mm , ' ExtUtils::MM_Any' );
22
24
25
+ my $MAKE = $mm -> {MAKE } or die ;
23
26
24
- sub try_oneliner {
25
- my ($code , $switches , $expect , $name ) = @_ ;
26
- my $cmd = $mm -> oneliner($code , $switches );
27
- $cmd =~ s {\$\( ABSPERLRUN\) } { $perl } ;
27
+ my $tmpdir = tempdir( CLEANUP => 1 );
28
28
29
- # VMS likes to put newlines at the end of commands if there isn't
30
- # one already.
31
- $expect =~ s / ([^\n ])\z / $1 \n / if $^O eq ' VMS' ;
29
+ my $cwd = getcwd; END { chdir $cwd if defined $cwd } # so File::Temp can cleanup
32
30
33
- $TB -> is_eq( scalar ` $cmd ` , $expect , $name ) || $TB -> diag( " oneliner: \n $cmd " );
34
- }
31
+ # run all these test from a temporary directory
32
+ chdir ( $tmpdir ) or die " Fail to change to tmp directory: $! " ;
35
33
36
34
# Lets see how it deals with quotes.
37
35
try_oneliner(q{ print "foo'o", ' bar"ar'} , [], q{ foo'o bar"ar} , ' quotes' );
38
36
39
37
# How about dollar signs?
40
- try_oneliner(q{ $PATH = 'foo'; print $PATH} ,[], q{ foo} , ' dollar signs' );
38
+ try_oneliner(q{ my $PATH = 'foo'; print $PATH} ,[], q{ foo} , ' dollar signs' );
39
+ try_oneliner(q{ my %h = (1, 2); print $h{1}} ,[], q{ 2} , ' %h and $h' );
41
40
42
41
# switches?
43
42
try_oneliner(q{ print 'foo'} , [' -l' ], " foo\n " , ' switches' );
@@ -59,3 +58,44 @@ try_oneliner(q{print q[ "C:\TEST %&^ A\" ]}, [], q{ "C:\TEST %&^ A\" }, 'examp
59
58
# XXX gotta rethink the newline test. The Makefile does newline
60
59
# escaping, then the shell.
61
60
61
+ done_testing;
62
+ exit ;
63
+
64
+ sub try_oneliner {
65
+ my ($code , $switches , $expect , $name ) = @_ ;
66
+ my $cmd = $mm -> oneliner($code , $switches );
67
+ $cmd =~ s {\$\( ABSPERLRUN\) } { $perl } ;
68
+
69
+ # VMS likes to put newlines at the end of commands if there isn't
70
+ # one already.
71
+ $expect =~ s / ([^\n ])\z / $1 \n / if $^O eq ' VMS' ;
72
+
73
+ my $content = Makefile_template( $cmd );
74
+ write_file(' Makefile' , $content );
75
+
76
+ my $output = qx{ $MAKE -s all} ;
77
+
78
+ my $ok = $TB -> is_eq($output , $expect , $name ) || $TB -> diag(" Makefile:\n $output " );
79
+
80
+ return $ok ;
81
+ }
82
+
83
+ sub Makefile_template {
84
+ my ( $RUN ) = @_ ;
85
+ my $NOECHO = ' @' ;
86
+
87
+ return <<"MAKEFILE" ;
88
+ all:
89
+ ${NOECHO} ${RUN}
90
+ MAKEFILE
91
+ }
92
+
93
+ sub write_file {
94
+ my ( $f , $content ) = @_ ;
95
+
96
+ open ( my $fh , ' >' , $f ) or die $! ;
97
+ print {$fh } $content or die $! ;
98
+ close $fh ;
99
+
100
+ return ;
101
+ }
0 commit comments