diff --git a/composer.json b/composer.json index 32f9022c..a2c0b0ce 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "require": { "php": "^8.1.0", "brianium/paratest": "^7.2.0", - "nunomaduro/collision": "^7.5.2", + "nunomaduro/collision": "^7.6.0", "nunomaduro/termwind": "^1.15.1", "pestphp/pest-plugin": "^2.0.1", "pestphp/pest-plugin-arch": "^2.2.0", diff --git a/src/Plugins/Parallel/Paratest/ResultPrinter.php b/src/Plugins/Parallel/Paratest/ResultPrinter.php index 4602ee31..f9d96ca2 100644 --- a/src/Plugins/Parallel/Paratest/ResultPrinter.php +++ b/src/Plugins/Parallel/Paratest/ResultPrinter.php @@ -121,8 +121,7 @@ final class ResultPrinter $unexpectedOutput = $this->tail($outputFile); if ($unexpectedOutput !== '') { - // if unexpected output only contains the letter "T", like "T", or "TT", or "TTT", etc, then ignore it. - if (preg_match('/^T+$/', $unexpectedOutput) !== false) { + if (preg_match('/^T+$/', $unexpectedOutput) > 0) { return; } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 4a22473a..0fda7cb9 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -808,6 +808,9 @@ PASS Tests\Fixtures\ExampleTest ✓ it example 2 + WARN Tests\Fixtures\UnexpectedOutput + - output + PASS Tests\Helpers\TestInHelpers ✓ it executes tests in the Helpers directory @@ -1035,7 +1038,11 @@ ✓ todo ✓ todo in parallel + PASS Tests\Visual\UnexpectedOutput + ✓ unexpected output with (['']) + ✓ unexpected output with (['--parallel']) + PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 8 todos, 17 skipped, 716 passed (1733 assertions) \ No newline at end of file + Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 8 todos, 18 skipped, 718 passed (1735 assertions) \ No newline at end of file diff --git a/tests/.snapshots/unexpected-output-parallel.txt b/tests/.snapshots/unexpected-output-parallel.txt new file mode 100644 index 00000000..1c8ccd25 --- /dev/null +++ b/tests/.snapshots/unexpected-output-parallel.txt @@ -0,0 +1,23 @@ + + .this is unexpected output! + ──────────────────────────────────────────────────────────────────────────── + RISKY Tests\Fixtures\UnexpectedOutput > output + This test printed output: this is unexpected output + + at src/Support/StateGenerator.php:58 + 54▕ foreach ($riskyEvents as $riskyEvent) { + 55▕ $state->add(TestResult::fromPestParallelTestCase( + 56▕ $riskyEvent->test(), + 57▕ TestResult::RISKY, + ➜ 58▕ ThrowableBuilder::from(new TestOutcome($riskyEvent->message())) + 59▕ )); + 60▕ } + 61▕ } + 62▕ + + 1 src/Support/StateGenerator.php:58 + +5 vendor frames + 7 src/Plugins/Actions/CallsHandleArguments.php:29 + + + Tests: 1 risky, 1 passed (2 assertions) \ No newline at end of file diff --git a/tests/.snapshots/unexpected-output.txt b/tests/.snapshots/unexpected-output.txt new file mode 100644 index 00000000..29529993 --- /dev/null +++ b/tests/.snapshots/unexpected-output.txt @@ -0,0 +1,20 @@ +this is unexpected output + WARN Tests\Fixtures\UnexpectedOutput + ! output → This test printed output: this is unexpected output + ──────────────────────────────────────────────────────────────────────────── + RISKY Tests\Fixtures\UnexpectedOutput > output + This test printed output: this is unexpected output + + at src/Kernel.php:86 + 82▕ { + 83▕ $args = CallsHandleArguments::execute($args); + 84▕ + 85▕ try { + ➜ 86▕ $this->application->run($args); + 87▕ } catch (NoDirtyTestsFound) { + 88▕ $this->output->writeln([ + 89▕ '', + 90▕ ' INFO No tests found.', + + + Tests: 1 risky (1 assertions) \ No newline at end of file diff --git a/tests/Fixtures/UnexpectedOutput.php b/tests/Fixtures/UnexpectedOutput.php new file mode 100644 index 00000000..170d17d7 --- /dev/null +++ b/tests/Fixtures/UnexpectedOutput.php @@ -0,0 +1,7 @@ +toBeTrue(); +})->skip(! isset($_SERVER['COLLISION_TEST'])); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index a67437b2..6d7cc11e 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -18,7 +18,7 @@ $run = function () { test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 1 deprecated, 3 warnings, 4 incomplete, 1 notice, 8 todos, 14 skipped, 705 passed (1718 assertions)') + ->toContain('Tests: 1 deprecated, 3 warnings, 4 incomplete, 1 notice, 8 todos, 15 skipped, 705 passed (1718 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); diff --git a/tests/Visual/UnexpectedOutput.php b/tests/Visual/UnexpectedOutput.php new file mode 100644 index 00000000..323ae0f5 --- /dev/null +++ b/tests/Visual/UnexpectedOutput.php @@ -0,0 +1,43 @@ + 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'COLLISION_TEST' => true] + )); + + $process->run(); + + return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); + }; + + if (getenv('REBUILD_SNAPSHOTS')) { + $outputContent = explode("\n", $output()); + array_pop($outputContent); + array_pop($outputContent); + array_pop($outputContent); + + if (in_array('--parallel', $arguments)) { + array_pop($outputContent); + array_pop($outputContent); + } + + file_put_contents($snapshot, implode("\n", $outputContent)); + + $this->markTestSkipped('Snapshot rebuilt.'); + } + + expect($output()) + ->toContain(file_get_contents($snapshot)); +})->with([ + [['']], + [['--parallel']], +])->skipOnWindows();