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

fix(clang_format_analyzer): create parent folders for target file #838

Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 26 additions & 0 deletions tests/test_code_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,29 @@ def test_code_report_extended_arg_search_embedded(tmp_path: pathlib.Path, stdout

env.run()
stdout_checker.assert_absent_calls_with_param("${CODE_REPORT_FILE}")


@pytest.mark.parametrize('analyzer, extra_args, tested_content', [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you don't need to parametrize the test, because you only have one set of parameter values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, removed

['clang_format', [], source_code_c],
], ids=[
"clang_format",
])
def test_clang_format_analyzer_with_subfolder(runner_with_analyzers: UniversumRunner, analyzer,
extra_args, tested_content):

root = runner_with_analyzers.local.root_directory
source_file = root / "subdir" / "source_file"
source_file.parent.mkdir(parents=True, exist_ok=True)
source_file.write_text(tested_content)
common_args = [
"--result-file", "${CODE_REPORT_FILE}",
"--files", "subdir/source_file"
]
(root / ".clang-format").write_text(config_clang_format)

args = common_args + extra_args
extra_config = "artifacts='./diff_temp/source_file.html'"

log = runner_with_analyzers.run(ConfigData().add_analyzer(analyzer, args, extra_config).finalize())
assert not re.findall(r'No such file or directory', log), f"'No such file or directory' is found in '{log}'"
assert re.findall(log_fail, log), f"'{log_fail}' is not found in '{log}'"
1 change: 1 addition & 0 deletions universum/analyzers/clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def main(settings: argparse.Namespace) -> List[utils.ReportData]:
cmd = [settings.executable, src_file_absolute]
_add_style_param_if_present(cmd, settings)
output, _ = utils.run_for_output(cmd)
target_file_absolute.parent.mkdir(parents=True, exist_ok=True)
with open(target_file_absolute, "w", encoding="utf-8") as output_file:
output_file.write(output)

Expand Down