Add ExtUtils::Miniperl to the list of core modules for all versions >= 5.00504
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / test_types.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 => 15 + 12;
6
7 use_ok 'Module::Build';
8 ensure_blib('Module::Build');
9
10 my $tmp = MBTest->tmpdir;
11
12 use DistGen;
13
14 my $dist = DistGen->new(dir => $tmp);
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->add_file('t/another_ext.at', <<'---');
24 #!perl 
25 use Test::More tests => 2;
26 ok(1, 'first test in another_ext');
27 ok(1, 'second test in another_ext');
28 ---
29 $dist->add_file('t/foo.txt', <<'---');
30 #!perl 
31 use Test::More tests => 1;
32 ok 0, "don't run this non-test file";
33 die "don't run this non-test file";
34 ---
35
36 $dist->regen;
37 $dist->chdir_in;
38 #########################
39
40 my $mb = Module::Build->subclass(
41    code => q#
42         sub ACTION_testspecial { 
43             shift->generic_test(type => 'special');
44         }
45
46         sub ACTION_testanother { 
47             shift->generic_test(type => 'another');
48         }
49   #
50   )->new(
51       module_name => $dist->name,
52       test_types  => {
53           special => '.st',
54           another => '.at',
55       },
56   );
57
58
59 ok $mb;
60
61 my $special_output = uc(stdout_of(
62     sub {$mb->dispatch('testspecial', verbose => 1)}
63 ));
64
65 like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
66     'saw expected output from first test');
67 like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
68     'saw expected output from second test');
69
70 my $another_output = uc(stdout_of(
71     sub {$mb->dispatch('testanother', verbose => 1)}
72 ));
73
74 ok($another_output, 'we have some test output');
75
76 like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
77     'saw expected output from first test');
78 like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
79     'saw expected output from second test');
80
81
82 my $all_output = uc(stdout_of(
83     sub {$mb->dispatch('testall', verbose => 1)}
84 ));
85
86 0 and warn "\ntestall said >>>\n$all_output\n<<<\n";
87
88 like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
89     'expected output from basic.t');
90 like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
91     'expected output from basic.t');
92
93 like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
94 like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);
95
96 # we get a third one from basic.t
97 is(scalar(@{[$all_output =~ m/OK 1/mg]}), 3 );
98 is(scalar(@{[$all_output =~ m/OK/mg]}),   8 );
99 is(scalar(@{[$all_output =~ m/ALL TESTS SUCCESSFUL\./mg]}),   1);
100
101 $dist->remove;
102
103 { # once-again
104
105 $dist->add_file('t/foo/special.st', <<'---');
106 #!perl 
107 use Test::More tests => 2;
108 ok(1, 'first test in special_ext');
109 ok(1, 'second test in special_ext');
110 ---
111 $dist->add_file('t/foo/basic_foo.t', <<'---');
112 use Test::More tests => 1;
113 use strict; use Simple;
114 ok 1;
115 ---
116 $dist->regen;
117 $dist->chdir_in;
118
119 my $mb = Module::Build->subclass(
120    code => q#
121         sub ACTION_testspecial { 
122             shift->generic_test(type => 'special');
123         }
124
125         sub ACTION_testanother { 
126             shift->generic_test(type => 'another');
127         }
128   #
129   )->new(
130       recursive_test_files => 1,
131       module_name => $dist->name,
132       test_types  => {
133           special => '.st',
134           another => '.at',
135       },
136   );
137
138 ok $mb;
139
140 my $special_output = uc(stdout_of(
141     sub {$mb->dispatch('testspecial', verbose => 1)}
142 ));
143
144 like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
145     'saw expected output from first test');
146 like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
147     'saw expected output from second test');
148
149 my $another_output = uc(stdout_of(
150     sub {$mb->dispatch('testanother', verbose => 1)}
151 ));
152
153 ok($another_output, 'we have some test output');
154
155 like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
156     'saw expected output from first test');
157 like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
158     'saw expected output from second test');
159
160
161 my $all_output = uc(stdout_of(
162     sub {$mb->dispatch('testall', verbose => 1)}
163 ));
164
165 like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
166     'expected output from basic.t');
167 like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
168     'expected output from basic.t');
169
170 like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
171 like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);
172
173 # we get a third one from basic.t
174 is(scalar(@{[$all_output =~ m/(OK 1)/mg]}), 5 );
175 is(scalar(@{[$all_output =~ m/(OK)/mg]}),   13 );
176
177 $dist->remove;
178 } # end once-again
179
180 # vim:ts=4:sw=4:et:sta