mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
tests: unexpected output
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1.0",
|
"php": "^8.1.0",
|
||||||
"brianium/paratest": "^7.2.0",
|
"brianium/paratest": "^7.2.0",
|
||||||
"nunomaduro/collision": "^7.5.2",
|
"nunomaduro/collision": "^7.6.0",
|
||||||
"nunomaduro/termwind": "^1.15.1",
|
"nunomaduro/termwind": "^1.15.1",
|
||||||
"pestphp/pest-plugin": "^2.0.1",
|
"pestphp/pest-plugin": "^2.0.1",
|
||||||
"pestphp/pest-plugin-arch": "^2.2.0",
|
"pestphp/pest-plugin-arch": "^2.2.0",
|
||||||
|
|||||||
@ -121,8 +121,7 @@ final class ResultPrinter
|
|||||||
|
|
||||||
$unexpectedOutput = $this->tail($outputFile);
|
$unexpectedOutput = $this->tail($outputFile);
|
||||||
if ($unexpectedOutput !== '') {
|
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) > 0) {
|
||||||
if (preg_match('/^T+$/', $unexpectedOutput) !== false) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -808,6 +808,9 @@
|
|||||||
PASS Tests\Fixtures\ExampleTest
|
PASS Tests\Fixtures\ExampleTest
|
||||||
✓ it example 2
|
✓ it example 2
|
||||||
|
|
||||||
|
WARN Tests\Fixtures\UnexpectedOutput
|
||||||
|
- output
|
||||||
|
|
||||||
PASS Tests\Helpers\TestInHelpers
|
PASS Tests\Helpers\TestInHelpers
|
||||||
✓ it executes tests in the Helpers directory
|
✓ it executes tests in the Helpers directory
|
||||||
|
|
||||||
@ -1035,7 +1038,11 @@
|
|||||||
✓ todo
|
✓ todo
|
||||||
✓ todo in parallel
|
✓ todo in parallel
|
||||||
|
|
||||||
|
PASS Tests\Visual\UnexpectedOutput
|
||||||
|
✓ unexpected output with ([''])
|
||||||
|
✓ unexpected output with (['--parallel'])
|
||||||
|
|
||||||
PASS Tests\Visual\Version
|
PASS Tests\Visual\Version
|
||||||
✓ visual snapshot of help command output
|
✓ visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 8 todos, 17 skipped, 716 passed (1733 assertions)
|
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 8 todos, 18 skipped, 718 passed (1735 assertions)
|
||||||
23
tests/.snapshots/unexpected-output-parallel.txt
Normal file
23
tests/.snapshots/unexpected-output-parallel.txt
Normal file
@ -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)
|
||||||
20
tests/.snapshots/unexpected-output.txt
Normal file
20
tests/.snapshots/unexpected-output.txt
Normal file
@ -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)
|
||||||
7
tests/Fixtures/UnexpectedOutput.php
Normal file
7
tests/Fixtures/UnexpectedOutput.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
test('output', function () {
|
||||||
|
echo 'this is unexpected output';
|
||||||
|
|
||||||
|
expect(true)->toBeTrue();
|
||||||
|
})->skip(! isset($_SERVER['COLLISION_TEST']));
|
||||||
@ -18,7 +18,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
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');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
43
tests/Visual/UnexpectedOutput.php
Normal file
43
tests/Visual/UnexpectedOutput.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
test('unexpected output', function (array $arguments) {
|
||||||
|
$snapshot = __DIR__.'/../.snapshots/unexpected-output.txt';
|
||||||
|
|
||||||
|
if (in_array('--parallel', $arguments)) {
|
||||||
|
$snapshot = __DIR__.'/../.snapshots/unexpected-output-parallel.txt';
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = function () use ($arguments) {
|
||||||
|
$process = (new Symfony\Component\Process\Process(
|
||||||
|
array_merge(['php', 'bin/pest', 'tests/Fixtures/UnexpectedOutput.php'], $arguments),
|
||||||
|
null,
|
||||||
|
['COLLISION_PRINTER' => '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();
|
||||||
Reference in New Issue
Block a user