mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Lockdown kata test prints as well as prints of various values (#249)
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
GitHub
parent
9894f00829
commit
3ac9b1121e
@@ -139,9 +139,10 @@ pub fn eval_file(
|
||||
query: &str,
|
||||
enable_tracing: bool,
|
||||
strict: bool,
|
||||
) -> Result<Vec<Value>> {
|
||||
) -> Result<(Vec<Value>, Vec<String>)> {
|
||||
let mut engine: Engine = Engine::new();
|
||||
engine.set_strict_builtin_errors(strict);
|
||||
engine.set_gather_prints(true);
|
||||
|
||||
#[cfg(feature = "coverage")]
|
||||
engine.set_enable_coverage(true);
|
||||
@@ -206,7 +207,7 @@ pub fn eval_file(
|
||||
}
|
||||
}
|
||||
|
||||
Ok(results)
|
||||
Ok((results, engine.take_prints()?))
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
@@ -254,6 +255,7 @@ struct TestCase {
|
||||
query: String,
|
||||
sort_bindings: Option<bool>,
|
||||
want_result: Option<ValueOrVec>,
|
||||
want_prints: Option<Vec<String>>,
|
||||
no_result: Option<bool>,
|
||||
skip: Option<bool>,
|
||||
error: Option<String>,
|
||||
@@ -333,7 +335,7 @@ fn yaml_test_impl(file: &str) -> Result<()> {
|
||||
enable_tracing,
|
||||
case.strict,
|
||||
) {
|
||||
Ok(results) => match case.want_result {
|
||||
Ok((results, prints)) => match case.want_result {
|
||||
Some(want_result) => {
|
||||
let mut expected_results = vec![];
|
||||
match want_result {
|
||||
@@ -344,6 +346,18 @@ fn yaml_test_impl(file: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
check_output(&results, &expected_results)?;
|
||||
if let Some(expected_prints) = case.want_prints {
|
||||
assert_eq!(expected_prints.len(), prints.len());
|
||||
for (idx, ep) in expected_prints.into_iter().enumerate() {
|
||||
if ep != prints[idx] {
|
||||
std::println!(
|
||||
"print mismatch :\n{}",
|
||||
prettydiff::diff_chars(&ep, &prints[idx])
|
||||
);
|
||||
panic!("exiting");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ if case.no_result == Some(true) => (),
|
||||
_ => bail!("eval succeeded and did not produce any errors"),
|
||||
|
||||
Reference in New Issue
Block a user