diff --git a/ondivi/__main__.py b/ondivi/__main__.py index b37c4ad..5b6cf6e 100644 --- a/ondivi/__main__.py +++ b/ondivi/__main__.py @@ -157,14 +157,14 @@ def main() -> None: ]), ) args = parser.parse_args() - violations = sys.stdin.read().strip().splitlines() - sys.stdout.write('\n'.join( - controller( - Repo('.').git.diff('--unified=0', args.baseline), - violations, - ), - )) + violations = controller( + Repo('.').git.diff('--unified=0', args.baseline), + sys.stdin.read().strip().splitlines(), + ) + sys.stdout.write('\n'.join(violations)) sys.stdout.write('\n') + if violations: + sys.exit(1) if __name__ == '__main__': diff --git a/tests/it/test_app.py b/tests/it/test_app.py index 689a8cd..1390aba 100644 --- a/tests/it/test_app.py +++ b/tests/it/test_app.py @@ -63,9 +63,10 @@ def test_gitpython_versions(version: str) -> None: ).stdout, stdout=subprocess.PIPE, check=False, - ).stdout.decode('utf-8').strip() + ) - assert got == 'file.py:4:80: E501 line too long (119 > 79 characters)' + assert got.stdout.decode('utf-8').strip() == 'file.py:4:80: E501 line too long (119 > 79 characters)' + assert got.returncode == 1 @pytest.mark.usefixtures('_test_repo') @@ -79,9 +80,10 @@ def test() -> None: ).stdout, stdout=subprocess.PIPE, check=False, - ).stdout.decode('utf-8').strip() + ) - assert got == 'file.py:4:80: E501 line too long (119 > 79 characters)' + assert got.stdout.decode('utf-8').strip() == 'file.py:4:80: E501 line too long (119 > 79 characters)' + assert got.returncode == 1 @pytest.mark.usefixtures('_test_repo') @@ -95,9 +97,10 @@ def test_baseline_default() -> None: ).stdout, stdout=subprocess.PIPE, check=False, - ).stdout.decode('utf-8').strip() + ) - assert got == 'file.py:4:80: E501 line too long (119 > 79 characters)' + assert got.stdout.decode('utf-8').strip() == 'file.py:4:80: E501 line too long (119 > 79 characters)' + assert got.returncode == 1 @pytest.mark.usefixtures('_test_repo') @@ -111,12 +114,13 @@ def test_ruff() -> None: ).stdout, stdout=subprocess.PIPE, check=False, - ).stdout.decode('utf-8').strip() + ) - assert got == '\n'.join([ + assert got.stdout.decode('utf-8').strip() == '\n'.join([ 'file.py:4:5: T201 `print` found', 'file.py:4:11: Q000 [*] Single quotes found but double quotes preferred', 'file.py:4:89: E501 Line too long (119 > 88)', 'Found 13 errors.', '[*] 4 fixable with the `--fix` option (4 hidden fixes can be enabled with the `--unsafe-fixes` option).', ]) + assert got.returncode == 1