1#!/usr/bin/perl -w
2
3# Ensure pm_to_blib runs at the right times.
4
5use strict;
6use warnings;
7use lib 't/lib';
8
9use File::Temp qw[tempdir];
10
11use ExtUtils::MakeMaker;
12
13use MakeMaker::Test::Utils;
14use MakeMaker::Test::Setup::BFD;
15use Config;
16use ExtUtils::MM;
17use Test::More
18    !MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'}
19    ? (skip_all => "cross-compiling and make not available")
20    : 'no_plan';
21
22my $perl     = which_perl();
23my $makefile = makefile_name();
24my $make     = make_run();
25
26local $ENV{PERL_INSTALL_QUIET};
27
28# Setup our test environment
29{
30    chdir 't';
31    perl_lib; # sets $ENV{PERL5LIB} relative to t/
32
33    my $tmpdir = tempdir( DIR => '../t', CLEANUP => 1 );
34    use Cwd; my $cwd = getcwd; END { chdir $cwd } # so File::Temp can cleanup
35    chdir $tmpdir;
36
37    ok( setup_recurs(), 'setup' );
38    END {
39        ok( chdir File::Spec->updir );
40        ok( teardown_recurs(), 'teardown' );
41    }
42
43    ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) ||
44      diag("chdir failed: $!");
45}
46
47
48# Run make once
49{
50    run_ok(qq{$perl Makefile.PL});
51    run_ok($make);
52
53    ok( -e "blib/lib/Big/Dummy.pm", "blib copied pm file" );
54}
55
56
57# Change a pm file, it should be copied.
58{
59    # Wait a couple seconds else our changed file will have the same timestamp
60    # as the blib file
61    sleep 2;
62
63    ok( open my $fh, ">>", "lib/Big/Dummy.pm" ) or die $!;
64    print $fh "Something else\n";
65    close $fh;
66
67    run_ok($make);
68    like slurp("blib/lib/Big/Dummy.pm"), qr/Something else\n$/;
69}
70
71
72# Rerun the Makefile.PL, pm_to_blib should rerun
73{
74    # Seems there are occasional race conditions with these tests
75    # waiting a couple of seconds appears to resolve these
76    sleep 2;
77    run_ok(qq{$perl Makefile.PL});
78
79    # XXX This is a fragile way to check that it reran.
80    like run_ok($make), qr/^Skip /ms;
81
82    ok( -e "blib/lib/Big/Dummy.pm", "blib copied pm file" );
83}
84