Skip to content

Commit

Permalink
Infection must return appropriate exit status when failing (#1299)
Browse files Browse the repository at this point in the history
* Infection must return appropriate exit status when failing

* Update src/Command/BaseCommand.php
  • Loading branch information
sanmai committed Aug 19, 2020
1 parent 9488dfd commit 31e4af4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/Command/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ protected function initialize(InputInterface $input, OutputInterface $output): v

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->executeCommand($this->getIO());

return 0;
return $this->executeCommand($this->getIO()) ? 0 : 1;
}

abstract protected function executeCommand(IO $io): void;
abstract protected function executeCommand(IO $io): bool;

final protected function getIO(): IO
{
Expand Down
4 changes: 3 additions & 1 deletion src/Command/ConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function configure(): void
);
}

protected function executeCommand(IO $io): void
protected function executeCommand(IO $io): bool
{
if (!$io->isInteractive()) {
$io->writeln(self::NONINTERACTIVE_MODE_ERROR);
Expand Down Expand Up @@ -156,6 +156,8 @@ protected function executeCommand(IO $io): void
SchemaConfigurationLoader::DEFAULT_DIST_CONFIG_FILE
));
$io->newLine();

return true;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected function configure(): void
;
}

protected function executeCommand(IO $io): void
protected function executeCommand(IO $io): bool
{
$logger = new ConsoleLogger($io);
$container = $this->createContainer($io, $logger);
Expand All @@ -238,10 +238,14 @@ protected function executeCommand(IO $io): void

try {
$engine->execute();

return true;
} catch (InitialTestsFailed | MinMsiCheckFailed $exception) {
// TODO: we can move that in a dedicated logger later and handle those cases in the
// Engine instead
$io->error($exception->getMessage());

return false;
}
}

Expand Down

0 comments on commit 31e4af4

Please sign in to comment.