-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add json output format #33
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR and tackling this long standing issue/missing feature! And even including a test! ^_^
Just a few comments about this.
@@ -92,6 +92,12 @@ impl Printer { | |||
writeln!(self.out).unwrap(); | |||
writeln!(self.out, "running {} test{}", num_tests, plural_s).unwrap(); | |||
} | |||
FormatSetting::Json => writeln!( | |||
self.out, | |||
"{{ \"type\": \"suite\", \"event\": \"started\", \"test_count\": {} }}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use raw string literals for all strings containing a "
? I think it's way easier to read. I.e.
"{{ \"type\": \"suite\", \"event\": \"started\", \"test_count\": {} }}", | |
r#"{{ "type": "suite", "event": "started", "test_count": {} }}"#, |
"{{ \"type\": \"test\", \"event\": \"started\", \"name\": \"{}\" }}", | ||
name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But what if the name contains a "
? Or \"
? The name
needs to be properly escaped. This crate looks like a perfect fit for this: it contains exactly the escaping logic we need without the full serde serialization logic. (I haven't looked too deeply into it yet though, so please check that)
Outcome::Failed(Failed { msg: Some(msg) }) => | ||
format!(r#", "stdout": "Error: \"{}\"\n""#, msg.escape_default()), | ||
_ => "".into(), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing trailing comma. This is true for many places actually. Would be great if you could add the trailing comma everywhere.
}, | ||
match outcome { | ||
Outcome::Failed(Failed { msg: Some(msg) }) => | ||
format!(r#", "stdout": "Error: \"{}\"\n""#, msg.escape_default()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also use the proper JSON escaping mentioned above.
{ "type": "test", "event": "started", "name": "cat" } | ||
{ "type": "test", "name": "cat", "event": "ok" } | ||
{ "type": "test", "event": "started", "name": "dog" } | ||
{ "type": "test", "name": "dog", "event": "failed", "stdout": "Error: \"was not a good boy\"\n" } | ||
{ "type": "test", "event": "started", "name": "fox" } | ||
{ "type": "test", "name": "fox", "event": "ok" } | ||
{ "type": "test", "event": "started", "name": "bunny" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_log!
cleans indentation, so please indent all these lines (just look at the test above)
Co-Authored-By: Timo <dev@2515.ch>
Co-Authored-By: Timo <dev@2515.ch>
Merged in #35 |
Closes #1