diff --git a/gersemi/runner.py b/gersemi/runner.py index 8e73475..9240648 100644 --- a/gersemi/runner.py +++ b/gersemi/runner.py @@ -131,7 +131,7 @@ def run_task( return task(formatted_file) -def consume_task_result(task_result: TaskResult, quiet: bool) -> Tuple[Path, int]: +def consume_task_result(task_result: TaskResult, quiet: bool) -> Tuple[Path, int, bool]: if task_result.to_stdout != "": print_to_stdout(task_result.to_stdout) @@ -142,7 +142,7 @@ def consume_task_result(task_result: TaskResult, quiet: bool) -> Tuple[Path, int if task_result.to_stderr != "": print_to_stderr(task_result.to_stderr) - return task_result.path, task_result.return_code + return task_result.path, task_result.return_code, (len(task_result.warnings) > 0) def create_pool(is_stdin_in_sources, num_workers): @@ -195,7 +195,7 @@ def handle_already_formatted_files( consume_task_result(result, quiet) for result in map(execute, already_formatted_files) ] - return compute_error_code(code for _, code in results) + return compute_error_code(code for _, code, _ in results) def handle_files_to_format( @@ -227,9 +227,13 @@ def handle_files_to_format( mode, cache, configuration_summary, - (path for path, code in results if code == SUCCESS and path != Path("-")), + ( + path + for path, code, has_warnings in results + if code == SUCCESS and path != Path("-") and (not has_warnings) + ), ) - return compute_error_code(code for _, code in results) + return compute_error_code(code for _, code, _ in results) def run(mode: Mode, configuration: Configuration, sources: Iterable[Path]): diff --git a/gersemi/warnings.py b/gersemi/warnings.py index 2d126e8..d243abe 100644 --- a/gersemi/warnings.py +++ b/gersemi/warnings.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Iterable, Tuple, Union +from typing import Sequence, Tuple, Union Position = Tuple[int, int] @@ -8,7 +8,7 @@ @dataclass class UnknownCommandWarning: command_name: str - positions: Iterable[Position] + positions: Sequence[Position] def get_message(self, filepath: str) -> str: return "\n".join( @@ -26,4 +26,4 @@ def get_message(self, filepath: str) -> str: FormatterWarning = Union[UnknownCommandWarning, WrongFormattingWarning] -FormatterWarnings = Iterable[FormatterWarning] +FormatterWarnings = Sequence[FormatterWarning] diff --git a/tests/test_executable.py b/tests/test_executable.py index 82ee8a1..b6f2747 100644 --- a/tests/test_executable.py +++ b/tests/test_executable.py @@ -901,20 +901,25 @@ def check_warnings(result, stderr): @pytest.mark.parametrize( - ["args"], + ["args", "check_cache"], [ - ((),), - (("--check",),), - (("--in-place",),), - (("--diff",),), + ((), False), + (("--check",), True), + (("--in-place",), True), + (("--diff",), False), ], ) -def test_warn_about_unknown_commands(tmpdir, args): - with temporary_dir_copy(TESTS / "warn_about_unknown_commands") as copy: - cmakelists = Path(copy) / "CMakeLists.txt" - custom_command_definition = Path(copy) / "watch_movies.cmake" +def test_warn_about_unknown_commands(tmpdir, args, check_cache): + original = TESTS / "warn_about_unknown_commands" - with_definition = gersemi( + with cache_tests(original) as (target, gersemi_, inspector): + if check_cache: + inspector.assert_that_has_no_tables() + + cmakelists = Path(target) / "CMakeLists.txt" + custom_command_definition = Path(target) / "watch_movies.cmake" + + with_definition = gersemi_( *args, cmakelists, "--definitions", @@ -927,7 +932,17 @@ def test_warn_about_unknown_commands(tmpdir, args): ) assert with_definition.stderr == "", with_definition.stderr - without_definition = gersemi(*args, cmakelists, cwd=tmpdir) + if check_cache: + inspector.assert_that_has_initialized_tables() + assert len(inspector.get_files()) > 0 + assert len(inspector.get_formatted()) > 0 + + with cache_tests(original) as (target, gersemi_, inspector): + if check_cache: + inspector.assert_that_has_no_tables() + + cmakelists = Path(target) / "CMakeLists.txt" + without_definition = gersemi_(*args, cmakelists, cwd=tmpdir) assert without_definition.returncode == 0, ( without_definition.returncode, without_definition.stderr, @@ -945,6 +960,11 @@ def test_warn_about_unknown_commands(tmpdir, args): """ ), without_definition.stderr + if check_cache: + inspector.assert_that_has_initialized_tables() + assert len(inspector.get_files()) == 0 + assert len(inspector.get_formatted()) == 0 + @pytest.mark.parametrize( ["args"],