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