Skip to content

Commit

Permalink
Properly handle the check_src_filters option per environment
Browse files Browse the repository at this point in the history
Resolves #4788
  • Loading branch information
valeros committed Nov 17, 2023
1 parent e1f34c7 commit 961ab6b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/platformio/platformio-core/issues/4783>`_)
* Resolved an issue where the ``COMPILATIONDB_INCLUDE_TOOLCHAIN`` setting was not correctly applying to private libraries (`issue #4762 <https://github.com/platformio/platformio-core/issues/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 <https://github.com/platformio/platformio-core/issues/4777>`_)
* Resolved an issue with incorrect handling of the ``check_src_filters`` option when used in multiple environments (`issue #4788 <https://github.com/platformio/platformio-core/issues/4788>`_)


6.1.11 (2023-08-31)
~~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions platformio/check/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tests/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
+<src/*>
[env:check_sources]
platform = native
[env:check_tests]
platform = native
check_src_filters =
+<test/*>
"""
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

0 comments on commit 961ab6b

Please sign in to comment.