about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-11 21:48:47 +0100
committerGitHub <noreply@github.com>2022-02-11 21:48:47 +0100
commitffa8d6b47d2b3f7e8931eae7d07f87e3585597b8 (patch)
treecaa031b9d6d47f40ee173dc7ae89ffea61e4b3e2 /src/tools
parent15d71cff2d6286b0f281485637eace03dbe94916 (diff)
parentbf0e862903c4a799dd08dd00ffe68f9756fc6eb1 (diff)
downloadrust-ffa8d6b47d2b3f7e8931eae7d07f87e3585597b8.tar.gz
rust-ffa8d6b47d2b3f7e8931eae7d07f87e3585597b8.zip
Rollup merge of #93660 - aDotInTheVoid:rustdoc-type-tests, r=CraftSpider
rustdoc-json: Add some tests for typealias item

r? ```@CraftSpider```

Improves https://github.com/rust-lang/rust/issues/81359

The test's arn't pretty, and I think eventually we need a better way of doing repeated tests on a deeply nested path,
without repeating the way to get to that path

```@rustbot``` modify labels: +A-rustdoc-json +T-rustdoc +A-rustdoc +A-testsuite
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/jsondocck/src/main.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs
index b8ea10f3d22..d0f476955e1 100644
--- a/src/tools/jsondocck/src/main.rs
+++ b/src/tools/jsondocck/src/main.rs
@@ -231,7 +231,21 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
 
             let val = cache.get_value(&command.args[0])?;
             let results = select(&val, &command.args[1]).unwrap();
-            results.len() == expected
+            let eq = results.len() == expected;
+            if !command.negated && !eq {
+                return Err(CkError::FailedCheck(
+                    format!(
+                        "`{}` matched to `{:?}` with length {}, but expected length {}",
+                        &command.args[1],
+                        results,
+                        results.len(),
+                        expected
+                    ),
+                    command,
+                ));
+            } else {
+                eq
+            }
         }
         CommandKind::Is => {
             // @has <path> <jsonpath> <value> = check *exactly one* item matched by path, and it equals value
@@ -317,6 +331,6 @@ fn string_to_value<'a>(s: &str, cache: &'a Cache) -> Cow<'a, Value> {
             panic!("No variable: `{}`. Current state: `{:?}`", &s[1..], cache.variables)
         }))
     } else {
-        Cow::Owned(serde_json::from_str(s).unwrap())
+        Cow::Owned(serde_json::from_str(s).expect(&format!("Cannot convert `{}` to json", s)))
     }
 }