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