Fix ament_clang_format output with empty files#580
Conversation
78269be to
9d07895
Compare
|
Pulls: #580 |
christophebedard
left a comment
There was a problem hiding this comment.
A test would be ideal, but there are no tests for ament_clang_format right now other than linter tests on the package itself. However, you could try extracting this logic to a separate function and then unit-testing it
|
@christophebedard this PR adds a basic executiion unit test for ament_clang_format #563 |
clang-format doesn't output anything for empty files that are passed to it. This causes our file indices to get offset, resulting in the printed replacements being generated for the wrong file. Instead, we'll detect empty files and output a special line for them instead. Signed-off-by: Nathan Wiebe Neufeldt <wn.nathan@gmail.com>
Without the previous change, the `test_empty_files` test would fail, though the `test_empty_files_reformat` succeeded. With the previous change, they both pass. Signed-off-by: Nathan Wiebe Neufeldt <wn.nathan@gmail.com>
9d07895 to
bf57caf
Compare
|
Tick the box to add this pull request to the merge queue (same as
|
|
@christophebedard I've added two unit tests to cover the case of empty files, similarly to the example provided in the PR description. |
Clang format doesn't output anything for empty files that are passed to it. This means an empty source code file causes our file indices to get offset from the parsed replacements, resulting in the printed replacements being generated for the wrong file. This behaviour has been verified on
clang-formatversions 10–21. (This doesn't impact the correctness of the--reformatoption, only the correctness of the rendered output without that flag.)This change detects empty files and fixes the indices accordingly. It also outputs a special output for them.
Example:
Files:
Before this change:
After this change: