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

Add json output format #33

Closed
wants to merge 1 commit into from

Conversation

PaulWagener
Copy link
Contributor

Closes #1

Copy link
Owner

@LukasKalbertodt LukasKalbertodt left a 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\": {} }}",
Copy link
Owner

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.

Suggested change
"{{ \"type\": \"suite\", \"event\": \"started\", \"test_count\": {} }}",
r#"{{ "type": "suite", "event": "started", "test_count": {} }}"#,

Comment on lines +133 to +134
"{{ \"type\": \"test\", \"event\": \"started\", \"name\": \"{}\" }}",
name
Copy link
Owner

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(),
}
Copy link
Owner

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()),
Copy link
Owner

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.

Comment on lines +548 to +554
{ "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" }
Copy link
Owner

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)

t-moe added a commit to t-moe/libtest-mimic that referenced this pull request Dec 22, 2023
LukasKalbertodt added a commit that referenced this pull request Jan 14, 2024
Co-Authored-By: Timo <dev@2515.ch>
@LukasKalbertodt LukasKalbertodt mentioned this pull request Jan 14, 2024
LukasKalbertodt added a commit that referenced this pull request Jan 14, 2024
Co-Authored-By: Timo <dev@2515.ch>
@LukasKalbertodt
Copy link
Owner

Merged in #35

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

Successfully merging this pull request may close these issues.

JSON output
2 participants