Skip to content

Commit

Permalink
Add --stop-on-error option to runner (paratestphp#765)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan Wentz <[email protected]>
  • Loading branch information
temp and Stephan Wentz authored May 25, 2023
1 parent 5169120 commit c2243b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/Runners/PHPUnit/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ final class Options
*/
private $stopOnFailure;

/**
* Prevents starting new tests after a test has errored.
*
* @var bool
*/
private $stopOnError;

/**
* A collection of post-processed option values. This is the collection
* containing ParaTest specific options.
Expand Down Expand Up @@ -261,6 +268,7 @@ private function __construct(
int $processes,
string $runner,
bool $stopOnFailure,
bool $stopOnError,
array $testsuite,
string $tmpDir,
bool $verbose,
Expand Down Expand Up @@ -302,6 +310,7 @@ private function __construct(
$this->processes = $processes;
$this->runner = $runner;
$this->stopOnFailure = $stopOnFailure;
$this->stopOnError = $stopOnError;
$this->testsuite = $testsuite;
$this->tmpDir = $tmpDir;
$this->verbose = $verbose;
Expand Down Expand Up @@ -344,6 +353,7 @@ public static function fromConsoleInput(InputInterface $input, string $cwd, bool
assert($options['random-order-seed'] === null || is_string($options['random-order-seed']));
assert(is_string($options['runner']));
assert(is_bool($options['stop-on-failure']));
assert(is_bool($options['stop-on-error']));
assert(is_string($options['tmp-dir']));
assert($options['whitelist'] === null || is_string($options['whitelist']));
assert($options['repeat'] === null || is_string($options['repeat']));
Expand Down Expand Up @@ -456,6 +466,10 @@ public static function fromConsoleInput(InputInterface $input, string $cwd, bool
$filtered['stop-on-failure'] = null;
}

if ($options['stop-on-error']) {
$filtered['stop-on-error'] = null;
}

$configuration = null;
$configurationFile = self::guessConfigurationFile($options['configuration'], $cwd);
if ($configurationFile !== null) {
Expand Down Expand Up @@ -557,6 +571,7 @@ public static function fromConsoleInput(InputInterface $input, string $cwd, bool
$options['processes'],
$options['runner'],
$options['stop-on-failure'],
$options['stop-on-error'],
$testsuite,
$options['tmp-dir'],
$options['verbose'],
Expand Down Expand Up @@ -789,6 +804,12 @@ public static function setInputDefinition(InputDefinition $inputDefinition): voi
'Runner or WrapperRunner.',
'Runner',
),
new InputOption(
'stop-on-error',
null,
InputOption::VALUE_NONE,
'Don\'t start any more processes after an error.',
),
new InputOption(
'stop-on-failure',
null,
Expand Down Expand Up @@ -961,6 +982,11 @@ public function stopOnFailure(): bool
return $this->stopOnFailure;
}

public function stopOnError(): bool
{
return $this->stopOnError;
}

/** @return array<string, string|null> */
public function filtered(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Runners/PHPUnit/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function testIsStillRunning(RunnerWorker $worker): bool
}

$this->exitcode = max($this->exitcode, (int) $worker->stop());
if ($this->options->stopOnFailure() && $this->exitcode > 0) {
if (($this->options->stopOnFailure() || $this->options->stopOnError()) && $this->exitcode > 0) {
$this->pending = [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Runners/PHPUnit/WrapperRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function assignAllPendingTests(): void
$worker = $this->startWorker($token);
}

if ($this->exitcode > 0 && $this->options->stopOnFailure()) {
if ($this->exitcode > 0 && ($this->options->stopOnFailure() || $this->options->stopOnError())) {
$this->pending = [];
} elseif (($pending = array_shift($this->pending)) !== null) {
$worker->assign($pending, $phpunit, $phpunitOptions, $this->options);
Expand Down
4 changes: 4 additions & 0 deletions test/Unit/Runners/PHPUnit/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public function testDefaultOptions(): void
static::assertSame(PROCESSES_FOR_TESTS, $options->processes());
static::assertSame('Runner', $options->runner());
static::assertFalse($options->stopOnFailure());
static::assertFalse($options->stopOnError());
static::assertEmpty($options->testsuite());
static::assertSame($this->tmpDir, $options->tmpDir());
static::assertFalse($options->verbose());
Expand Down Expand Up @@ -304,6 +305,7 @@ public function testProvidedOptions(): void
'--processes' => '999',
'--runner' => 'MYRUNNER',
'--stop-on-failure' => true,
'--stop-on-error' => true,
'--testsuite' => 'TESTSUITE',
'--tmp-dir' => ($tmpDir = uniqid($this->tmpDir . DS . 't')),
'--verbose' => true,
Expand Down Expand Up @@ -346,6 +348,7 @@ public function testProvidedOptions(): void
static::assertSame(999, $options->processes());
static::assertSame('MYRUNNER', $options->runner());
static::assertTrue($options->stopOnFailure());
static::assertTrue($options->stopOnError());
static::assertSame(['TESTSUITE'], $options->testsuite());
static::assertSame($tmpDir, $options->tmpDir());
static::assertTrue($options->verbose());
Expand All @@ -364,6 +367,7 @@ public function testProvidedOptions(): void
'order-by' => Options::ORDER_RANDOM,
'random-order-seed' => (string) $expected_random_seed,
'repeat' => '2',
'stop-on-error' => null,
'stop-on-failure' => null,
'whitelist' => 'WHITELIST',
], $options->filtered());
Expand Down

0 comments on commit c2243b2

Please sign in to comment.