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