Improve some jsondocck errors

This commit is contained in:
Nixon Enraght-Moony 2021-02-26 22:55:28 +00:00
parent 9925ecb392
commit 5f24798b9e
1 changed files with 22 additions and 2 deletions

View File

@ -205,7 +205,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();
let pat = string_to_value(&command.args[2], cache);
results.contains(&pat.as_ref())
let has = results.contains(&pat.as_ref());
// Give better error for when @has check fails
if !command.negated && !has {
return Err(CkError::FailedCheck(
format!(
"{} matched to {:?} but didn't have {:?}",
&command.args[1],
results,
pat.as_ref()
),
command,
));
} else {
has
}
}
_ => unreachable!(),
}
@ -233,7 +247,13 @@ fn check_command(command: Command, cache: &mut Cache) -> Result<(), CkError> {
assert_eq!(command.args[1], "=", "Expected an `=`");
let val = cache.get_value(&command.args[2])?;
let results = select(&val, &command.args[3]).unwrap();
assert_eq!(results.len(), 1);
assert_eq!(
results.len(),
1,
"Didn't get 1 result for `{}`: got {:?}",
command.args[3],
results
);
match results.len() {
0 => false,
1 => {