From 0e9c1bc0f797473982e3206f7d45ed8137585296 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 12 Feb 2023 01:06:02 +0000 Subject: [PATCH] fix: no `--dirty` tests found --- src/Contracts/Panicable.php | 23 +++++++ src/Exceptions/NoDirtyTestsFound.php | 38 ++++++++++++ src/Exceptions/NoTestsFound.php | 26 -------- src/Kernel.php | 4 +- src/Panic.php | 60 +++++++++++++++++++ .../GitDirtyTestCaseFilter.php | 5 +- 6 files changed, 126 insertions(+), 30 deletions(-) create mode 100644 src/Contracts/Panicable.php create mode 100644 src/Exceptions/NoDirtyTestsFound.php delete mode 100644 src/Exceptions/NoTestsFound.php create mode 100644 src/Panic.php 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;