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