forked from paratestphp/paratest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle unexpected output (paratestphp#769)
- Loading branch information
Showing
14 changed files
with
297 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ParaTest\WrapperRunner; | ||
|
||
use PHPUnit\TextUI\Output\Printer; | ||
|
||
use function preg_match; | ||
|
||
/** @internal */ | ||
final class ProgressPrinterOutput implements Printer | ||
{ | ||
public function __construct( | ||
private readonly Printer $progressPrinter, | ||
private readonly Printer $outputPrinter, | ||
) { | ||
} | ||
|
||
public function print(string $buffer): void | ||
{ | ||
// Skip anything in \PHPUnit\TextUI\Output\Default\ProgressPrinter\ProgressPrinter::printProgress except $progress | ||
if ( | ||
$buffer === "\n" | ||
|| preg_match('/^ +$/', $buffer) === 1 | ||
|| preg_match('/^ \\d+ \\/ \\d+ \\(...%\\)$/', $buffer) === 1 | ||
) { | ||
return; | ||
} | ||
|
||
match ($buffer) { | ||
'E', 'F', 'I', 'N', 'D', 'R', 'W', 'S', '.' => $this->progressPrinter->print($buffer), | ||
default => $this->outputPrinter->print($buffer), | ||
}; | ||
} | ||
|
||
public function flush(): void | ||
{ | ||
$this->progressPrinter->flush(); | ||
$this->outputPrinter->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ParaTest\Tests; | ||
|
||
use PHPUnit\TextUI\Output\Printer; | ||
|
||
/** @internal */ | ||
final class MemoryPrinter implements Printer | ||
{ | ||
private string $memory = ''; | ||
private bool $flushed = false; | ||
|
||
public function print(string $buffer): void | ||
{ | ||
$this->memory .= $buffer; | ||
} | ||
|
||
public function tail(): string | ||
{ | ||
$memory = $this->memory; | ||
$this->memory = ''; | ||
|
||
return $memory; | ||
} | ||
|
||
public function flush(): void | ||
{ | ||
$this->flushed = true; | ||
} | ||
|
||
public function hasBeenFlushed(): bool | ||
{ | ||
return $this->flushed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ParaTest\Tests\Unit\WrapperRunner; | ||
|
||
use ParaTest\Tests\MemoryPrinter; | ||
use ParaTest\WrapperRunner\ProgressPrinterOutput; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @internal */ | ||
#[CoversClass(ProgressPrinterOutput::class)] | ||
final class ProgressPrinterOutputTest extends TestCase | ||
{ | ||
private MemoryPrinter $progress; | ||
private MemoryPrinter $output; | ||
private ProgressPrinterOutput $printer; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->progress = new MemoryPrinter(); | ||
$this->output = new MemoryPrinter(); | ||
|
||
$this->printer = new ProgressPrinterOutput( | ||
$this->progress, | ||
$this->output, | ||
); | ||
} | ||
|
||
public function testSkipProgressRelatedContents(): void | ||
{ | ||
$this->printer->print("\n"); | ||
$this->printer->print(' '); | ||
$this->printer->print(' '); | ||
$this->printer->print(' 65 / 75 ( 86%)'); | ||
$this->printer->print(' 2484 / 2484 (100%)'); | ||
|
||
self::assertSame('', $this->progress->tail()); | ||
self::assertSame('', $this->output->tail()); | ||
} | ||
|
||
public function testAProgressGoesIntoProgressTheRestInOutput(): void | ||
{ | ||
foreach (['E', 'F', 'I', 'N', 'D', 'R', 'W', 'S', '.'] as $progress) { | ||
$this->printer->print($progress); | ||
} | ||
|
||
$this->printer->print('var_dump'); | ||
|
||
self::assertSame('EFINDRWS.', $this->progress->tail()); | ||
self::assertSame('var_dump', $this->output->tail()); | ||
|
||
$this->printer->print('a '); | ||
self::assertSame('', $this->progress->tail()); | ||
self::assertSame('a ', $this->output->tail()); | ||
|
||
$this->printer->print(' z'); | ||
self::assertSame('', $this->progress->tail()); | ||
self::assertSame(' z', $this->output->tail()); | ||
|
||
$this->printer->print(' 65 / 75 ( 86%)'); | ||
self::assertSame('', $this->progress->tail()); | ||
self::assertSame(' 65 / 75 ( 86%)', $this->output->tail()); | ||
|
||
$this->printer->print(' 2484 / 2484 (100%) '); | ||
self::assertSame('', $this->progress->tail()); | ||
self::assertSame(' 2484 / 2484 (100%) ', $this->output->tail()); | ||
} | ||
|
||
public function testFlushBoth(): void | ||
{ | ||
self::assertFalse($this->progress->hasBeenFlushed()); | ||
self::assertFalse($this->output->hasBeenFlushed()); | ||
|
||
$this->printer->flush(); | ||
|
||
self::assertTrue($this->progress->hasBeenFlushed()); | ||
self::assertTrue($this->output->hasBeenFlushed()); | ||
} | ||
} |
Oops, something went wrong.