mirror of
https://github.com/pestphp/pest.git
synced 2026-12-03 22:45:06 +01:00
Skip execution for empty test shards (#2041)
Co-authored-by: haranishi <223786623+haranishi@users.noreply.github.com> Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
@@ -124,10 +124,6 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
||||
'testsCount' => count($tests),
|
||||
];
|
||||
|
||||
if ($testsToRun === []) {
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
$filter = $this->buildFilterArgument($testsToRun);
|
||||
|
||||
$this->ensureFilterLengthIsSafe($filter);
|
||||
@@ -175,7 +171,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
||||
private function allTests(array $arguments): array
|
||||
{
|
||||
$command = $this->buildListTestsCommand(
|
||||
$arguments,
|
||||
$this->popArgument('--list-tests', $arguments),
|
||||
TestSuite::getInstance()->testPath,
|
||||
);
|
||||
|
||||
@@ -247,7 +243,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
|
||||
private function buildFilterArgument(array $testsToRun): string
|
||||
{
|
||||
if ($testsToRun === []) {
|
||||
return '';
|
||||
return '(?!)';
|
||||
}
|
||||
|
||||
/** @var array<string, mixed> $tree */
|
||||
|
||||
@@ -1880,7 +1880,7 @@
|
||||
✓ buildFilterArgument → it generates compact filter for single test
|
||||
✓ buildFilterArgument → it generates compact filter for multiple tests with common prefix
|
||||
✓ buildFilterArgument → it generates compact filter for tests with different namespaces
|
||||
✓ buildFilterArgument → it returns empty string for empty test list
|
||||
✓ buildFilterArgument → it generates a filter that selects no tests for an empty test list
|
||||
✓ buildFilterArgument → it generates compact filter for deeply nested namespaces
|
||||
✓ buildFilterArgument → it handles mix of nested and flat namespaces
|
||||
✓ buildFilterArgument → it does not match a class outside of the shard when another class name is its prefix
|
||||
@@ -2498,6 +2498,14 @@
|
||||
✓ parallel counts a shared issue only once across recycled workers with ('notice', 'shares notice', 'notice')
|
||||
✓ parallel combines stop-on counts from different workers and cleans up their files
|
||||
|
||||
PASS Tests\Visual\Shard
|
||||
✓ an empty shard runs no tests with dataset "sequential"
|
||||
✓ an empty shard runs no tests with dataset "parallel"
|
||||
✓ an empty shard runs no tests with dataset "sequential with fail-on-empty-test-suite"
|
||||
✓ an empty shard runs no tests with dataset "parallel with fail-on-empty-test-suite"
|
||||
✓ an empty shard lists no tests
|
||||
✓ a non-empty shard runs its assigned test
|
||||
|
||||
PASS Tests\Visual\SingleTestOrDirectory
|
||||
✓ allows to run a single test
|
||||
✓ allows to run a directory
|
||||
@@ -2529,4 +2537,4 @@
|
||||
✓ pass with dataset with ('my-datas-set-value')
|
||||
✓ within describe → pass with dataset with ('my-datas-set-value')
|
||||
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1833 passed (4181 assertions)
|
||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1839 passed (4203 assertions)
|
||||
@@ -94,7 +94,7 @@ describe('buildFilterArgument', function (): void {
|
||||
expect($filter)->toBe('Tests\\\\(Unit\\\\FooTest::|Feature\\\\BarTest::)');
|
||||
});
|
||||
|
||||
it('returns empty string for empty test list', function (): void {
|
||||
it('generates a filter that selects no tests for an empty test list', function (): void {
|
||||
$output = new BufferedOutput;
|
||||
$shard = new Shard($output);
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('buildFilterArgument', function (): void {
|
||||
|
||||
$filter = $method->invoke($shard, []);
|
||||
|
||||
expect($filter)->toBeEmpty();
|
||||
expect('Tests\\Unit\\ExampleTest::testExample')->not->toMatch('/'.$filter.'/');
|
||||
});
|
||||
|
||||
it('generates compact filter for deeply nested namespaces', function (): void {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
test('an empty shard runs no tests', function (int $exitCode, string ...$arguments): void {
|
||||
$process = new Process([
|
||||
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
||||
'--colors=never', '--shard=2/2', ...$arguments,
|
||||
], dirname(__DIR__, 2));
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe($exitCode)
|
||||
->and(removeAnsiEscapeSequences($process->getOutput()))
|
||||
->toContain('No tests found.', '2 of 2 — 0 files ran, out of 1.')
|
||||
->not->toContain('example 1');
|
||||
})->with([
|
||||
'sequential' => [0],
|
||||
'parallel' => [0, '--parallel', '--processes=2'],
|
||||
'sequential with fail-on-empty-test-suite' => [1, '--fail-on-empty-test-suite'],
|
||||
'parallel with fail-on-empty-test-suite' => [1, '--parallel', '--processes=2', '--fail-on-empty-test-suite'],
|
||||
]);
|
||||
|
||||
test('an empty shard lists no tests', function (): void {
|
||||
$process = new Process([
|
||||
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
||||
'--colors=never', '--shard=2/2', '--list-tests',
|
||||
], dirname(__DIR__, 2));
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0)
|
||||
->and($process->getOutput())->toContain('Available test')
|
||||
->not->toContain('__pest_evaluable_it_example_1', 'example 1');
|
||||
});
|
||||
|
||||
test('a non-empty shard runs its assigned test', function (): void {
|
||||
$process = new Process([
|
||||
PHP_BINARY, 'bin/pest', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
|
||||
'--colors=never', '--shard=1/2',
|
||||
], dirname(__DIR__, 2));
|
||||
|
||||
$process->run();
|
||||
|
||||
expect($process->getExitCode())->toBe(0)
|
||||
->and($process->getOutput())->toContain('1 passed', '1 of 2 — 1 file ran, out of 1.');
|
||||
});
|
||||
Reference in New Issue
Block a user