From 65f163c9d8b02c4e3024c91de02a59e796f90366 Mon Sep 17 00:00:00 2001 From: Tobias Reiher Date: Mon, 12 Feb 2024 09:11:40 +0100 Subject: [PATCH] Fix error reporting in CLI Ref. eng/recordflux/RecordFlux#1530 --- Makefile | 2 +- rflx/cli.py | 4 ++-- tests/README.md | 2 +- tests/{end-to-end => end_to_end}/__init__.py | 0 tests/{end-to-end => end_to_end}/cli_test.py | 19 +++++++++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) rename tests/{end-to-end => end_to_end}/__init__.py (100%) rename tests/{end-to-end => end_to_end}/cli_test.py (91%) diff --git a/Makefile b/Makefile index bf5c428d8..5edd3b451 100644 --- a/Makefile +++ b/Makefile @@ -155,7 +155,7 @@ test_language_coverage: timeout -k 60 7200 $(PYTEST) --cov=rflx/lang --cov-branch --cov-fail-under=73.8 --cov-report=term-missing:skip-covered tests/language test_end_to_end: - $(PYTEST) tests/end-to-end + $(PYTEST) tests/end_to_end test_property: $(PYTEST) tests/property diff --git a/rflx/cli.py b/rflx/cli.py index 594c4a609..5d1aca9d6 100644 --- a/rflx/cli.py +++ b/rflx/cli.py @@ -129,8 +129,8 @@ def __call__( # type: ignore [no-untyped-def] setattr(namespace, self.dest, values) -def run() -> None: - main(sys.argv) +def run() -> Union[int, str]: + return main(sys.argv) def main( # noqa: PLR0915 diff --git a/tests/README.md b/tests/README.md index 9ed4de6ed..853f6a2c9 100644 --- a/tests/README.md +++ b/tests/README.md @@ -29,7 +29,7 @@ The executability and provability tests require the definition of a session call Session functions can be defined by putting a custom implementation of the `Session` package inside the `src` directory. -### End-to-End Tests (`tests/end-to-end`) +### End-to-End Tests (`tests/end_to_end`) End-to-end tests verify the functionality of the entire application. These tests ensure that the application behaves as intended, particularly focusing on its primary use cases. diff --git a/tests/end-to-end/__init__.py b/tests/end_to_end/__init__.py similarity index 100% rename from tests/end-to-end/__init__.py rename to tests/end_to_end/__init__.py diff --git a/tests/end-to-end/cli_test.py b/tests/end_to_end/cli_test.py similarity index 91% rename from tests/end-to-end/cli_test.py rename to tests/end_to_end/cli_test.py index ca575d8a9..1c1ac2d35 100644 --- a/tests/end-to-end/cli_test.py +++ b/tests/end_to_end/cli_test.py @@ -27,6 +27,25 @@ def test_check() -> None: ) +def test_check_error() -> None: + p = subprocess.run( + ["rflx", "--no-caching", "check", SPEC_DIR / "invalid" / "incorrect_name.rflx"], + capture_output=True, + ) + assert p.returncode == 1 + assert p.stdout.decode("utf-8") == "" + assert p.stderr.decode("utf-8") == textwrap.dedent( + """\ + Parsing tests/data/specs/invalid/incorrect_name.rflx + Processing Test + Verifying __BUILTINS__::Boolean + Verifying __INTERNAL__::Opaque + tests/data/specs/invalid/incorrect_name.rflx:1:9: parser: error: file name does not match\ + unit name "Test", should be "test.rflx" + """, + ) + + def test_check_no_verification() -> None: p = subprocess.run( [