Skip to content

refactor: move what any external tool needs out of clang-format - #146

Merged
skipbit merged 4 commits into
mainfrom
refactor/external-tool
Nov 23, 2026
Merged

skipbit merged 4 commits into
mainfrom
refactor/external-tool

Conversation

@skipbit

@skipbit skipbit commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

Moves what any external tool needs out of the clang-format code, so a second tool can use it without a copy. Nothing a user sees changes.

  • src/tool/ExternalTool holds the tool's name, program and version (ExternalTool), why it could not run or failed (ToolNotRun, ToolFailed), finding it on PATH by name (findTool), asking it for its version (describeTool), and running it (runTool, standardOutputOf).
  • command/ToolText holds the messages about a tool: the line naming the tool in use, the one saying it was not found, a version that could not be learned, and a run that failed under a given heading.
  • command/ToolLookup finds a tool, learns its version and names it on standard error (lookUpTool), which the format command did itself.
  • format/ClangFormat keeps the command lines of a format and a check, and command/FormatText the messages that name a file.

src/format and src/tool join the linted modules. src/format had been left out, so the code moved here was not checked before; the one finding, a missing <cstddef>, is fixed in the moved code.

Tests

The tests of finding a tool and reading its version move from ClangFormatTest to ExternalToolTest, and those of the tool messages from FormatTextTest to ToolTextTest, with the name of the tool now given and kept in ExternalTool. ToolTextTest has one more test, of a failed run under a heading, which FormatTextTest covered only through a format, and ExternalToolTest three more, of runTool and standardOutputOf, which ClangFormatTest covered only through a format and a check.

Finding a program on PATH, asking it for its version, running it and
describing why it could not run or failed hold nothing particular to
clang-format. They move to src/tool and command/ToolText, which take
the tool's name, so another tool can use them as they are.

ClangFormat keeps the command lines of a format and a check, and
FormatText the messages that name a file.
Both were left out of the linted modules, so the code that runs
clang-format and other tools was never checked.
ExternalTool holds the name the messages give the tool, so the
messages about a tool that was found take the tool alone. lookUpTool
finds a tool, learns its version and names it on standard error, as
the format command did itself, so another command can do the same.
runTool and standardOutputOf are tested on their own, including the
second run that reads why a run failed. The header names
Process::runProgram again as why the streams cannot be read apart, and
the new command sources sit in order in the source list.
@skipbit
skipbit merged commit afe5120 into main Nov 23, 2026
29 checks passed
@skipbit
skipbit deleted the refactor/external-tool branch November 23, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant