I'd like to integrate cargo into Atom (the text editor) and I was wondering if it is possible to get the commands' result as json. I'd like to be able to get errors and their line number from cargo build as well as test results from cargo test.
Unfortunately no, this aspect of Cargo has not yet been implemented. Cargo is planned to have more tooling support with nice machine-readable output formats (like JSON or TOML). For test results, however, that would be a problem more of the testing framework than Cargo itself, so it may not necessarily be up to Cargo to do so.
What is the testing framework that cargo runs when you use cargo test?
Currently it's libtest in the standard distribution.
And we removed it fairly recently in an effort to streamline the runner, since we didn't want to stabilize it.
since rustc can now output json, at least cargo build could get a setting to output json
Can RUSTFLAGS env variable be used here?
No, it can't: https://github.com/rust-lang/rust/issues/37011
With --message-format=json now stable, I'm going to close this.
Sorry to necropost, but I figured this issue was a good place to bring up this point than creating a new one.
Are there plans to add JSON output for cargo test results? While I see there's --message-format=json it looks like that only makes the build step output JSON, and the actual test results are still in the human-readable pretty format.
My motivation is that I want to build a Nuclide test runner provider for Atom, and it would be a lot easier to parse test results if they were output in JSON.
@aergonaut ah the test framework (src/libtest/lib.rs in the rust-lang/rust repository) is actually somewhat separate from the current implementation of --message-format=json). It's definitely desired to have a more full-featured testing framework in the long run, though! We've long wanted the ability to have custom test frameworks to implement this logic.
Thanks for the reply @alexcrichton. I'll look forward to hopefully seeing that RFC make progress in the future 馃槂
Most helpful comment
@aergonaut ah the test framework (src/libtest/lib.rs in the rust-lang/rust repository) is actually somewhat separate from the current implementation of
--message-format=json). It's definitely desired to have a more full-featured testing framework in the long run, though! We've long wanted the ability to have custom test frameworks to implement this logic.