Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error deserialising output of cargo test --doc #102

Closed
xd009642 opened this issue Mar 8, 2020 · 3 comments
Closed

Error deserialising output of cargo test --doc #102

xd009642 opened this issue Mar 8, 2020 · 3 comments

Comments

@xd009642
Copy link

xd009642 commented Mar 8, 2020

I got the deserialisation message Err(Error("expected value", line: 3, column: 1)) when running parse_messages on the piped output of: cargo +nightly test --message-format json --manifest-path tarpaulin/tests/data/doc_coverage/Cargo.toml --doc

Below is the json (but prettified):

{
   "reason":"compiler-artifact",
   "package_id":"doc_coverage 0.1.0 (path+file:///home/xd009642/code/rust/tarpaulin/tests/data/doc_coverage)",
   "target":{
      "kind":[
         "lib"
      ],
      "crate_types":[
         "lib"
      ],
      "name":"doc_coverage",
      "src_path":"/home/xd009642/code/rust/tarpaulin/tests/data/doc_coverage/src/lib.rs",
      "edition":"2018",
      "doctest":true
   },
   "profile":{
      "opt_level":"0",
      "debuginfo":2,
      "debug_assertions":true,
      "overflow_checks":true,
      "test":false
   },
   "features":[

   ],
   "filenames":[
      "/home/xd009642/code/rust/tarpaulin/tests/data/doc_coverage/target/debug/deps/libdoc_coverage-c0b9eafea90c1625.rlib",
      "/home/xd009642/code/rust/tarpaulin/tests/data/doc_coverage/target/debug/deps/libdoc_coverage-c0b9eafea90c1625.rmeta"
   ],
   "executable":null,
   "fresh":false
}
@ehuss
Copy link
Contributor

ehuss commented Mar 8, 2020

I think parse_messages is misleading for how to parse JSON output. At a minimum, it would be best to only parse lines that start with {, like this:

    let mut reader = BufReader::new(command.stdout.unwrap());
    for line in reader.lines() {
        let line = line.unwrap();
        if line.starts_with('{') {
            let message: Message = serde_json::from_str(&line).unwrap();
            println!("{:#?}", message);
        }
    }

Additionally, you may want to scan for lines to stop looking for JSON output. For example, you don't want to continue parsing with cargo run when it starts executing the process. One tool I wrote has "stop lines" that will abort processing, like the regex ^\s*Running . I filed rust-lang/cargo#7978 for improving that.

In this case, test --doc is emitting test results to stdout.

@xd009642
Copy link
Author

xd009642 commented Mar 8, 2020

Ah I see! It would be helpful in this case if --doc also allowed the --no-run option because that's likely how my other usage is working fine

@oli-obk
Copy link
Owner

oli-obk commented Jul 12, 2020

We now have a more robust message parsing scheme

@oli-obk oli-obk closed this as completed Jul 12, 2020
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

No branches or pull requests

3 participants