| 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 |
$dir =~ s/\d+$//; |
| 14 |
|
| 15 |
my ($fh, $cfile) = tempfile(SUFFIX => '.jsonl'); |
| 16 |
close($fh); |
| 17 |
|
| 18 |
yath( |
| 19 |
command => 'test', |
| 20 |
args => ["-I$dir/lib", $dir, '--ext=tx', "--cover-write=$cfile", '-v'], |
| 21 |
exit => 0, |
| 22 |
); |
| 23 |
|
| 24 |
my @coverage; |
| 25 |
open($fh, '<', $cfile); |
| 26 |
for my $line (<$fh>) { |
| 27 |
next unless $line; |
| 28 |
push @coverage => decode_json($line); |
| 29 |
} |
| 30 |
|
| 31 |
is( |
| 32 |
\@coverage, |
| 33 |
bag { |
| 34 |
item { |
| 35 |
'test' => 't/integration/coverage/a.tx', |
| 36 |
'manager' => 'Manager', |
| 37 |
'aggregator' => 'Test2::Harness::Log::CoverageAggregator::ByTest', |
| 38 |
'files' => { |
| 39 |
'Ax.pm' => { |
| 40 |
'*' => ['*'], |
| 41 |
'a' => bag { item {'subtest' => 'b'}; item {'subtest' => 'c'}; item {'subtest' => 'a'} }, |
| 42 |
'aa' => [{'subtest' => 'a'}], |
| 43 |
}, |
| 44 |
'Bx.pm' => { |
| 45 |
'b' => bag { item {'subtest' => 'b'}; item {'subtest' => 'c'} }, |
| 46 |
'*' => ['*'], |
| 47 |
}, |
| 48 |
'Cx.pm' => { |
| 49 |
'c' => bag { item '*'; item {'subtest' => 'c'} }, |
| 50 |
'*' => ['*'], |
| 51 |
}, |
| 52 |
}, |
| 53 |
}; |
| 54 |
|
| 55 |
item { |
| 56 |
'test' => 't/integration/coverage/b.tx', |
| 57 |
'aggregator' => 'Test2::Harness::Log::CoverageAggregator::ByTest', |
| 58 |
'files' => { |
| 59 |
'Bx.pm' => { |
| 60 |
'b' => ['*'], |
| 61 |
'*' => ['*'], |
| 62 |
}, |
| 63 |
}, |
| 64 |
}; |
| 65 |
|
| 66 |
item { |
| 67 |
'test' => 't/integration/coverage/c.tx', |
| 68 |
'manager' => 'Manager', |
| 69 |
'aggregator' => 'Test2::Harness::Log::CoverageAggregator::ByTest', |
| 70 |
'files' => { |
| 71 |
'Ax.pm' => { |
| 72 |
'a' => bag { item {'subtest' => 'c'}; item {'subtest' => 'a'} }, |
| 73 |
'*' => [{'subtest' => 'a'}], |
| 74 |
}, |
| 75 |
'Cx.pm' => { |
| 76 |
'c' => [{'subtest' => 'c'}], |
| 77 |
'*' => [{'subtest' => 'c'}], |
| 78 |
} |
| 79 |
} |
| 80 |
}; |
| 81 |
|
| 82 |
item { |
| 83 |
'test' => 't/integration/coverage/once.tx', |
| 84 |
'aggregator' => 'Test2::Harness::Log::CoverageAggregator::ByTest', |
| 85 |
'files' => {}, |
| 86 |
}; |
| 87 |
|
| 88 |
item { |
| 89 |
'aggregator' => 'Test2::Harness::Log::CoverageAggregator::ByTest', |
| 90 |
'test' => 't/integration/coverage/open.tx', |
| 91 |
'files' => {'Bx.pm' => {'<>' => ['*']}}, |
| 92 |
}; |
| 93 |
|
| 94 |
item { |
| 95 |
'test' => 't/integration/coverage/x.tx', |
| 96 |
'aggregator' => 'Test2::Harness::Log::CoverageAggregator::ByTest', |
| 97 |
'files' => {'Bx.pm' => {'*' => ['*']}}, |
| 98 |
}; |
| 99 |
}, |
| 100 |
"Got predicted coverage data", |
| 101 |
); |
| 102 |
|
| 103 |
yath( |
| 104 |
command => 'test', |
| 105 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 106 |
exit => 0, |
| 107 |
env => {TEST_CASE => 'Ax'}, |
| 108 |
test => sub { |
| 109 |
my $out = shift; |
| 110 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 111 |
$_ = decode_json($_) for values %$input; |
| 112 |
is( |
| 113 |
$input, |
| 114 |
{ |
| 115 |
't/integration/coverage/a.tx' => {env => {COVER_TEST_SUBTESTS => 'a, b, c'}, stdin => "a\nb\nc\n", argv => ['a', 'b', 'c']}, |
| 116 |
't/integration/coverage/c.tx' => {env => {COVER_TEST_SUBTESTS => 'a, c'}, stdin => "a\nc\n", argv => ['a', 'c']}, |
| 117 |
}, |
| 118 |
"Test got the correct input about what subtests to run", |
| 119 |
); |
| 120 |
}, |
| 121 |
); |
| 122 |
|
| 123 |
yath( |
| 124 |
command => 'test', |
| 125 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 126 |
exit => 0, |
| 127 |
env => {TEST_CASE => 'Bx'}, |
| 128 |
test => sub { |
| 129 |
my $out = shift; |
| 130 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 131 |
$_ = decode_json($_) for values %$input; |
| 132 |
is( |
| 133 |
$input, |
| 134 |
{ |
| 135 |
# No manager, so run entire tests |
| 136 |
't/integration/coverage/b.tx' => {argv => [], env => {}, stdin => ''}, |
| 137 |
't/integration/coverage/x.tx' => {argv => [], env => {}, stdin => ''}, |
| 138 |
't/integration/coverage/open.tx' => {argv => [], env => {}, stdin => ''}, |
| 139 |
|
| 140 |
# Managed, so we have custom input |
| 141 |
't/integration/coverage/a.tx' => {'argv' => ['b', 'c'], 'env' => {'COVER_TEST_SUBTESTS' => 'b, c'}, 'stdin' => "b\nc\n"}, |
| 142 |
}, |
| 143 |
"Test got the correct input about what subtests to run", |
| 144 |
); |
| 145 |
}, |
| 146 |
); |
| 147 |
|
| 148 |
yath( |
| 149 |
command => 'test', |
| 150 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 151 |
exit => 0, |
| 152 |
env => {TEST_CASE => 'Cx'}, |
| 153 |
test => sub { |
| 154 |
my $out = shift; |
| 155 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 156 |
$_ = decode_json($_) for values %$input; |
| 157 |
is( |
| 158 |
$input, |
| 159 |
{ |
| 160 |
"t/integration/coverage/a.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 161 |
"t/integration/coverage/c.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 162 |
}, |
| 163 |
"Test got the correct input about what subtests to run", |
| 164 |
); |
| 165 |
}, |
| 166 |
); |
| 167 |
|
| 168 |
yath( |
| 169 |
command => 'test', |
| 170 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 171 |
exit => 0, |
| 172 |
env => {TEST_CASE => 'Bxb'}, |
| 173 |
test => sub { |
| 174 |
my $out = shift; |
| 175 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 176 |
$_ = decode_json($_) for values %$input; |
| 177 |
is( |
| 178 |
$input, |
| 179 |
{ |
| 180 |
"t/integration/coverage/b.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 181 |
"t/integration/coverage/open.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 182 |
"t/integration/coverage/x.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 183 |
|
| 184 |
"t/integration/coverage/a.tx" => {"argv" => ["b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "b, c"}, "stdin" => "b\nc\n"}, |
| 185 |
}, |
| 186 |
"Test got the correct input about what subtests to run", |
| 187 |
); |
| 188 |
}, |
| 189 |
); |
| 190 |
|
| 191 |
yath( |
| 192 |
command => 'test', |
| 193 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 194 |
exit => 0, |
| 195 |
env => {TEST_CASE => 'Cxc'}, |
| 196 |
test => sub { |
| 197 |
my $out = shift; |
| 198 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 199 |
$_ = decode_json($_) for values %$input; |
| 200 |
is( |
| 201 |
$input, |
| 202 |
{ |
| 203 |
"t/integration/coverage/a.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 204 |
"t/integration/coverage/c.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 205 |
}, |
| 206 |
"Test got the correct input about what subtests to run", |
| 207 |
); |
| 208 |
}, |
| 209 |
); |
| 210 |
|
| 211 |
yath( |
| 212 |
command => 'test', |
| 213 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 214 |
exit => 0, |
| 215 |
env => {TEST_CASE => 'Ax*'}, |
| 216 |
test => sub { |
| 217 |
my $out = shift; |
| 218 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 219 |
$_ = decode_json($_) for values %$input; |
| 220 |
is( |
| 221 |
$input, |
| 222 |
{ |
| 223 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 224 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 225 |
}, |
| 226 |
"Test got the correct input about what subtests to run", |
| 227 |
); |
| 228 |
}, |
| 229 |
); |
| 230 |
|
| 231 |
yath( |
| 232 |
command => 'test', |
| 233 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 234 |
exit => 0, |
| 235 |
env => {TEST_CASE => 'Axa'}, |
| 236 |
test => sub { |
| 237 |
my $out = shift; |
| 238 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 239 |
$_ = decode_json($_) for values %$input; |
| 240 |
is( |
| 241 |
$input, |
| 242 |
{ |
| 243 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 244 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 245 |
}, |
| 246 |
"Test got the correct input about what subtests to run", |
| 247 |
); |
| 248 |
}, |
| 249 |
); |
| 250 |
|
| 251 |
yath( |
| 252 |
command => 'test', |
| 253 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 254 |
exit => 0, |
| 255 |
env => {TEST_CASE => 'Axaa'}, |
| 256 |
test => sub { |
| 257 |
my $out = shift; |
| 258 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 259 |
$_ = decode_json($_) for values %$input; |
| 260 |
is( |
| 261 |
$input, |
| 262 |
{ |
| 263 |
"t/integration/coverage/a.tx" => {"argv" => ["a"], "env" => {"COVER_TEST_SUBTESTS" => "a"}, "stdin" => "a\n"}, |
| 264 |
"t/integration/coverage/c.tx" => {"argv" => ["a"], "env" => {"COVER_TEST_SUBTESTS" => "a"}, "stdin" => "a\n"}, |
| 265 |
}, |
| 266 |
"Test got the correct input about what subtests to run", |
| 267 |
); |
| 268 |
}, |
| 269 |
); |
| 270 |
|
| 271 |
yath( |
| 272 |
command => 'test', |
| 273 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 274 |
exit => 0, |
| 275 |
env => {TEST_CASE => 'Axaaa'}, |
| 276 |
test => sub { |
| 277 |
my $out = shift; |
| 278 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 279 |
$_ = decode_json($_) for values %$input; |
| 280 |
is( |
| 281 |
$input, |
| 282 |
{ |
| 283 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 284 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 285 |
}, |
| 286 |
"Test got the correct input about what subtests to run", |
| 287 |
); |
| 288 |
}, |
| 289 |
); |
| 290 |
|
| 291 |
yath( |
| 292 |
command => 'test', |
| 293 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$cfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 294 |
exit => 0, |
| 295 |
env => {TEST_CASE => 'AxCx'}, |
| 296 |
test => sub { |
| 297 |
my $out = shift; |
| 298 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 299 |
$_ = decode_json($_) for values %$input; |
| 300 |
is( |
| 301 |
$input, |
| 302 |
{ |
| 303 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 304 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 305 |
}, |
| 306 |
"Test got the correct input about what subtests to run", |
| 307 |
); |
| 308 |
}, |
| 309 |
); |
| 310 |
|
| 311 |
done_testing; |