Skip to content

Commit

Permalink
fix(code_report): create parent folders for target file for clang_format
Browse files Browse the repository at this point in the history
  • Loading branch information
d-cheholia authored Feb 5, 2024
1 parent 920baf2 commit f6abf90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit f6abf90

Please sign in to comment.