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

Libtest produces invalid JSONs for doctests on Windows #76151

Closed
mchernyavsky opened this issue Aug 31, 2020 · 4 comments
Closed

Libtest produces invalid JSONs for doctests on Windows #76151

mchernyavsky opened this issue Aug 31, 2020 · 4 comments
Labels
A-libtest Area: #[test] related C-bug Category: This is a bug.

Comments

@mchernyavsky
Copy link

Example project:

  • lib.rs
/// ```
/// ```
fn _foo() {}

I run the following command:

$ cargo test -- -Z unstable-options --format=json

This produces the following output:

    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running target\debug\deps\untitled-d6b954951d0421be.exe
{ "type": "suite", "event": "started", "test_count": 0 }
{ "type": "suite", "event": "ok", "passed": 0, "failed": 0, "allowed_fail": 0, "ignored": 0, "measured": 0, "filtered_out": 0 }
   Doc-tests untitled
{ "type": "suite", "event": "started", "test_count": 1 }
{ "type": "test", "event": "started", "name": "src\lib.rs - _foo (line 1)" }
{ "type": "test", "name": "src\lib.rs - _foo (line 1)", "event": "ok" }
{ "type": "suite", "event": "ok", "passed": 1, "failed": 0, "allowed_fail": 0, "ignored": 0, "measured": 0, "filtered_out": 0 }

For example, this JSON

{ "type": "test", "event": "started", "name": "src\lib.rs - _foo (line 1)" }

can't be parsed, because contains unescaped \ character.

Meta

rustc --version --verbose:

rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-pc-windows-msvc
release: 1.46.0
LLVM version: 10.0
@mchernyavsky mchernyavsky added the C-bug Category: This is a bug. label Aug 31, 2020
@jonas-schievink jonas-schievink added the A-libtest Area: #[test] related label Aug 31, 2020
@mchernyavsky
Copy link
Author

P.S. - On Unix, I also can create a directory with backslash in name (e.g. mkdir 'qwe\qwe').

@matklad
Copy link
Member

matklad commented Aug 31, 2020

Relevant code is here: https://github.com/rust-lang/rust/blob/8bfe289886af727150c1b9ec502cbfd7bbf425e8/library/test/src/formatters/json.rs

Not sure why this doesn't use serde/rustc-sereialize, but, if the reason is "we want to be as simple as possible", I have a super-simple library for outputting JSON here: https://github.com/matklad/write-json/

@euclio
Copy link
Contributor

euclio commented Aug 31, 2020

libtest can't easily depend on crates: they need the "rustc-dep-of-std" hack. That's probably why serde wasn't used here.

@ehuss
Copy link
Contributor

ehuss commented Apr 26, 2023

Closing as I believe this was fixed by #77890.

@ehuss ehuss closed this as completed Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: #[test] related C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants