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