mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Introduce new flag --fail-on-defect to pio check
This commit is contained in:
@ -56,6 +56,7 @@ from platformio.project.helpers import find_project_dir_above, get_project_dir
|
|||||||
@click.option("-s", "--silent", is_flag=True)
|
@click.option("-s", "--silent", is_flag=True)
|
||||||
@click.option("-v", "--verbose", is_flag=True)
|
@click.option("-v", "--verbose", is_flag=True)
|
||||||
@click.option("--json-output", is_flag=True)
|
@click.option("--json-output", is_flag=True)
|
||||||
|
@click.option("--fail-on-defect", is_flag=True)
|
||||||
def cli(
|
def cli(
|
||||||
environment,
|
environment,
|
||||||
project_dir,
|
project_dir,
|
||||||
@ -66,6 +67,7 @@ def cli(
|
|||||||
silent,
|
silent,
|
||||||
verbose,
|
verbose,
|
||||||
json_output,
|
json_output,
|
||||||
|
fail_on_defect
|
||||||
):
|
):
|
||||||
app.set_session_var("custom_project_conf", project_conf)
|
app.set_session_var("custom_project_conf", project_conf)
|
||||||
|
|
||||||
@ -134,9 +136,11 @@ def cli(
|
|||||||
|
|
||||||
result["defects"] = ct.get_defects()
|
result["defects"] = ct.get_defects()
|
||||||
result["duration"] = time() - result["duration"]
|
result["duration"] = time() - result["duration"]
|
||||||
result["succeeded"] = rc == 0 and not any(
|
|
||||||
d.severity == DefectItem.SEVERITY_HIGH for d in result["defects"]
|
result["succeeded"] = rc == 0
|
||||||
)
|
if fail_on_defect:
|
||||||
|
result["succeeded"] = rc == 0 and not any(
|
||||||
|
d.severity == DefectItem.SEVERITY_HIGH for d in result["defects"])
|
||||||
result["stats"] = collect_component_stats(result)
|
result["stats"] = collect_component_stats(result)
|
||||||
results.append(result)
|
results.append(result)
|
||||||
|
|
||||||
@ -144,7 +148,10 @@ def cli(
|
|||||||
click.echo("\n".join(repr(d) for d in result["defects"]))
|
click.echo("\n".join(repr(d) for d in result["defects"]))
|
||||||
|
|
||||||
if not json_output and not silent:
|
if not json_output and not silent:
|
||||||
if not result["defects"]:
|
if rc != 0:
|
||||||
|
click.echo("Error: %s failed to perform check! Please "
|
||||||
|
"examine tool output in verbose mode." % tool)
|
||||||
|
elif not result["defects"]:
|
||||||
click.echo("No defects found")
|
click.echo("No defects found")
|
||||||
print_processing_footer(result)
|
print_processing_footer(result)
|
||||||
|
|
||||||
|
@ -280,3 +280,29 @@ R21.4 text.
|
|||||||
assert result.exit_code != 0
|
assert result.exit_code != 0
|
||||||
assert "R21.3 Found MISRA defect" in result.output
|
assert "R21.3 Found MISRA defect" in result.output
|
||||||
assert not isfile(join(str(check_dir), "src", "main.cpp.dump"))
|
assert not isfile(join(str(check_dir), "src", "main.cpp.dump"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_fails_on_defects_only_with_flag(clirunner, tmpdir):
|
||||||
|
config = DEFAULT_CONFIG + "\ncheck_tool = cppcheck, clangtidy"
|
||||||
|
tmpdir.join("platformio.ini").write(config)
|
||||||
|
tmpdir.mkdir("src").join("main.cpp").write(TEST_CODE)
|
||||||
|
|
||||||
|
default_result = clirunner.invoke(
|
||||||
|
cmd_check, ["--project-dir", str(tmpdir)])
|
||||||
|
|
||||||
|
result_with_flag = clirunner.invoke(
|
||||||
|
cmd_check, ["--project-dir", str(tmpdir), "--fail-on-defect"])
|
||||||
|
|
||||||
|
assert default_result.exit_code == 0
|
||||||
|
assert result_with_flag.exit_code != 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_bad_tool_flag_fails_check(clirunner, tmpdir):
|
||||||
|
config = DEFAULT_CONFIG + "\ncheck_tool = cppcheck, clangtidy"
|
||||||
|
config += "\ncheck_flags = --unknown-flag"
|
||||||
|
tmpdir.join("platformio.ini").write(config)
|
||||||
|
tmpdir.mkdir("src").join("main.cpp").write(TEST_CODE)
|
||||||
|
|
||||||
|
result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
|
||||||
|
|
||||||
|
assert result.exit_code != 0
|
||||||
|
Reference in New Issue
Block a user