Port run-make/libtest-json/validate_json.py to Rust · rust-lang/rust@3116db6 (original) (raw)

File tree

2 files changed

lines changed

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
3 3 //@ ignore-cross-compile
4 4 //@ needs-unwind (test file contains #[should_panic] test)
5 5
6 -use run_make_support::{cmd, diff, python_command, rustc};
6 +use run_make_support::{cmd, diff, rustc, serde_json};
7 7
8 8 fn main() {
9 9 rustc().arg("--test").input("f.rs").run();
@@ -21,7 +21,18 @@ fn run_tests(extra_args: &[&str], expected_file: &str) {
21 21 .run_fail();
22 22 let test_stdout = &cmd_out.stdout_utf8();
23 23
24 -python_command().arg("validate_json.py").stdin(test_stdout).run();
24 +// Verify that the test process output is JSON Lines, i.e. each line is valid JSON.
25 +for (line, n) in test_stdout.lines().zip(1..) {
26 +if let Err(e) = serde_json::from_str::<serde_json::Value>(line) {
27 +panic!(
28 +"could not parse JSON on line {n}: {e}\n\
29 + \n\
30 + === STDOUT ===\n\
31 + {test_stdout}\
32 + =============="
33 +);
34 +}
35 +}
25 36
26 37 diff()
27 38 .expected_file(expected_file)