about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-09-02 04:19:30 +0200
committerGitHub <noreply@github.com>2024-09-02 04:19:30 +0200
commit5c3370d684a0fe2d1f9b23092e454890c1ef746a (patch)
treed8dc1fd740eb9b83530893826656bf26c3e7f6b0
parent820540aaa0707deba50905d54e6750f9a963cbbf (diff)
parentf78979e687a3105f33be30f94a597ae9f5a18f4d (diff)
downloadrust-5c3370d684a0fe2d1f9b23092e454890c1ef746a.tar.gz
rust-5c3370d684a0fe2d1f9b23092e454890c1ef746a.zip
Rollup merge of #129837 - aDotInTheVoid:test-better-json, r=jieyouxu
Actually parse stdout json, instead of using hacky contains logic.

Fixes up the test added in #128963, to actually parse the stdout to JSON, instead of just checking that it contains `{"`.

CC ``@GuillaumeGomez``

r? ``@jieyouxu``
-rw-r--r--tests/run-make/rustdoc-output-stdout/rmake.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/tests/run-make/rustdoc-output-stdout/rmake.rs b/tests/run-make/rustdoc-output-stdout/rmake.rs
index dbc9892f3f5..bcf5e4d9723 100644
--- a/tests/run-make/rustdoc-output-stdout/rmake.rs
+++ b/tests/run-make/rustdoc-output-stdout/rmake.rs
@@ -4,17 +4,28 @@
 use std::path::PathBuf;
 
 use run_make_support::path_helpers::{cwd, has_extension, read_dir_entries_recursive};
-use run_make_support::rustdoc;
+use run_make_support::{rustdoc, serde_json};
 
 fn main() {
-    // First we check that we generate the JSON in the stdout.
-    rustdoc()
+    let json_string = rustdoc()
         .input("foo.rs")
         .out_dir("-")
         .arg("-Zunstable-options")
         .output_format("json")
         .run()
-        .assert_stdout_contains("{\"");
+        .stdout_utf8();
+
+    // First we check that we generate the JSON in the stdout.
+    let json_value: serde_json::Value =
+        serde_json::from_str(&json_string).expect("stdout should be valid json");
+
+    // We don't care to test the specifics of the JSON, as that's done
+    // elsewhere, just check that it has a format_version (as all JSON output
+    // should).
+    let format_version = json_value["format_version"]
+        .as_i64()
+        .expect("json output should contain format_version field");
+    assert!(format_version > 30);
 
     // Then we check it didn't generate any JSON file.
     read_dir_entries_recursive(cwd(), |path| {