diff --git a/src/Contracts/Panicable.php b/src/Contracts/Panicable.php new file mode 100644 index 00000000..f56b4b78 --- /dev/null +++ b/src/Contracts/Panicable.php @@ -0,0 +1,23 @@ +writeln([ + '', + ' INFO No "dirty" tests found.', + '', + ]); + } + + /** + * The exit code to be used. + */ + public function exitCode(): int + { + return 0; + } +} diff --git a/src/Exceptions/NoTestsFound.php b/src/Exceptions/NoTestsFound.php deleted file mode 100644 index 951b9ec7..00000000 --- a/src/Exceptions/NoTestsFound.php +++ /dev/null @@ -1,26 +0,0 @@ -application->run($args); - } catch (NoTestsFound) { + } catch (NoDirtyTestsFound) { $this->output->writeln([ '', ' INFO No tests found.', diff --git a/src/Panic.php b/src/Panic.php new file mode 100644 index 00000000..a14bf428 --- /dev/null +++ b/src/Panic.php @@ -0,0 +1,60 @@ +handle(); + + exit(1); + } + + /** + * Handles the panic. + */ + private function handle(): void + { + /** @var OutputInterface $output */ + $output = Container::getInstance()->get(OutputInterface::class); + + if ($this->throwable instanceof Contracts\Panicable) { + $this->throwable->render($output); + + exit($this->throwable->exitCode()); + } + + $writer = new Writer(null, $output); + + $inspector = new Inspector($this->throwable); + + $output->writeln(''); + $writer->write($inspector); + $output->writeln(''); + + exit(1); + } +} diff --git a/src/TestCaseFilters/GitDirtyTestCaseFilter.php b/src/TestCaseFilters/GitDirtyTestCaseFilter.php index 3083c3f1..c38e49c7 100644 --- a/src/TestCaseFilters/GitDirtyTestCaseFilter.php +++ b/src/TestCaseFilters/GitDirtyTestCaseFilter.php @@ -6,7 +6,8 @@ namespace Pest\TestCaseFilters; use Pest\Contracts\TestCaseFilter; use Pest\Exceptions\MissingDependency; -use Pest\Exceptions\NoTestsFound; +use Pest\Exceptions\NoDirtyTestsFound; +use Pest\Panic; use Pest\TestSuite; use Symfony\Component\Process\Process; @@ -66,7 +67,7 @@ final class GitDirtyTestCaseFilter implements TestCaseFilter $dirtyFiles = array_values($dirtyFiles); if ($dirtyFiles === []) { - throw new NoTestsFound(); + Panic::with(new NoDirtyTestsFound()); } $this->changedFiles = $dirtyFiles;