| 1 |
use Test2::V0; |
| 2 |
use Test2::Harness::Util::JSON qw/encode_json decode_json/; |
| 3 |
use Test2::Require::Module 'Test2::Plugin::Cover' => '0.000029'; |
| 4 |
use Test2::Require::AuthorTesting; |
| 5 |
|
| 6 |
use App::Yath::Tester qw/yath/; |
| 7 |
|
| 8 |
use File::Temp qw/tempfile/; |
| 9 |
|
| 10 |
my $dir = __FILE__; |
| 11 |
$dir =~ s{\.t$}{}g; |
| 12 |
$dir =~ s{^\./}{}; |
| 13 |
|
| 14 |
my ($fh, $cfile) = tempfile(SUFFIX => '.json'); |
| 15 |
close($fh); |
| 16 |
|
| 17 |
yath( |
| 18 |
command => 'test', |
| 19 |
args => ["-I$dir/lib", $dir, '--ext=tx', "--cover-write=$cfile", '-v'], |
| 20 |
exit => 0, |
| 21 |
); |
| 22 |
|
| 23 |
open($fh, '<', $cfile); |
| 24 |
my $json = join '' => <$fh>; |
| 25 |
my $coverage = decode_json($json); |
| 26 |
|
| 27 |
is( |
| 28 |
$coverage, |
| 29 |
{ |
| 30 |
'aggregator' => 'Test2::Harness::Log::CoverageAggregator::ByRun', |
| 31 |
'testmeta' => { |
| 32 |
't/integration/coverage/a.tx' => {'manager' => 'Manager', 'type' => 'split'}, |
| 33 |
't/integration/coverage/b.tx' => {'type' => 'flat'}, |
| 34 |
't/integration/coverage/c.tx' => {'manager' => 'Manager', 'type' => 'split'}, |
| 35 |
't/integration/coverage/once.tx' => {'type' => 'flat'}, |
| 36 |
't/integration/coverage/open.tx' => {'type' => 'flat'}, |
| 37 |
't/integration/coverage/x.tx' => {'type' => 'flat'}, |
| 38 |
}, |
| 39 |
'files' => { |
| 40 |
'Ax.pm' => { |
| 41 |
'*' => { |
| 42 |
't/integration/coverage/a.tx' => ['*'], |
| 43 |
't/integration/coverage/c.tx' => [{'subtest' => 'a'}], |
| 44 |
}, |
| 45 |
'a' => { |
| 46 |
't/integration/coverage/a.tx' => bag { |
| 47 |
item {'subtest' => 'c'}; |
| 48 |
item {'subtest' => 'b'}; |
| 49 |
item {'subtest' => 'a'}; |
| 50 |
end; |
| 51 |
}, |
| 52 |
't/integration/coverage/c.tx' => bag { |
| 53 |
item {'subtest' => 'c'}; |
| 54 |
item {'subtest' => 'a'}; |
| 55 |
end; |
| 56 |
}, |
| 57 |
}, |
| 58 |
'aa' => {'t/integration/coverage/a.tx' => [{'subtest' => 'a'}]}, |
| 59 |
}, |
| 60 |
'Bx.pm' => { |
| 61 |
'*' => { |
| 62 |
't/integration/coverage/a.tx' => ['*'], |
| 63 |
't/integration/coverage/b.tx' => ['*'], |
| 64 |
't/integration/coverage/x.tx' => ['*'], |
| 65 |
}, |
| 66 |
'<>' => {'t/integration/coverage/open.tx' => ['*']}, |
| 67 |
'b' => { |
| 68 |
't/integration/coverage/a.tx' => bag { |
| 69 |
item {'subtest' => 'c'}; |
| 70 |
item {'subtest' => 'b'}; |
| 71 |
end; |
| 72 |
}, |
| 73 |
't/integration/coverage/b.tx' => ['*'], |
| 74 |
}, |
| 75 |
}, |
| 76 |
'Cx.pm' => { |
| 77 |
'*' => { |
| 78 |
't/integration/coverage/a.tx' => ['*'], |
| 79 |
't/integration/coverage/c.tx' => [{'subtest' => 'c'}], |
| 80 |
}, |
| 81 |
'c' => { |
| 82 |
't/integration/coverage/a.tx' => bag { |
| 83 |
item '*'; |
| 84 |
item {'subtest' => 'c'}; |
| 85 |
end; |
| 86 |
}, |
| 87 |
't/integration/coverage/c.tx' => [{'subtest' => 'c'}] |
| 88 |
}, |
| 89 |
}, |
| 90 |
}, |
| 91 |
}, |
| 92 |
"Got predicted coverage data", |
| 93 |
); |
| 94 |
|
| 95 |
yath( |
| 96 |
command => 'test', |
| 97 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 98 |
exit => 0, |
| 99 |
env => {TEST_CASE => 'Ax'}, |
| 100 |
test => sub { |
| 101 |
my $out = shift; |
| 102 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 103 |
$_ = decode_json($_) for values %$input; |
| 104 |
is( |
| 105 |
$input, |
| 106 |
{ |
| 107 |
't/integration/coverage/a.tx' => {env => {COVER_TEST_SUBTESTS => 'a, b, c'}, stdin => "a\nb\nc\n", argv => ['a', 'b', 'c']}, |
| 108 |
't/integration/coverage/c.tx' => {env => {COVER_TEST_SUBTESTS => 'a, c'}, stdin => "a\nc\n", argv => ['a', 'c']}, |
| 109 |
}, |
| 110 |
"Test got the correct input about what subtests to run", |
| 111 |
); |
| 112 |
}, |
| 113 |
); |
| 114 |
|
| 115 |
yath( |
| 116 |
command => 'test', |
| 117 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 118 |
exit => 0, |
| 119 |
env => {TEST_CASE => 'Bx'}, |
| 120 |
test => sub { |
| 121 |
my $out = shift; |
| 122 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 123 |
$_ = decode_json($_) for values %$input; |
| 124 |
is( |
| 125 |
$input, |
| 126 |
{ |
| 127 |
# No manager, so run entire tests |
| 128 |
't/integration/coverage/b.tx' => {argv => [], env => {}, stdin => ''}, |
| 129 |
't/integration/coverage/x.tx' => {argv => [], env => {}, stdin => ''}, |
| 130 |
't/integration/coverage/open.tx' => {argv => [], env => {}, stdin => ''}, |
| 131 |
|
| 132 |
# Managed, so we have custom input |
| 133 |
't/integration/coverage/a.tx' => {'argv' => ['b', 'c'], 'env' => {'COVER_TEST_SUBTESTS' => 'b, c'}, 'stdin' => "b\nc\n"}, |
| 134 |
}, |
| 135 |
"Test got the correct input about what subtests to run", |
| 136 |
); |
| 137 |
}, |
| 138 |
); |
| 139 |
|
| 140 |
yath( |
| 141 |
command => 'test', |
| 142 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 143 |
exit => 0, |
| 144 |
env => {TEST_CASE => 'Cx'}, |
| 145 |
test => sub { |
| 146 |
my $out = shift; |
| 147 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 148 |
$_ = decode_json($_) for values %$input; |
| 149 |
is( |
| 150 |
$input, |
| 151 |
{ |
| 152 |
"t/integration/coverage/a.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 153 |
"t/integration/coverage/c.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 154 |
}, |
| 155 |
"Test got the correct input about what subtests to run", |
| 156 |
); |
| 157 |
}, |
| 158 |
); |
| 159 |
|
| 160 |
yath( |
| 161 |
command => 'test', |
| 162 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 163 |
exit => 0, |
| 164 |
env => {TEST_CASE => 'Bxb'}, |
| 165 |
test => sub { |
| 166 |
my $out = shift; |
| 167 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 168 |
$_ = decode_json($_) for values %$input; |
| 169 |
is( |
| 170 |
$input, |
| 171 |
{ |
| 172 |
"t/integration/coverage/b.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 173 |
"t/integration/coverage/open.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 174 |
"t/integration/coverage/x.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 175 |
|
| 176 |
"t/integration/coverage/a.tx" => {"argv" => ["b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "b, c"}, "stdin" => "b\nc\n"}, |
| 177 |
}, |
| 178 |
"Test got the correct input about what subtests to run", |
| 179 |
); |
| 180 |
}, |
| 181 |
); |
| 182 |
|
| 183 |
yath( |
| 184 |
command => 'test', |
| 185 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 186 |
exit => 0, |
| 187 |
env => {TEST_CASE => 'Cxc'}, |
| 188 |
test => sub { |
| 189 |
my $out = shift; |
| 190 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 191 |
$_ = decode_json($_) for values %$input; |
| 192 |
is( |
| 193 |
$input, |
| 194 |
{ |
| 195 |
"t/integration/coverage/a.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 196 |
"t/integration/coverage/c.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 197 |
}, |
| 198 |
"Test got the correct input about what subtests to run", |
| 199 |
); |
| 200 |
}, |
| 201 |
); |
| 202 |
|
| 203 |
yath( |
| 204 |
command => 'test', |
| 205 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 206 |
exit => 0, |
| 207 |
env => {TEST_CASE => 'Ax*'}, |
| 208 |
test => sub { |
| 209 |
my $out = shift; |
| 210 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 211 |
$_ = decode_json($_) for values %$input; |
| 212 |
is( |
| 213 |
$input, |
| 214 |
{ |
| 215 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 216 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 217 |
}, |
| 218 |
"Test got the correct input about what subtests to run", |
| 219 |
); |
| 220 |
}, |
| 221 |
); |
| 222 |
|
| 223 |
yath( |
| 224 |
command => 'test', |
| 225 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 226 |
exit => 0, |
| 227 |
env => {TEST_CASE => 'Axa'}, |
| 228 |
test => sub { |
| 229 |
my $out = shift; |
| 230 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 231 |
$_ = decode_json($_) for values %$input; |
| 232 |
is( |
| 233 |
$input, |
| 234 |
{ |
| 235 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 236 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 237 |
}, |
| 238 |
"Test got the correct input about what subtests to run", |
| 239 |
); |
| 240 |
}, |
| 241 |
); |
| 242 |
|
| 243 |
yath( |
| 244 |
command => 'test', |
| 245 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 246 |
exit => 0, |
| 247 |
env => {TEST_CASE => 'Axaa'}, |
| 248 |
test => sub { |
| 249 |
my $out = shift; |
| 250 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 251 |
$_ = decode_json($_) for values %$input; |
| 252 |
is( |
| 253 |
$input, |
| 254 |
{ |
| 255 |
"t/integration/coverage/a.tx" => {"argv" => ["a"], "env" => {"COVER_TEST_SUBTESTS" => "a"}, "stdin" => "a\n"}, |
| 256 |
"t/integration/coverage/c.tx" => {"argv" => ["a"], "env" => {"COVER_TEST_SUBTESTS" => "a"}, "stdin" => "a\n"}, |
| 257 |
}, |
| 258 |
"Test got the correct input about what subtests to run", |
| 259 |
); |
| 260 |
}, |
| 261 |
); |
| 262 |
|
| 263 |
yath( |
| 264 |
command => 'test', |
| 265 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 266 |
exit => 0, |
| 267 |
env => {TEST_CASE => 'Axaaa'}, |
| 268 |
test => sub { |
| 269 |
my $out = shift; |
| 270 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 271 |
$_ = decode_json($_) for values %$input; |
| 272 |
is( |
| 273 |
$input, |
| 274 |
{ |
| 275 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 276 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 277 |
}, |
| 278 |
"Test got the correct input about what subtests to run", |
| 279 |
); |
| 280 |
}, |
| 281 |
); |
| 282 |
|
| 283 |
yath( |
| 284 |
command => 'test', |
| 285 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 286 |
exit => 0, |
| 287 |
env => {TEST_CASE => 'AxCx'}, |
| 288 |
test => sub { |
| 289 |
my $out = shift; |
| 290 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 291 |
$_ = decode_json($_) for values %$input; |
| 292 |
is( |
| 293 |
$input, |
| 294 |
{ |
| 295 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 296 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 297 |
}, |
| 298 |
"Test got the correct input about what subtests to run", |
| 299 |
); |
| 300 |
}, |
| 301 |
); |
| 302 |
|
| 303 |
# Add some tests that do not exist, coverage testing shoudl warn and should skip them. |
| 304 |
$coverage->{testmeta}->{'t/integration/coverage/mia1.tx'} = $coverage->{testmeta}->{'t/integration/coverage/a.tx'}; |
| 305 |
$coverage->{testmeta}->{'t/integration/coverage/mia2.tx'} = $coverage->{testmeta}->{'t/integration/coverage/b.tx'}; |
| 306 |
|
| 307 |
$coverage->{files}->{'Ax.pm'}->{'*'}->{'t/integration/coverage/mia1.tx'} = ['*']; |
| 308 |
$coverage->{files}->{'Ax.pm'}->{'*'}->{'t/integration/coverage/mia2.tx'} = ['*']; |
| 309 |
|
| 310 |
open($fh, '>', $cfile) or die "Could not open file: $!"; |
| 311 |
my $njson = encode_json($coverage); |
| 312 |
print $fh $njson; |
| 313 |
close($fh); |
| 314 |
|
| 315 |
yath( |
| 316 |
command => 'test', |
| 317 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 318 |
exit => 0, |
| 319 |
env => {TEST_CASE => 'Ax'}, |
| 320 |
test => sub { |
| 321 |
my $out = shift; |
| 322 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 323 |
$_ = decode_json($_) for values %$input; |
| 324 |
is( |
| 325 |
$input, |
| 326 |
{ |
| 327 |
't/integration/coverage/a.tx' => {env => {COVER_TEST_SUBTESTS => 'a, b, c'}, stdin => "a\nb\nc\n", argv => ['a', 'b', 'c']}, |
| 328 |
't/integration/coverage/c.tx' => {env => {COVER_TEST_SUBTESTS => 'a, c'}, stdin => "a\nc\n", argv => ['a', 'c']}, |
| 329 |
}, |
| 330 |
"Test got the correct input about what subtests to run", |
| 331 |
); |
| 332 |
|
| 333 |
like( |
| 334 |
$out->{output}, |
| 335 |
qr{Coverage wants to run test 't/integration/coverage/mia1\.tx', but it does not exist, skipping\.\.\.}, |
| 336 |
"Skipped mia1 because it does not exist", |
| 337 |
); |
| 338 |
|
| 339 |
like( |
| 340 |
$out->{output}, |
| 341 |
qr{Coverage wants to run test 't/integration/coverage/mia2\.tx', but it does not exist, skipping\.\.\.}, |
| 342 |
"Skipped mia2 because it does not exist", |
| 343 |
); |
| 344 |
}, |
| 345 |
); |
| 346 |
|
| 347 |
done_testing; |