Move Module::Pluggable into ext/ as the next version has actions in its
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / test_type.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if ($^O eq 'VMS') {
5         print '1..0 # Child test output confuses harness';
6         exit;
7     }
8 }
9
10 use strict;
11 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
12 use MBTest tests => 8;
13
14 use Cwd ();
15 my $cwd = Cwd::cwd;
16 my $tmp = MBTest->tmpdir;
17
18 use DistGen;
19
20 my $dist = DistGen->new( dir => $tmp );
21
22
23 $dist->add_file('t/special_ext.st', <<'---' );
24 #!perl 
25 use Test::More tests => 2;
26 ok(1, 'first test in special_ext');
27 ok(1, 'second test in special_ext');
28 ---
29
30 $dist->regen;
31
32 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
33
34 #########################
35
36 use_ok 'Module::Build';
37
38 # Here we make sure we can define an action that will test a particular type
39 $::x = 0;
40 my $mb = Module::Build->subclass(
41     code => q#
42         sub ACTION_testspecial { 
43             $::x++;
44             shift->generic_test(type => 'special');
45         }
46     #
47 )->new(
48     module_name => $dist->name,
49     test_types  => { special => '.st' }
50 );
51
52 ok $mb;
53
54 $mb->dispatch('testspecial');
55 is($::x, 1, "called once");
56
57
58 $mb->add_to_cleanup('save_out');
59 # Use uc() so we don't confuse the current test output
60 my $verbose_output = uc(stdout_of(
61     sub {$mb->dispatch('testspecial', verbose => 1)}
62 ));
63
64 like($verbose_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m);
65 like($verbose_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m);
66
67 is( $::x, 2, "called again");
68
69 my $output = uc(stdout_of(
70     sub {$mb->dispatch('testspecial', verbose => 0)}
71 ));
72 like($output, qr/\.\.OK/);
73
74 is($::x, 3, "called a third time");
75
76 chdir( $cwd ) or die "Can't chdir to '$cwd': $!";
77 $dist->remove;
78
79 # vim:ts=4:sw=4:et:sta