forked from platformio/platformio-core
paths fix for check tool (#4874)
* paths fix for check tool * Minor changes - Handle an edge case on Windows when sources and the project are located on different drives - Cover edge cases with tests --------- Co-authored-by: Valerii Koval <valeros@users.noreply.github.com>
This commit is contained in:
@ -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
|
||||
|
@ -803,3 +803,49 @@ check_src_filters =
|
||||
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
|
||||
|
Reference in New Issue
Block a user