Update CargoTool for new tool support and improved parsing.
Review Request #11654 — Created June 12, 2021 and submitted
CargoToolto subclass the newer
BaseTool, and to use
the newer features it offers (dependencies, improved file extension
handling, centralized base command building, and new comment options).
The parsing has been completely redone. This tool runs both
cargo test, and these output content differently.
cargo clippy, we can safely use
--message-format=jsonto get a
series of JSON payloads we can process, which works well, and is less
error-prone than the previous parsing logic.
However, JSON output is, as of now, only available in nightly builds of
cargo test, so we can't depend on it. Instead, we use pattern matching
to try to find the test output, turning that into a general comment.
It's still better than the old logic, which as far as I can tell no
longer works (or maybe never did), since the old logic was looking for
output that isn't present in at least modern builds of
There's also some additional handling for unit tests. If
is enabled, it will be run against unit tests, using the (semi-modern
--testsargument). If not, and
cargo testencounters a syntax error,
it will be reported, along with recommendations.
Test output is also capped to 100 lines.
Unit tests cover all these situations, and we have notes to support
future JSON output from
This is the last tool that needed to be ported over to the new tool
and test support.
Unit tests pass on Python 2.7 and 3.x.