diff options
| author | bors <bors@rust-lang.org> | 2021-03-26 04:10:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-03-26 04:10:13 +0000 |
| commit | 7637fd588bfee93d627474a18dcbf11a81803665 (patch) | |
| tree | f27d975515727ef5279c2650b088fda0f2a4872e /src/tools | |
| parent | 0ced530534de1a77504b6229e6303d37a12282ee (diff) | |
| parent | b0bec9553429639fc20dcc224f7525d99c325655 (diff) | |
| download | rust-7637fd588bfee93d627474a18dcbf11a81803665.tar.gz rust-7637fd588bfee93d627474a18dcbf11a81803665.zip | |
Auto merge of #83503 - Dylan-DPC:rollup-mqvjfav, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #83055 ([rustdoc] Don't document stripped items in JSON renderer.) - #83437 (Refactor #82270 as lint instead of an error) - #83444 (Fix bootstrap tests on beta) - #83456 (Add docs for Vec::from functions) - #83463 (ExitStatusExt: Fix missing word in two docs messages) - #83470 (Fix patch note about #80653 not mentioning nested nor recursive) - #83485 (Mark asm tests as requiring LLVM 10.0.1) - #83486 (Don't ICE when using `#[global_alloc]` on a non-item statement) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/jsondocck/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/tools/jsondocck/src/cache.rs | 10 | ||||
| -rw-r--r-- | src/tools/jsondocck/src/main.rs | 20 |
3 files changed, 27 insertions, 4 deletions
diff --git a/src/tools/jsondocck/Cargo.toml b/src/tools/jsondocck/Cargo.toml index 97052ef58d6..a6efc4c9a6b 100644 --- a/src/tools/jsondocck/Cargo.toml +++ b/src/tools/jsondocck/Cargo.toml @@ -12,3 +12,4 @@ lazy_static = "1.4" shlex = "0.1" serde = "1.0" serde_json = "1.0" +fs-err = "2.5.0" diff --git a/src/tools/jsondocck/src/cache.rs b/src/tools/jsondocck/src/cache.rs index 8a6a911321c..a188750c56a 100644 --- a/src/tools/jsondocck/src/cache.rs +++ b/src/tools/jsondocck/src/cache.rs @@ -1,8 +1,10 @@ use crate::error::CkError; use serde_json::Value; use std::collections::HashMap; +use std::io; use std::path::{Path, PathBuf}; -use std::{fs, io}; + +use fs_err as fs; #[derive(Debug)] pub struct Cache { @@ -31,7 +33,11 @@ impl Cache { self.last_path = Some(resolve.clone()); resolve } else { - self.last_path.as_ref().unwrap().clone() + self.last_path + .as_ref() + // FIXME: Point to a line number + .expect("No last path set. Make sure to specify a full path before using `-`") + .clone() } } diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs index bcb3f6922ef..216890d59ad 100644 --- a/src/tools/jsondocck/src/main.rs +++ b/src/tools/jsondocck/src/main.rs @@ -239,7 +239,20 @@ 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(); let pat = string_to_value(&command.args[2], cache); - results.len() == 1 && results[0] == pat.as_ref() + let is = results.len() == 1 && results[0] == pat.as_ref(); + if !command.negated && !is { + return Err(CkError::FailedCheck( + format!( + "{} matched to {:?}, but expected {:?}", + &command.args[1], + results, + pat.as_ref() + ), + command, + )); + } else { + is + } } CommandKind::Set => { // @set <name> = <path> <jsonpath> @@ -299,7 +312,10 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> { fn string_to_value<'a>(s: &str, cache: &'a Cache) -> Cow<'a, Value> { if s.starts_with("$") { - Cow::Borrowed(&cache.variables[&s[1..]]) + Cow::Borrowed(&cache.variables.get(&s[1..]).unwrap_or_else(|| { + // FIXME(adotinthevoid): Show line number + panic!("No variable: `{}`. Current state: `{:?}`", &s[1..], cache.variables) + })) } else { Cow::Owned(serde_json::from_str(s).unwrap()) } |
