Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paths fix for check tool #4874

Merged
merged 2 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions platformio/check/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,21 @@ def cli(
"%s: %s" % (k, ", ".join(v) if isinstance(v, list) else v)
)

default_src_filters = [
"+<%s>" % os.path.basename(config.get("platformio", "src_dir")),
"+<%s>" % os.path.basename(config.get("platformio", "include_dir")),
]
default_src_filters = []
for d in (
config.get("platformio", "src_dir"),
config.get("platformio", "include_dir"),
):
try:
default_src_filters.append("+<%s>" % os.path.relpath(d))
except ValueError as exc:
# On Windows if sources are located on a different logical drive
if not json_output and not silent:
click.echo(
"Error: Project cannot be analyzed! The project folder `%s`"
" is located on a different logical drive\n" % d
)
raise exception.ReturnErrorCode(1) from exc

env_src_filters = (
src_filters
Expand Down
46 changes: 46 additions & 0 deletions tests/commands/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,49 @@ def test_check_src_filter_multiple_envs(clirunner, validate_cliresult, tmpdir_fa
assert errors + warnings + style == EXPECTED_DEFECTS
assert "test.cpp" in result.output
assert "main.cpp" not in result.output


def test_check_sources_in_project_root(clirunner, validate_cliresult, tmpdir_factory):
tmpdir = tmpdir_factory.mktemp("project")

config = (
"""
[platformio]
src_dir = ./
"""
+ DEFAULT_CONFIG
)
tmpdir.join("platformio.ini").write(config)
tmpdir.join("main.cpp").write(TEST_CODE)
tmpdir.mkdir("spi").join("uart.cpp").write(TEST_CODE)

result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
validate_cliresult(result)

errors, warnings, style = count_defects(result.output)

assert result.exit_code == 0
assert errors + warnings + style == EXPECTED_DEFECTS * 2


def test_check_sources_in_external_dir(clirunner, validate_cliresult, tmpdir_factory):
tmpdir = tmpdir_factory.mktemp("project")
external_src_dir = tmpdir_factory.mktemp("external_src_dir")

config = (
f"""
[platformio]
src_dir = {external_src_dir}
"""
+ DEFAULT_CONFIG
)
tmpdir.join("platformio.ini").write(config)
external_src_dir.join("main.cpp").write(TEST_CODE)

result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
validate_cliresult(result)

errors, warnings, style = count_defects(result.output)

assert result.exit_code == 0
assert errors + warnings + style == EXPECTED_DEFECTS
Loading