Skip to main content

read_crate_output

Function read_crate_output 

Source
pub fn read_crate_output(text: &str) -> CrateRead
Expand description

Read cargo test’s output: each Running tests/<name>.rs line joined to the test result: line that follows it, judged by its counts, and everything else it ran listed rather than ignored.

cargo test’s machine format is still unstable, so this reads what every cargo prints. The Running line names the binary the following result belongs to; without it a run of forty binaries is forty anonymous result lines, which is how a per-test-binary outcome becomes an untraceable total. Escape sequences are stripped from every line before it is matched, so a coloured run reads as a plain one.

A result line is judged by the first of these that holds:

The result lineOutcome
a failed count above zerofail
the word FAILEDfail
the word ok and no passed counterror
the word ok and nothing passed (every test ignored, say)skip
the word ok and a filtered-out count above zero (a subset)skip
the word okpass
any other worderror

A binary whose Running line is followed by no result line is an error. The crate’s own unit-test binary (Running unittests <path>), its doctests (Doc-tests <crate>), a binary outside tests/ and a result line with no Running line before it are listed in CrateRead::dropped with the reason, and never credited to a neighbour.

use majordomus_cli::evidence::{read_crate_output, Outcome};

let read = read_crate_output(
    "     Running tests/all_ignored.rs (target/debug/deps/all_ignored-1)\n\
     test result: ok. 0 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; \
     finished in 0.00s\n\
          Running tests/broken.rs (target/debug/deps/broken-1)\n\
     test result: ok. 2 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; \
     finished in 0.20s\n\
          Running tests/silent.rs (target/debug/deps/silent-1)\n",
);
let outcomes: Vec<(&str, Outcome)> =
    read.binaries.iter().map(|b| (b.name.as_str(), b.outcome)).collect();
assert_eq!(
    outcomes,
    [("all_ignored", Outcome::Skip), ("broken", Outcome::Fail), ("silent", Outcome::Error)]
);