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 Test::More;
16use ExtUtils::MM;
17plan !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    my $tmpdir = tempdir( DIR => 't', CLEANUP => 1 );
30    chdir $tmpdir;
31
32    perl_lib;
33
34    ok( setup_recurs(), 'setup' );
35    END {
36        ok( chdir File::Spec->updir );
37        ok( teardown_recurs(), 'teardown' );
38    }
39
40    ok( chdir('Big-Dummy'), "chdir'd to Big-Dummy" ) ||
41      diag("chdir failed: $!");
42}
43
44
45# Run make once
46{
47    run_ok(qq{$perl Makefile.PL});
48    run_ok($make);
49
50    ok( -e "blib/lib/Big/Dummy.pm", "blib copied pm file" );
51}
52
53
54# Change a pm file, it should be copied.
55{
56    # Wait a couple seconds else our changed file will have the same timestamp
57    # as the blib file
58    sleep 2;
59
60    ok( open my $fh, ">>", "lib/Big/Dummy.pm" ) or die $!;
61    print $fh "Something else\n";
62    close $fh;
63
64    run_ok($make);
65    like slurp("blib/lib/Big/Dummy.pm"), qr/Something else\n$/;
66}
67
68
69# Rerun the Makefile.PL, pm_to_blib should rerun
70{
71    # Seems there are occasional race conditions with these tests
72    # waiting a couple of seconds appears to resolve these
73    sleep 2;
74    run_ok(qq{$perl Makefile.PL});
75
76    # XXX This is a fragile way to check that it reran.
77    like run_ok($make), qr/^Skip /ms;
78
79    ok( -e "blib/lib/Big/Dummy.pm", "blib copied pm file" );
80}
81