Skip to content

Commit

Permalink
Use separate exit code to indicate Psalm finding issues (#5087)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
weirdan committed Jan 24, 2021
1 parent 531cd36 commit 0489dd1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions docs/running_psalm/command_line_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/IssueBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ function (IssueData $d1, IssueData $d2) : int {
&& $project_analyzer->generated_report_options
&& isset($_SERVER['GITHUB_WORKFLOW']))
) {
exit(1);
exit(2);
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/EndToEnd/PsalmEndToEndTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testPsalm(): void
$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
Expand All @@ -136,7 +136,7 @@ public function testPsalmDiff(): void
$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);

Expand All @@ -145,7 +145,7 @@ public function testPsalmDiff(): void
$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');
}
Expand All @@ -157,7 +157,7 @@ public function testTainting(): void

$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
Expand All @@ -166,7 +166,7 @@ public function testTaintingWithoutInit(): void

$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
Expand All @@ -181,7 +181,7 @@ public function testTaintGraphDumping(): void
true
);

$this->assertSame(1, $result['CODE']);
$this->assertSame(2, $result['CODE']);
$this->assertFileEquals(
__DIR__ . '/../fixtures/expected_taint_graph.dot',
self::$tmpDir.'/taints.dot'
Expand All @@ -200,7 +200,7 @@ public function testLegacyConfigWithoutresolveFromConfigFile(): void

$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());
}

Expand Down

0 comments on commit 0489dd1

Please sign in to comment.