Skip to content

Commit

Permalink
Break long lines
Browse files Browse the repository at this point in the history
That was fairly annoying because of the JSON literal in the test. Using
raw strings is good to not need to escape all the quotes, but it makes
it super hard to split a line. Just putting it into a new file is
probably the best idea.
  • Loading branch information
LukasKalbertodt committed Jan 14, 2024
1 parent 698e85e commit 431df0d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: LukasKalbertodt/check-basic-style@v0.1
with:
files: '**/!(*.md|*.json)'

check:
name: 'Build & test'
Expand Down
13 changes: 10 additions & 3 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ impl Printer {
Outcome::Measured(_) => unreachable!(),
},
match outcome {
Outcome::Failed(Failed { msg: Some(msg) }) =>
format!(r#", "stdout": "Error: \"{}\"\n""#, escape8259::escape(msg)),
Outcome::Failed(Failed { msg: Some(msg) }) => {
format!(
r#", "stdout": "Error: \"{}\"\n""#,
escape8259::escape(msg),
)
}
_ => "".into(),
}
)
Expand Down Expand Up @@ -226,7 +230,10 @@ impl Printer {
FormatSetting::Json => {
writeln!(
self.out,
r#"{{ "type": "suite", "event": "{}", "passed": {}, "failed": {}, "ignored": {}, "measured": {}, "filtered_out": {}, "exec_time": {} }}"#,
concat!(
r#"{{ "type": "suite", "event": "{}", "passed": {}, "failed": {},"#,
r#" "ignored": {}, "measured": {}, "filtered_out": {}, "exec_time": {} }}"#,
),
if conclusion.num_failed > 0 { "failed" } else { "ok" },
conclusion.num_passed,
conclusion.num_failed,
Expand Down
36 changes: 36 additions & 0 deletions tests/json-output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ "type": "suite", "event": "started", "test_count": 17 }
{ "type": "test", "event": "started", "name": "cat" }
{ "type": "test", "name": "cat", "event": "ok" }
{ "type": "test", "event": "started", "name": "\"ups\"" }
{ "type": "test", "name": "\"ups\"", "event": "failed", "stdout": "Error: \"failed to parse \"abc\"\"\n" }
{ "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" }
{ "type": "test", "name": "bunny", "event": "failed", "stdout": "Error: \"jumped too high\"\n" }
{ "type": "test", "event": "started", "name": "frog" }
{ "type": "test", "name": "frog", "event": "ignored" }
{ "type": "test", "event": "started", "name": "owl" }
{ "type": "test", "name": "owl", "event": "ignored" }
{ "type": "test", "event": "started", "name": "fly" }
{ "type": "test", "name": "fly", "event": "ignored" }
{ "type": "test", "event": "started", "name": "bear" }
{ "type": "test", "name": "bear", "event": "ignored" }
{ "type": "test", "event": "started", "name": "red" }
{ "type": "test", "name": "red", "event": "ok" }
{ "type": "test", "event": "started", "name": "blue" }
{ "type": "test", "name": "blue", "event": "failed", "stdout": "Error: \"sky fell down\"\n" }
{ "type": "test", "event": "started", "name": "yellow" }
{ "type": "test", "name": "yellow", "event": "ok" }
{ "type": "test", "event": "started", "name": "green" }
{ "type": "test", "name": "green", "event": "failed", "stdout": "Error: \"was poisoned\"\n" }
{ "type": "test", "event": "started", "name": "purple" }
{ "type": "test", "name": "purple", "event": "ignored" }
{ "type": "test", "event": "started", "name": "cyan" }
{ "type": "test", "name": "cyan", "event": "ignored" }
{ "type": "test", "event": "started", "name": "orange" }
{ "type": "test", "name": "orange", "event": "ignored" }
{ "type": "test", "event": "started", "name": "pink" }
{ "type": "test", "name": "pink", "event": "ignored" }
{ "type": "suite", "event": "failed", "passed": 4, "failed": 5, "ignored": 8, "measured": 0, "filtered_out": 0, "exec_time": 0.000000000 }
41 changes: 1 addition & 40 deletions tests/mixed_bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,44 +635,5 @@ fn json_output() {
}
);

assert_log!(
out,
r#"
{ "type": "suite", "event": "started", "test_count": 17 }
{ "type": "test", "event": "started", "name": "cat" }
{ "type": "test", "name": "cat", "event": "ok" }
{ "type": "test", "event": "started", "name": "\"ups\"" }
{ "type": "test", "name": "\"ups\"", "event": "failed", "stdout": "Error: \"failed to parse \"abc\"\"\n" }
{ "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" }
{ "type": "test", "name": "bunny", "event": "failed", "stdout": "Error: \"jumped too high\"\n" }
{ "type": "test", "event": "started", "name": "frog" }
{ "type": "test", "name": "frog", "event": "ignored" }
{ "type": "test", "event": "started", "name": "owl" }
{ "type": "test", "name": "owl", "event": "ignored" }
{ "type": "test", "event": "started", "name": "fly" }
{ "type": "test", "name": "fly", "event": "ignored" }
{ "type": "test", "event": "started", "name": "bear" }
{ "type": "test", "name": "bear", "event": "ignored" }
{ "type": "test", "event": "started", "name": "red" }
{ "type": "test", "name": "red", "event": "ok" }
{ "type": "test", "event": "started", "name": "blue" }
{ "type": "test", "name": "blue", "event": "failed", "stdout": "Error: \"sky fell down\"\n" }
{ "type": "test", "event": "started", "name": "yellow" }
{ "type": "test", "name": "yellow", "event": "ok" }
{ "type": "test", "event": "started", "name": "green" }
{ "type": "test", "name": "green", "event": "failed", "stdout": "Error: \"was poisoned\"\n" }
{ "type": "test", "event": "started", "name": "purple" }
{ "type": "test", "name": "purple", "event": "ignored" }
{ "type": "test", "event": "started", "name": "cyan" }
{ "type": "test", "name": "cyan", "event": "ignored" }
{ "type": "test", "event": "started", "name": "orange" }
{ "type": "test", "name": "orange", "event": "ignored" }
{ "type": "test", "event": "started", "name": "pink" }
{ "type": "test", "name": "pink", "event": "ignored" }
{ "type": "suite", "event": "failed", "passed": 4, "failed": 5, "ignored": 8, "measured": 0, "filtered_out": 0, "exec_time": 0.000000000 }"#
);
assert_log!(out, include_str!("json-output.json"));
}

0 comments on commit 431df0d

Please sign in to comment.