From 0aa4f2044c2913e7d7ca5707775c72117b3e2cae Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sun, 24 Jan 2021 20:30:35 +0200 Subject: [PATCH] Use separate exit code to indicate Psalm finding issues (#5087) * Use separate exit code to indicate Psalm finding issues This will allow to distinguish successful run that found some issues from crashes. * Fix e2e test expectations * Documented exit statuses --- docs/running_psalm/command_line_usage.md | 7 +++++++ src/Psalm/IssueBuffer.php | 2 +- tests/EndToEnd/PsalmEndToEndTest.php | 14 +++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/running_psalm/command_line_usage.md b/docs/running_psalm/command_line_usage.md index e2f97a4e6..5aeb50837 100644 --- a/docs/running_psalm/command_line_usage.md +++ b/docs/running_psalm/command_line_usage.md @@ -16,6 +16,13 @@ If you want to run on specific files, use Run with `--help` to see a list of options that Psalm supports. +## Exit status + +Psalm exits with status `0` when it successfully completed and found no issues, +`1` when there was a problem running Psalm and `2` when it completed +successfully but found some issues. Any exit status apart from those indicate +some internal problem. + ## Shepherd Psalm currently offers some GitHub integration with public projects. diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index 513fade48..35df503ed 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -686,7 +686,7 @@ class IssueBuffer && $project_analyzer->generated_report_options && isset($_SERVER['GITHUB_WORKFLOW'])) ) { - exit(1); + exit(2); } } diff --git a/tests/EndToEnd/PsalmEndToEndTest.php b/tests/EndToEnd/PsalmEndToEndTest.php index 76d8cf985..380bf0db1 100644 --- a/tests/EndToEnd/PsalmEndToEndTest.php +++ b/tests/EndToEnd/PsalmEndToEndTest.php @@ -118,7 +118,7 @@ class PsalmEndToEndTest extends TestCase $this->assertStringContainsString('InvalidReturnType', $result['STDOUT']); $this->assertStringContainsString('InvalidReturnStatement', $result['STDOUT']); $this->assertStringContainsString('2 errors', $result['STDOUT']); - $this->assertSame(1, $result['CODE']); + $this->assertSame(2, $result['CODE']); } public function testPsalmDiff(): void @@ -136,7 +136,7 @@ class PsalmEndToEndTest extends TestCase $this->assertStringContainsString('2 errors', $result['STDOUT']); $this->assertStringContainsString('E', $result['STDERR']); - $this->assertSame(1, $result['CODE']); + $this->assertSame(2, $result['CODE']); $result = $this->runPsalm(['--diff', '-m'], self::$tmpDir, true); @@ -145,7 +145,7 @@ class PsalmEndToEndTest extends TestCase $this->assertStringContainsString('2 errors', $result['STDOUT']); $this->assertStringNotContainsString('E', $result['STDERR']); - $this->assertSame(1, $result['CODE']); + $this->assertSame(2, $result['CODE']); @unlink(self::$tmpDir . '/composer.lock'); } @@ -157,7 +157,7 @@ class PsalmEndToEndTest extends TestCase $this->assertStringContainsString('TaintedHtml', $result['STDOUT']); $this->assertStringContainsString('1 errors', $result['STDOUT']); - $this->assertSame(1, $result['CODE']); + $this->assertSame(2, $result['CODE']); } public function testTaintingWithoutInit(): void @@ -166,7 +166,7 @@ class PsalmEndToEndTest extends TestCase $this->assertStringContainsString('TaintedHtml', $result['STDOUT']); $this->assertStringContainsString('1 errors', $result['STDOUT']); - $this->assertSame(1, $result['CODE']); + $this->assertSame(2, $result['CODE']); } public function testTaintGraphDumping(): void @@ -181,7 +181,7 @@ class PsalmEndToEndTest extends TestCase true ); - $this->assertSame(1, $result['CODE']); + $this->assertSame(2, $result['CODE']); $this->assertFileEquals( __DIR__ . '/../fixtures/expected_taint_graph.dot', self::$tmpDir.'/taints.dot' @@ -200,7 +200,7 @@ class PsalmEndToEndTest extends TestCase $process = new Process(['php', $this->psalm, '--config=src/psalm.xml'], self::$tmpDir); $process->run(); - $this->assertSame(1, $process->getExitCode()); + $this->assertSame(2, $process->getExitCode()); $this->assertStringContainsString('InvalidReturnType', $process->getOutput()); }