From a760470e4868cc9ca0c40ef027382409cd2a6737 Mon Sep 17 00:00:00 2001 From: luke Date: Mon, 9 Aug 2021 18:57:20 +0100 Subject: [PATCH] Adds Pest output to parallel. --- src/Console/Paratest/PestRunnerWorker.php | 38 +++++++++++++++++++++-- src/Console/Paratest/Runner.php | 14 ++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/Console/Paratest/PestRunnerWorker.php b/src/Console/Paratest/PestRunnerWorker.php index b1a4adc9..fbddf2b1 100644 --- a/src/Console/Paratest/PestRunnerWorker.php +++ b/src/Console/Paratest/PestRunnerWorker.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Pest\Console\Paratest; +use Symfony\Component\Console\Output\OutputInterface; use function array_merge; use const DIRECTORY_SEPARATOR; use ParaTest\Runners\PHPUnit\ExecutableTest; @@ -22,11 +23,23 @@ final class PestRunnerWorker { /** @var ExecutableTest */ private $executableTest; + /** @var Process */ private $process; - public function __construct(ExecutableTest $executableTest, Options $options, int $token) + /** + * @var OutputInterface + */ + private $output; + + /** + * @var array + */ + public static $additionalOutput = []; + + public function __construct(OutputInterface $output, ExecutableTest $executableTest, Options $options, int $token) { + $this->output = $output; $this->executableTest = $executableTest; $phpFinder = new PhpExecutableFinder(); @@ -81,7 +94,28 @@ final class PestRunnerWorker */ public function stop(): ?int { - return $this->process->stop(); + $exitCode = $this->process->stop(); + $this->handleOutput($this->process->getOutput()); + return $exitCode; + } + + private function handleOutput(string $output) + { + $matches = []; + preg_match_all("/^\\n/m", $output, $matches, PREG_OFFSET_CAPTURE); + + $overview = substr($output, 0, $matches[0][1][1]); + $this->output->write($overview); + + if (count($matches[0]) > 3) { + $summarySectionIndex = count($matches[0]) - 2; + + static::$additionalOutput[] = substr( + $output, + $matches[0][1][1], + $matches[0][$summarySectionIndex][1] - $matches[0][1][1], + ); + } } /** diff --git a/src/Console/Paratest/Runner.php b/src/Console/Paratest/Runner.php index 678eb37c..749fb3cc 100644 --- a/src/Console/Paratest/Runner.php +++ b/src/Console/Paratest/Runner.php @@ -84,7 +84,7 @@ final class Runner implements RunnerInterface final public function run(): void { $this->load(new SuiteLoader($this->options, $this->output)); - $this->printer->start(); +// $this->printer->start(); $this->doRun(); @@ -109,7 +109,7 @@ final class Runner implements RunnerInterface $this->sortPending(); foreach ($this->pending as $pending) { - $this->printer->addTest($pending); +// $this->printer->addTest($pending); } } @@ -135,7 +135,11 @@ final class Runner implements RunnerInterface */ private function complete(): void { - $this->printer->printResults(); + foreach(PestRunnerWorker::$additionalOutput as $output) { + $this->output->write($output); + } + PestRunnerWorker::$additionalOutput = []; +// $this->printer->printResults(); $this->log(); $this->logCoverage(); $readers = $this->interpreter->getReaders(); @@ -273,7 +277,7 @@ final class Runner implements RunnerInterface ) { $executableTest = array_shift($this->pending); - $this->running[$token] = new PestRunnerWorker($executableTest, $this->options, $token); + $this->running[$token] = new PestRunnerWorker($this->output, $executableTest, $this->options, $token); $this->running[$token]->run(); if ($this->options->verbosity() < Options::VERBOSITY_VERY_VERBOSE) { @@ -314,7 +318,7 @@ final class Runner implements RunnerInterface $executableTest = $worker->getExecutableTest(); try { - $this->printer->printFeedback($executableTest); +// $this->printer->printFeedback($executableTest); } catch (EmptyLogFileException $emptyLogFileException) { throw $worker->getWorkerCrashedException($emptyLogFileException); }