summaryrefslogtreecommitdiff
path: root/t/test_types.t
blob: bcb58c444afe15b79dfc710866a9b875546fdf0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/perl -w

use strict;
use lib 't/lib';
use MBTest tests => 25;

blib_load('Module::Build');

use DistGen;

my $dist = DistGen->new()->chdir_in;

$dist->add_file('t/special_ext.st', <<'---');
#!perl
use Test::More tests => 2;
ok(1, 'first test in special_ext');
ok(1, 'second test in special_ext');
---

$dist->add_file('t/another_ext.at', <<'---');
#!perl
use Test::More tests => 2;
ok(1, 'first test in another_ext');
ok(1, 'second test in another_ext');
---
$dist->add_file('t/foo.txt', <<'---');
#!perl
use Test::More tests => 1;
ok 0, "don't run this non-test file";
die "don't run this non-test file";
---

$dist->regen;
#########################

my $mb = Module::Build->subclass(
   code => q#
        sub ACTION_testspecial {
            shift->generic_test(type => 'special');
        }

        sub ACTION_testanother {
            shift->generic_test(type => 'another');
        }
  #
  )->new(
      module_name => $dist->name,
      test_types  => {
          special => '.st',
          another => '.at',
      },
  );


ok $mb;

my $special_output = uc(stdout_of(
    sub {$mb->dispatch('testspecial', verbose => 1)}
));

like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
    'saw expected output from first test');
like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
    'saw expected output from second test');

my $another_output = uc(stdout_of(
    sub {$mb->dispatch('testanother', verbose => 1)}
));

ok($another_output, 'we have some test output');

like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
    'saw expected output from first test');
like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
    'saw expected output from second test');


my $all_output = uc(stdout_of(
    sub {$mb->dispatch('testall', verbose => 1)}
));

0 and warn "\ntestall said >>>\n$all_output\n<<<\n";

like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
    'expected output from basic.t');
like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
    'expected output from basic.t');

like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);

# we get a third one from basic.t
is(scalar(@{[$all_output =~ m/OK 1/mg]}), 3 );
is(scalar(@{[$all_output =~ m/OK/mg]}),   8 );
is(scalar(@{[$all_output =~ m/ALL TESTS SUCCESSFUL\./mg]}),   1);

{ # once-again

$dist->revert;

$dist->add_file('t/foo/special.st', <<'---');
#!perl
use Test::More tests => 2;
ok(1, 'first test in special_ext');
ok(1, 'second test in special_ext');
---
$dist->add_file('t/foo/basic_foo.t', <<'---');
use Test::More tests => 1;
use strict; use Simple;
ok 1;
---
$dist->regen;

my $mb = Module::Build->subclass(
   code => q#
        sub ACTION_testspecial {
            shift->generic_test(type => 'special');
        }

        sub ACTION_testanother {
            shift->generic_test(type => 'another');
        }
  #
  )->new(
      recursive_test_files => 1,
      module_name => $dist->name,
      test_types  => {
          special => '.st',
          another => '.at',
      },
  );

ok $mb;

my $special_output = uc(stdout_of(
    sub {$mb->dispatch('testspecial', verbose => 1)}
));

like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
    'saw expected output from first test');
like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
    'saw expected output from second test');

my $another_output = uc(stdout_of(
    sub {$mb->dispatch('testanother', verbose => 1)}
));

ok($another_output, 'we have some test output');

like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m,
    'saw expected output from first test');
like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m,
    'saw expected output from second test');


my $all_output = uc(stdout_of(
    sub {$mb->dispatch('testall', verbose => 1)}
));

like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m,
    'expected output from basic.t');
like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m,
    'expected output from basic.t');

like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m);
like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m);

# we get a third one from basic.t
is(scalar(@{[$all_output =~ m/(OK 1)/mg]}), 5 );
is(scalar(@{[$all_output =~ m/(OK)/mg]}),   13 );

} # end once-again

# vim:ts=4:sw=4:et:sta