Skip to content

Commit

Permalink
Fix PR Comments of JSON PR (#33)
Browse files Browse the repository at this point in the history
Co-Authored-By: Timo <dev@2515.ch>
  • Loading branch information
LukasKalbertodt and t-moe committed Jan 14, 2024
1 parent 3bfc0f3 commit 766448d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 69 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exclude = [".github"]
clap = { version = "4.0.8", features = ["derive"] }
threadpool = "1.8.1"
termcolor = "1.0.5"
escape8259 = "0.5.2"

[dev-dependencies]
fastrand = "1.8.0"
Expand Down
24 changes: 13 additions & 11 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use std::{fs::File, time::Duration};
use termcolor::{Ansi, Color, ColorChoice, ColorSpec, NoColor, StandardStream, WriteColor};

use crate::{
Arguments, ColorSetting, Conclusion, FormatSetting, Outcome, Trial, Failed,
Measurement, TestInfo,
Arguments, ColorSetting, Conclusion, Failed, FormatSetting, Measurement, Outcome, TestInfo,
Trial,
};

pub(crate) struct Printer {
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Printer {
}
FormatSetting::Json => writeln!(
self.out,
"{{ \"type\": \"suite\", \"event\": \"started\", \"test_count\": {} }}",
r#"{{ "type": "suite", "event": "started", "test_count": {} }}"#,
num_tests
)
.unwrap(),
Expand All @@ -108,7 +108,7 @@ impl Printer {
match self.format {
FormatSetting::Pretty => {
let kind = if kind.is_empty() {
format!("")
String::new()
} else {
format!("[{}] ", kind)
};
Expand All @@ -130,8 +130,8 @@ impl Printer {
FormatSetting::Json => {
writeln!(
self.out,
"{{ \"type\": \"test\", \"event\": \"started\", \"name\": \"{}\" }}",
name
r#"{{ "type": "test", "event": "started", "name": "{}" }}"#,
escape8259::escape(name),
)
.unwrap();
}
Expand Down Expand Up @@ -169,14 +169,16 @@ impl Printer {
writeln!(
self.out,
r#"{{ "type": "bench", "name": "{}", "median": {}, "deviation": {} }}"#,
info.name, avg, variance
escape8259::escape(&info.name),
avg,
variance,
)
.unwrap();
} else {
writeln!(
self.out,
r#"{{ "type": "test", "name": "{}", "event": "{}"{} }}"#,
info.name,
escape8259::escape(&info.name),
match outcome {
Outcome::Passed => "ok",
Outcome::Failed(_) => "failed",
Expand All @@ -185,7 +187,7 @@ impl Printer {
},
match outcome {
Outcome::Failed(Failed { msg: Some(msg) }) =>
format!(r#", "stdout": "Error: \"{}\"\n""#, msg.escape_default()),
format!(r#", "stdout": "Error: \"{}\"\n""#, escape8259::escape(msg)),

Check failure on line 190 in src/printer.rs

View workflow job for this annotation

GitHub Actions / Check basic style

Line too long

Line exceeds maximum length of 100 (it's 101 Unicode codepoints long)

Check failure on line 190 in src/printer.rs

View workflow job for this annotation

GitHub Actions / Check basic style

Line too long

Line exceeds maximum length of 100 (it's 101 Unicode codepoints long)
_ => "".into(),
}
)
Expand Down Expand Up @@ -224,7 +226,7 @@ impl Printer {
FormatSetting::Json => {
writeln!(
self.out,
"{{ \"type\": \"suite\", \"event\": \"{}\", \"passed\": {}, \"failed\": {}, \"ignored\": {}, \"measured\": {}, \"filtered_out\": {}, \"exec_time\": {} }}",
r#"{{ "type": "suite", "event": "{}", "passed": {}, "failed": {}, "ignored": {}, "measured": {}, "filtered_out": {}, "exec_time": {} }}"#,

Check failure on line 229 in src/printer.rs

View workflow job for this annotation

GitHub Actions / Check basic style

Line too long

Line exceeds maximum length of 100 (it's 158 Unicode codepoints long)

Check failure on line 229 in src/printer.rs

View workflow job for this annotation

GitHub Actions / Check basic style

Line too long

Line exceeds maximum length of 100 (it's 158 Unicode codepoints long)
if conclusion.num_failed > 0 { "failed" } else { "ok" },
conclusion.num_passed,
conclusion.num_failed,
Expand Down Expand Up @@ -257,7 +259,7 @@ impl Printer {
}

let kind = if test.info.kind.is_empty() {
format!("")
String::new()
} else {
format!("[{}] ", test.info.kind)
};
Expand Down
Loading

0 comments on commit 766448d

Please sign in to comment.