Add ARM files
[dh-make-perl] / dev / arm / libmodule-build-perl / libmodule-build-perl-0.2808.01 / 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 => 14 + 12;
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 $dist->add_file('t/special_ext.st', <<'---');
16 #!perl 
17 use Test::More tests => 2;
18 ok(1, 'first test in special_ext');
19 ok(1, 'second test in special_ext');
20 ---
21
22 $dist->add_file('t/another_ext.at', <<'---');
23 #!perl 
24 use Test::More tests => 2;
25 ok(1, 'first test in another_ext');
26 ok(1, 'second test in another_ext');
27 ---
28 $dist->add_file('t/foo.txt', <<'---');
29 #!perl 
30 use Test::More tests => 1;
31 ok 0, "don't run this non-test file";
32 die "don't run this non-test file";
33 ---
34
35 $dist->regen;
36
37 chdir($dist->dirname) or die "Can't chdir to '@{[$dist->dirname]}': $!";
38
39 #########################
40
41 use_ok 'Module::Build';
42
43 my $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
62 ok $mb;
63
64 my $special_output = uc(stdout_of(
65     sub {$mb->dispatch('testspecial', verbose => 1)}
66 ));
67
68 like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
69     'saw expected output from first test');
70 like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
71     'saw expected output from second test');
72
73 my $another_output = uc(stdout_of(
74     sub {$mb->dispatch('testanother', verbose => 1)}
75 ));
76
77 ok($another_output, 'we have some test output');
78
79 like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
80     'saw expected output from first test');
81 like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
82     'saw expected output from second test');
83
84
85 my $all_output = uc(stdout_of(
86     sub {$mb->dispatch('testall', verbose => 1)}
87 ));
88
89 0 and warn "\ntestall said >>>\n$all_output\n<<<\n";
90
91 like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
92     'expected output from basic.t');
93 like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
94     'expected output from basic.t');
95
96 like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
97 like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);
98
99 # we get a third one from basic.t
100 is(scalar(@{[$all_output =~ m/OK 1/mg]}), 3 );
101 is(scalar(@{[$all_output =~ m/OK/mg]}),   8 );
102 is(scalar(@{[$all_output =~ m/ALL TESTS SUCCESSFUL\./mg]}),   1);
103
104 chdir($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 
111 use Test::More tests => 2;
112 ok(1, 'first test in special_ext');
113 ok(1, 'second test in special_ext');
114 ---
115 $dist->add_file('t/foo/basic_foo.t', <<'---');
116 use Test::More tests => 1;
117 use strict; use Simple;
118 ok 1;
119 ---
120 $dist->regen;
121
122 chdir($dist->dirname) or die "Can't chdir to '@{[$dist->dirname]}': $!";
123
124 my $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
143 ok $mb;
144
145 my $special_output = uc(stdout_of(
146     sub {$mb->dispatch('testspecial', verbose => 1)}
147 ));
148
149 like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
150     'saw expected output from first test');
151 like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
152     'saw expected output from second test');
153
154 my $another_output = uc(stdout_of(
155     sub {$mb->dispatch('testanother', verbose => 1)}
156 ));
157
158 ok($another_output, 'we have some test output');
159
160 like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
161     'saw expected output from first test');
162 like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
163     'saw expected output from second test');
164
165
166 my $all_output = uc(stdout_of(
167     sub {$mb->dispatch('testall', verbose => 1)}
168 ));
169
170 like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
171     'expected output from basic.t');
172 like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
173     'expected output from basic.t');
174
175 like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
176 like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);
177
178 # we get a third one from basic.t
179 is(scalar(@{[$all_output =~ m/(OK 1)/mg]}), 5 );
180 is(scalar(@{[$all_output =~ m/(OK)/mg]}),   13 );
181
182 chdir($cwd) or die "Can't chdir to '$cwd': $!";
183 $dist->remove;
184 } # end once-again
185
186 # vim:ts=4:sw=4:et:sta