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