Upgrade to ExtUtils::MakeMaker 6.52
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / t / fixin.t
CommitLineData
277189c8 1#!/usr/bin/perl -w
2
5bdf71cc 3# Try to test fixin. I say "try" because what fixin will actually do
4# is highly variable from system to system.
5
277189c8 6BEGIN {
7 if( $ENV{PERL_CORE} ) {
8 chdir 't';
9 @INC = ('../lib', 'lib/');
10 }
11 else {
12 unshift @INC, 't/lib/';
13 }
14}
15chdir 't';
16
17use File::Spec;
18
5bdf71cc 19use Test::More tests => 22;
277189c8 20
5bdf71cc 21use Config;
277189c8 22use TieOut;
23use MakeMaker::Test::Utils;
24use MakeMaker::Test::Setup::BFD;
25
26use ExtUtils::MakeMaker;
27
28chdir 't';
29
30perl_lib();
31
32ok( setup_recurs(), 'setup' );
33END {
34 ok( chdir File::Spec->updir );
35 ok( teardown_recurs(), 'teardown' );
36}
37
38ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
39 diag("chdir failed: $!");
40
41# [rt.cpan.org 26234]
42{
43 local $/ = "foo";
44 local $\ = "bar";
45 MY->fixin("bin/program");
46 is $/, "foo", '$/ not clobbered';
47 is $\, "bar", '$\ not clobbered';
48}
49
5bdf71cc 50
51sub test_fixin {
52 my($code, $test) = @_;
53
54 my $file = "fixin_test";
55 ok(open(my $fh, ">", $file), "write $file") or diag "Can't write $file: $!";
56 print $fh $code;
57 close $fh;
58
59 MY->fixin($file);
60
61 ok(open($fh, "<", $file), "read $file") or diag "Can't read $file: $!";
62 my @lines = <$fh>;
63 close $fh;
64
65 $test->(@lines);
66
67 1 while unlink $file;
68 ok !-e $file, "cleaned up $file";
69}
70
71
72# A simple test of fixin
73test_fixin(<<END,
74#!/foo/bar/perl -w
75
76blah blah blah
77END
78 sub {
79 my @lines = @_;
80 unlike $lines[0], qr[/foo/bar/perl], "#! replaced";
81 like $lines[0], qr[ -w\b], "switch retained";
82
83 # In between might be that "not running under some shell" madness.
84
85 is $lines[-1], "blah blah blah\n", "Program text retained";
86 }
87);
88
89
90# [rt.cpan.org 29442]
91test_fixin(<<END,
92#!/foo/bar/perl5.8.8 -w
93
94blah blah blah
95END
96
97 sub {
98 my @lines = @_;
99 unlike $lines[0], qr[/foo/bar/perl5.8.8], "#! replaced";
100 like $lines[0], qr[ -w\b], "switch retained";
101
102 # In between might be that "not running under some shell" madness.
103
104 is $lines[-1], "blah blah blah\n", "Program text retained";
105 }
106);
107
108
109# fixin shouldn't pick this up.
110test_fixin(<<END,
111#!/foo/bar/perly -w
112
113blah blah blah
114END
115
116 sub {
117 is join("", @_), <<END;
118#!/foo/bar/perly -w
119
120blah blah blah
121END
122 }
123);