about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-08-18 14:55:23 +0800
committerGitHub <noreply@github.com>2024-08-18 14:55:23 +0800
commit4e087683e59e89cce3754512af8316b0c5680c23 (patch)
tree586dd6722ea358b8e6e67f764380abaf3024e2c7
parent42b54a98b6db10254a519b889f75006ac367640c (diff)
parent3116db669c4e80ffdae5a34a8dd9bcfba4b1a9be (diff)
Rollup merge of #129185 - Zalathar:validate-json, r=jieyouxu
Port `run-make/libtest-json/validate_json.py` to Rust

This is a trivial Python script that simply tries to parse each line of stdin (i.e. the test process output) as JSON, to verify that the overall output is JSON Lines.

We can perform the same check directly in `rmake.rs` using `serde_json`.

r? ````@jieyouxu````
-rw-r--r--tests/run-make/libtest-json/rmake.rs15
-rwxr-xr-xtests/run-make/libtest-json/validate_json.py8
2 files changed, 13 insertions, 10 deletions
diff --git a/tests/run-make/libtest-json/rmake.rs b/tests/run-make/libtest-json/rmake.rs
index acbd88dc46c..c31f4a79b64 100644
--- a/tests/run-make/libtest-json/rmake.rs
+++ b/tests/run-make/libtest-json/rmake.rs
@@ -3,7 +3,7 @@
 //@ ignore-cross-compile
 //@ needs-unwind (test file contains #[should_panic] test)
 
-use run_make_support::{cmd, diff, python_command, rustc};
+use run_make_support::{cmd, diff, rustc, serde_json};
 
 fn main() {
     rustc().arg("--test").input("f.rs").run();
@@ -21,7 +21,18 @@ fn run_tests(extra_args: &[&str], expected_file: &str) {
         .run_fail();
     let test_stdout = &cmd_out.stdout_utf8();
 
-    python_command().arg("validate_json.py").stdin(test_stdout).run();
+    // Verify that the test process output is JSON Lines, i.e. each line is valid JSON.
+    for (line, n) in test_stdout.lines().zip(1..) {
+        if let Err(e) = serde_json::from_str::<serde_json::Value>(line) {
+            panic!(
+                "could not parse JSON on line {n}: {e}\n\
+                \n\
+                === STDOUT ===\n\
+                {test_stdout}\
+                =============="
+            );
+        }
+    }
 
     diff()
         .expected_file(expected_file)
diff --git a/tests/run-make/libtest-json/validate_json.py b/tests/run-make/libtest-json/validate_json.py
deleted file mode 100755
index 657f732f2bf..00000000000
--- a/tests/run-make/libtest-json/validate_json.py
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import json
-
-# Try to decode line in order to ensure it is a valid JSON document
-for line in sys.stdin:
-    json.loads(line)