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
CommitLineData
7253302f 1#!/usr/bin/perl -w
2
3use strict;
4use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
738349a8 5use MBTest tests => 15 + 12;
6
7use_ok 'Module::Build';
8ensure_blib('Module::Build');
7253302f 9
7a827510 10my $tmp = MBTest->tmpdir;
7253302f 11
12use DistGen;
13
14my $dist = DistGen->new(dir => $tmp);
15
16$dist->add_file('t/special_ext.st', <<'---');
17#!perl
18use Test::More tests => 2;
19ok(1, 'first test in special_ext');
20ok(1, 'second test in special_ext');
21---
22
23$dist->add_file('t/another_ext.at', <<'---');
24#!perl
25use Test::More tests => 2;
26ok(1, 'first test in another_ext');
27ok(1, 'second test in another_ext');
28---
29$dist->add_file('t/foo.txt', <<'---');
30#!perl
31use Test::More tests => 1;
32ok 0, "don't run this non-test file";
33die "don't run this non-test file";
34---
35
36$dist->regen;
738349a8 37$dist->chdir_in;
7253302f 38#########################
39
7253302f 40my $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
59ok $mb;
60
61my $special_output = uc(stdout_of(
62 sub {$mb->dispatch('testspecial', verbose => 1)}
63));
64
65like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
66 'saw expected output from first test');
67like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
68 'saw expected output from second test');
69
70my $another_output = uc(stdout_of(
71 sub {$mb->dispatch('testanother', verbose => 1)}
72));
73
74ok($another_output, 'we have some test output');
75
76like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
77 'saw expected output from first test');
78like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
79 'saw expected output from second test');
80
81
82my $all_output = uc(stdout_of(
83 sub {$mb->dispatch('testall', verbose => 1)}
84));
85
860 and warn "\ntestall said >>>\n$all_output\n<<<\n";
87
88like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
89 'expected output from basic.t');
90like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
91 'expected output from basic.t');
92
93like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
94like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);
95
96# we get a third one from basic.t
97is(scalar(@{[$all_output =~ m/OK 1/mg]}), 3 );
98is(scalar(@{[$all_output =~ m/OK/mg]}), 8 );
99is(scalar(@{[$all_output =~ m/ALL TESTS SUCCESSFUL\./mg]}), 1);
100
7253302f 101$dist->remove;
102
103{ # once-again
104
105$dist->add_file('t/foo/special.st', <<'---');
106#!perl
107use Test::More tests => 2;
108ok(1, 'first test in special_ext');
109ok(1, 'second test in special_ext');
110---
111$dist->add_file('t/foo/basic_foo.t', <<'---');
112use Test::More tests => 1;
113use strict; use Simple;
114ok 1;
115---
116$dist->regen;
738349a8 117$dist->chdir_in;
7253302f 118
119my $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
138ok $mb;
139
140my $special_output = uc(stdout_of(
141 sub {$mb->dispatch('testspecial', verbose => 1)}
142));
143
144like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
145 'saw expected output from first test');
146like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
147 'saw expected output from second test');
148
149my $another_output = uc(stdout_of(
150 sub {$mb->dispatch('testanother', verbose => 1)}
151));
152
153ok($another_output, 'we have some test output');
154
155like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
156 'saw expected output from first test');
157like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
158 'saw expected output from second test');
159
160
161my $all_output = uc(stdout_of(
162 sub {$mb->dispatch('testall', verbose => 1)}
163));
164
165like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
166 'expected output from basic.t');
167like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
168 'expected output from basic.t');
169
170like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
171like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);
172
173# we get a third one from basic.t
174is(scalar(@{[$all_output =~ m/(OK 1)/mg]}), 5 );
175is(scalar(@{[$all_output =~ m/(OK)/mg]}), 13 );
176
7253302f 177$dist->remove;
178} # end once-again
179
180# vim:ts=4:sw=4:et:sta