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 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
17 changes: 17 additions & 0 deletions tests/test_code_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,20 @@ 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}")


def test_clang_format_analyzer_with_subfolder(runner_with_analyzers: UniversumRunner):
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(source_code_c)
common_args = [
"--result-file", "${CODE_REPORT_FILE}",
"--files", "subdir/source_file"
]

(root / ".clang-format").write_text(config_clang_format)
log = runner_with_analyzers.run(ConfigData().add_analyzer("clang_format", common_args).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