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
CommitLineData
7253302f 1#!/usr/bin/perl -w
2
9548cd0f 3BEGIN {
4 if ($^O eq 'VMS') {
5 print '1..0 # Child test output confuses harness';
6 exit;
7 }
8}
9
7253302f 10use strict;
11use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
12use MBTest tests => 8;
13
14use Cwd ();
15my $cwd = Cwd::cwd;
7a827510 16my $tmp = MBTest->tmpdir;
7253302f 17
18use DistGen;
19
20my $dist = DistGen->new( dir => $tmp );
21
22
23$dist->add_file('t/special_ext.st', <<'---' );
24#!perl
25use Test::More tests => 2;
26ok(1, 'first test in special_ext');
27ok(1, 'second test in special_ext');
28---
29
30$dist->regen;
31
32chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
33
34#########################
35
36use_ok 'Module::Build';
37
38# Here we make sure we can define an action that will test a particular type
39$::x = 0;
40my $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
52ok $mb;
53
54$mb->dispatch('testspecial');
55is($::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
60my $verbose_output = uc(stdout_of(
61 sub {$mb->dispatch('testspecial', verbose => 1)}
62));
63
64like($verbose_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m);
65like($verbose_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m);
66
67is( $::x, 2, "called again");
68
69my $output = uc(stdout_of(
70 sub {$mb->dispatch('testspecial', verbose => 0)}
71));
72like($output, qr/\.\.OK/);
73
74is($::x, 3, "called a third time");
75
76chdir( $cwd ) or die "Can't chdir to '$cwd': $!";
77$dist->remove;
78
79# vim:ts=4:sw=4:et:sta