| 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, $logfile) = tempfile("yathlog-$$-XXXXXXXX", TMPDIR => 1, UNLINK => 1, SUFFIX => '.jsonl.bz2'); |
| 16 |
close($fh); |
| 17 |
|
| 18 |
yath( |
| 19 |
command => 'test', |
| 20 |
args => ["-I$dir/lib", $dir, '--ext=tx', '-v', '-B', '-F' => $logfile, '--cover-files', '--cover-agg' => 'ByTest'], |
| 21 |
exit => 0, |
| 22 |
); |
| 23 |
|
| 24 |
yath( |
| 25 |
command => 'test', |
| 26 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 27 |
exit => 0, |
| 28 |
env => {TEST_CASE => 'Ax'}, |
| 29 |
test => sub { |
| 30 |
my $out = shift; |
| 31 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 32 |
$_ = decode_json($_) for values %$input; |
| 33 |
is( |
| 34 |
$input, |
| 35 |
{ |
| 36 |
't/integration/coverage/a.tx' => {env => {COVER_TEST_SUBTESTS => 'a, b, c'}, stdin => "a\nb\nc\n", argv => ['a', 'b', 'c']}, |
| 37 |
't/integration/coverage/c.tx' => {env => {COVER_TEST_SUBTESTS => 'a, c'}, stdin => "a\nc\n", argv => ['a', 'c']}, |
| 38 |
}, |
| 39 |
"Test got the correct input about what subtests to run", |
| 40 |
); |
| 41 |
}, |
| 42 |
); |
| 43 |
|
| 44 |
yath( |
| 45 |
command => 'test', |
| 46 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 47 |
exit => 0, |
| 48 |
env => {TEST_CASE => 'Bx'}, |
| 49 |
test => sub { |
| 50 |
my $out = shift; |
| 51 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 52 |
$_ = decode_json($_) for values %$input; |
| 53 |
is( |
| 54 |
$input, |
| 55 |
{ |
| 56 |
# No manager, so run entire tests |
| 57 |
't/integration/coverage/b.tx' => {argv => [], env => {}, stdin => ''}, |
| 58 |
't/integration/coverage/x.tx' => {argv => [], env => {}, stdin => ''}, |
| 59 |
't/integration/coverage/open.tx' => {argv => [], env => {}, stdin => ''}, |
| 60 |
|
| 61 |
# Managed, so we have custom input |
| 62 |
't/integration/coverage/a.tx' => {'argv' => ['b', 'c'], 'env' => {'COVER_TEST_SUBTESTS' => 'b, c'}, 'stdin' => "b\nc\n"}, |
| 63 |
}, |
| 64 |
"Test got the correct input about what subtests to run", |
| 65 |
); |
| 66 |
}, |
| 67 |
); |
| 68 |
|
| 69 |
yath( |
| 70 |
command => 'test', |
| 71 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 72 |
exit => 0, |
| 73 |
env => {TEST_CASE => 'Cx'}, |
| 74 |
test => sub { |
| 75 |
my $out = shift; |
| 76 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 77 |
$_ = decode_json($_) for values %$input; |
| 78 |
is( |
| 79 |
$input, |
| 80 |
{ |
| 81 |
"t/integration/coverage/a.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 82 |
"t/integration/coverage/c.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 83 |
}, |
| 84 |
"Test got the correct input about what subtests to run", |
| 85 |
); |
| 86 |
}, |
| 87 |
); |
| 88 |
|
| 89 |
yath( |
| 90 |
command => 'test', |
| 91 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 92 |
exit => 0, |
| 93 |
env => {TEST_CASE => 'Bxb'}, |
| 94 |
test => sub { |
| 95 |
my $out = shift; |
| 96 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 97 |
$_ = decode_json($_) for values %$input; |
| 98 |
is( |
| 99 |
$input, |
| 100 |
{ |
| 101 |
"t/integration/coverage/b.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 102 |
"t/integration/coverage/open.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 103 |
"t/integration/coverage/x.tx" => {"argv" => [], "env" => {}, "stdin" => ""}, |
| 104 |
|
| 105 |
"t/integration/coverage/a.tx" => {"argv" => ["b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "b, c"}, "stdin" => "b\nc\n"}, |
| 106 |
}, |
| 107 |
"Test got the correct input about what subtests to run", |
| 108 |
); |
| 109 |
}, |
| 110 |
); |
| 111 |
|
| 112 |
yath( |
| 113 |
command => 'test', |
| 114 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 115 |
exit => 0, |
| 116 |
env => {TEST_CASE => 'Cxc'}, |
| 117 |
test => sub { |
| 118 |
my $out = shift; |
| 119 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 120 |
$_ = decode_json($_) for values %$input; |
| 121 |
is( |
| 122 |
$input, |
| 123 |
{ |
| 124 |
"t/integration/coverage/a.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 125 |
"t/integration/coverage/c.tx" => {"argv" => ["c"], "env" => {"COVER_TEST_SUBTESTS" => "c"}, "stdin" => "c\n"}, |
| 126 |
}, |
| 127 |
"Test got the correct input about what subtests to run", |
| 128 |
); |
| 129 |
}, |
| 130 |
); |
| 131 |
|
| 132 |
yath( |
| 133 |
command => 'test', |
| 134 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 135 |
exit => 0, |
| 136 |
env => {TEST_CASE => 'Ax*'}, |
| 137 |
test => sub { |
| 138 |
my $out = shift; |
| 139 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 140 |
$_ = decode_json($_) for values %$input; |
| 141 |
is( |
| 142 |
$input, |
| 143 |
{ |
| 144 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 145 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 146 |
}, |
| 147 |
"Test got the correct input about what subtests to run", |
| 148 |
); |
| 149 |
}, |
| 150 |
); |
| 151 |
|
| 152 |
yath( |
| 153 |
command => 'test', |
| 154 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 155 |
exit => 0, |
| 156 |
env => {TEST_CASE => 'Axa'}, |
| 157 |
test => sub { |
| 158 |
my $out = shift; |
| 159 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 160 |
$_ = decode_json($_) for values %$input; |
| 161 |
is( |
| 162 |
$input, |
| 163 |
{ |
| 164 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 165 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 166 |
}, |
| 167 |
"Test got the correct input about what subtests to run", |
| 168 |
); |
| 169 |
}, |
| 170 |
); |
| 171 |
|
| 172 |
yath( |
| 173 |
command => 'test', |
| 174 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 175 |
exit => 0, |
| 176 |
env => {TEST_CASE => 'Axaa'}, |
| 177 |
test => sub { |
| 178 |
my $out = shift; |
| 179 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 180 |
$_ = decode_json($_) for values %$input; |
| 181 |
is( |
| 182 |
$input, |
| 183 |
{ |
| 184 |
"t/integration/coverage/a.tx" => {"argv" => ["a"], "env" => {"COVER_TEST_SUBTESTS" => "a"}, "stdin" => "a\n"}, |
| 185 |
"t/integration/coverage/c.tx" => {"argv" => ["a"], "env" => {"COVER_TEST_SUBTESTS" => "a"}, "stdin" => "a\n"}, |
| 186 |
}, |
| 187 |
"Test got the correct input about what subtests to run", |
| 188 |
); |
| 189 |
}, |
| 190 |
); |
| 191 |
|
| 192 |
yath( |
| 193 |
command => 'test', |
| 194 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 195 |
exit => 0, |
| 196 |
env => {TEST_CASE => 'Axaaa'}, |
| 197 |
test => sub { |
| 198 |
my $out = shift; |
| 199 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 200 |
$_ = decode_json($_) for values %$input; |
| 201 |
is( |
| 202 |
$input, |
| 203 |
{ |
| 204 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 205 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 206 |
}, |
| 207 |
"Test got the correct input about what subtests to run", |
| 208 |
); |
| 209 |
}, |
| 210 |
); |
| 211 |
|
| 212 |
yath( |
| 213 |
command => 'test', |
| 214 |
args => ["-D$dir/lib", "-I$dir/lib", '--ext=tx', "--cover-from=$logfile", '--plugin' => '+Plugin', '--changed-only', '-v'], |
| 215 |
exit => 0, |
| 216 |
env => {TEST_CASE => 'AxCx'}, |
| 217 |
test => sub { |
| 218 |
my $out = shift; |
| 219 |
my $input = +{$out->{output} =~ m/INPUT (\S+): (\{.+\})$/gm}; |
| 220 |
$_ = decode_json($_) for values %$input; |
| 221 |
is( |
| 222 |
$input, |
| 223 |
{ |
| 224 |
"t/integration/coverage/a.tx" => {"argv" => ["a", "b", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, b, c"}, "stdin" => "a\nb\nc\n"}, |
| 225 |
"t/integration/coverage/c.tx" => {"argv" => ["a", "c"], "env" => {"COVER_TEST_SUBTESTS" => "a, c"}, "stdin" => "a\nc\n"}, |
| 226 |
}, |
| 227 |
"Test got the correct input about what subtests to run", |
| 228 |
); |
| 229 |
}, |
| 230 |
); |
| 231 |
|
| 232 |
done_testing; |