Skip to content

Commit 71679a0

Browse files
SCANPY-171 return properly exit code
1 parent ff0e44d commit 71679a0

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ from = 'src'
5454
include = 'pysonar_scanner'
5555

5656
[tool.poetry.scripts]
57-
pysonar = 'pysonar_scanner.__main__:scan'
57+
pysonar = 'pysonar_scanner.__main__:main'
5858

5959
[[tool.poetry.source]]
6060
name = 'jfrog-server'

src/pysonar_scanner/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
from pysonar_scanner.scannerengine import ScannerEngine, ScannerEngineProvisioner
4242

4343

44+
def main():
45+
exit(scan())
46+
47+
4448
def scan():
4549
try:
4650
return do_scan()

tests/unit/test_main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from pyfakefs import fake_filesystem_unittest as pyfakefs
2424

25-
from pysonar_scanner.__main__ import scan, check_version, create_jre
25+
from pysonar_scanner.__main__ import scan, main, check_version, create_jre
2626
from pysonar_scanner.api import SQVersion, SonarQubeApi
2727
from pysonar_scanner.cache import Cache
2828
from pysonar_scanner.configuration.configuration_loader import ConfigurationLoader
@@ -91,6 +91,12 @@ def test_scan_with_exception(self, load_mock):
9191
exitcode = scan()
9292
self.assertEqual(1, exitcode)
9393

94+
def test_main_with_exitcode_not_zero(self):
95+
with patch("pysonar_scanner.__main__.scan", return_value=42):
96+
with self.assertRaises(SystemExit) as main_exit:
97+
main()
98+
self.assertEqual(main_exit.exception.code, 42)
99+
94100
def test_version_check_outdated_sonarqube(self):
95101
sq_cloud_api = sq_api_utils.get_sq_server()
96102
sq_cloud_api.get_analysis_version = Mock(return_value=SQVersion.from_str("9.9.9"))

0 commit comments

Comments
 (0)