Skip to content

Commit

Permalink
Fix progress mangle (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Feb 6, 2023
1 parent 87fc18b commit 5346ac0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ all: csfix test

vendor: composer.json
composer update
composer bump
#composer bump
touch vendor

.PHONY: csfix
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"phpunit/php-code-coverage": "^10.0",
"phpunit/php-file-iterator": "^4.0",
"phpunit/php-timer": "^6.0",
"phpunit/phpunit": "^10.0.3",
"phpunit/phpunit": "^10.0.4",
"sebastian/environment": "^6.0",
"symfony/console": "^6.2.5",
"symfony/process": "^6.2.5"
Expand Down
9 changes: 7 additions & 2 deletions src/WrapperRunner/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ public function printFeedback(SplFileInfo $progressFile, array $teamcityFiles):
}

$feedbackItems = $this->tail($progressFile);
$feedbackItems = preg_replace('/ +\\d+ \\/ \\d+ \\(\\d+%\\)\\s*/', '', $feedbackItems);
if ($feedbackItems === '') {
return;
}

$feedbackItems = preg_replace('/ +\\d+ \\/ \\d+ \\( ?\\d+%\\)\\s*/', '', $feedbackItems);

$actualTestCount = strlen($feedbackItems);
for ($index = 0; $index < $actualTestCount; ++$index) {
Expand Down Expand Up @@ -230,14 +234,15 @@ private function printFeedbackItem(string $item): void
}

$this->output->write($this->getProgress() . "\n");
$this->column = 0;
}

private function printFeedbackItemColor(string $item): void
{
$buffer = match ($item) {
'E' => $this->colorizeTextBox('fg-red, bold', $item),
'F' => $this->colorizeTextBox('bg-red, fg-white', $item),
'W', 'I', 'R' => $this->colorizeTextBox('fg-yellow, bold', $item),
'I', 'N', 'D', 'R', 'W' => $this->colorizeTextBox('fg-yellow, bold', $item),
'S' => $this->colorizeTextBox('fg-cyan, bold', $item),
default => $item,
};
Expand Down
21 changes: 21 additions & 0 deletions test/Unit/WrapperRunner/ResultPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,27 @@ public function testTestdoxOutputWithoutProgress(): void
static::assertSame($testdoxSourceContent, $this->output->fetch());
}

public function testPrintFeedbackFromMultilineSource(): void
{
$source = <<<'EOF'
............................................................... 63 / 300 ( 21%)
............................................................... 126 / 300 ( 42%)
............................................................... 189 / 300 ( 63%)
............................................................... 252 / 300 ( 84%)
................................................ 300 / 300 (100%)

EOF;

$this->printer->setTestCount(300);
$this->printer->start();
$this->output->fetch();
$feedbackFile = $this->tmpDir . DS . 'feedback1';
file_put_contents($feedbackFile, $source);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), []);
$contents = $this->output->fetch();
static::assertSame($source, $contents);
}

private function getStartOutput(): string
{
$this->printer->start();
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ public function testStopOnFailureEndsRunBeforeWholeTestSuite(): void
$this->bareOptions['--processes'] = '1';
$this->bareOptions['path'] = $this->fixture('common_results');
$output = $this->runRunner()->output;
self::assertStringContainsString('Tests: 59, Assertions: 185,', $output);
self::assertStringContainsString('Tests: 60, Assertions: 187,', $output);

$this->bareOptions['--stop-on-failure'] = true;
$output = $this->runRunner()->output;
self::assertStringContainsString('Tests: 53, Assertions: 182,', $output);
self::assertStringContainsString('Tests: 54, Assertions: 184,', $output);
}

public function testRaiseExceptionWhenATestCallsExitWithoutCoverageSingleProcess(): void
Expand Down

0 comments on commit 5346ac0

Please sign in to comment.