diff --git a/HISTORY.rst b/HISTORY.rst index 8f2ee0cafe..579c1e7074 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -23,6 +23,8 @@ test-driven methodologies, and modern toolchains for unrivaled success. * Drastically enhanced the speed of project building when operating in verbose mode (`issue #4783 `_) * Resolved an issue where the ``COMPILATIONDB_INCLUDE_TOOLCHAIN`` setting was not correctly applying to private libraries (`issue #4762 `_) * Resolved an issue where ``get_systype()`` inaccurately returned the architecture when executed within a Docker container on a 64-bit kernel with a 32-bit userspace (`issue #4777 `_) +* Resolved an issue with incorrect handling of the ``check_src_filters`` option when used in multiple environments (`issue #4788 `_) + 6.1.11 (2023-08-31) ~~~~~~~~~~~~~~~~~~~ diff --git a/platformio/check/cli.py b/platformio/check/cli.py index d99da3137b..1deced8766 100644 --- a/platformio/check/cli.py +++ b/platformio/check/cli.py @@ -108,7 +108,7 @@ def cli( "+<%s>" % os.path.basename(config.get("platformio", "include_dir")), ] - src_filters = ( + env_src_filters = ( src_filters or pattern or env_options.get( @@ -120,7 +120,7 @@ def cli( tool_options = dict( verbose=verbose, silent=silent, - src_filters=src_filters, + src_filters=env_src_filters, flags=flags or env_options.get("check_flags"), severity=[DefectItem.SEVERITY_LABELS[DefectItem.SEVERITY_HIGH]] if silent diff --git a/tests/commands/test_check.py b/tests/commands/test_check.py index d50a79a463..a9a99d6509 100644 --- a/tests/commands/test_check.py +++ b/tests/commands/test_check.py @@ -767,3 +767,39 @@ def test_check_src_filter_from_config_legacy( assert errors + warnings + style == EXPECTED_DEFECTS * 2 assert "main.cpp" not in result.output + + +def test_check_src_filter_multiple_envs(clirunner, validate_cliresult, tmpdir_factory): + tmpdir = tmpdir_factory.mktemp("project") + + config = """ +[env] +check_tool = cppcheck +check_src_filters = + + + +[env:check_sources] +platform = native + +[env:check_tests] +platform = native +check_src_filters = + + + """ + tmpdir.join("platformio.ini").write(config) + + src_dir = tmpdir.mkdir("src") + src_dir.join("main.cpp").write(TEST_CODE) + src_dir.mkdir("spi").join("spi.cpp").write(TEST_CODE) + tmpdir.mkdir("test").join("test.cpp").write(TEST_CODE) + + result = clirunner.invoke( + cmd_check, ["--project-dir", str(tmpdir), "-e", "check_tests"] + ) + validate_cliresult(result) + + errors, warnings, style = count_defects(result.output) + + assert errors + warnings + style == EXPECTED_DEFECTS + assert "test.cpp" in result.output + assert "main.cpp" not in result.output