difftreelog
test upgrade tests to new apis
in: master
11 files changed
tests/golden/array_comp.jsonnet.goldendiffbeforeafterboth--- a/tests/golden/array_comp.jsonnet.golden
+++ b/tests/golden/array_comp.jsonnet.golden
@@ -1,38 +1,38 @@
[
- [
- 1,
- 4
- ],
- [
- 1,
- 5
- ],
- [
- 1,
- 6
- ],
- [
- 2,
- 4
- ],
- [
- 2,
- 5
- ],
- [
- 2,
- 6
- ],
- [
- 3,
- 4
- ],
- [
- 3,
- 5
- ],
- [
- 3,
- 6
- ]
+ [
+ 1,
+ 4
+ ],
+ [
+ 1,
+ 5
+ ],
+ [
+ 1,
+ 6
+ ],
+ [
+ 2,
+ 4
+ ],
+ [
+ 2,
+ 5
+ ],
+ [
+ 2,
+ 6
+ ],
+ [
+ 3,
+ 4
+ ],
+ [
+ 3,
+ 5
+ ],
+ [
+ 3,
+ 6
+ ]
]
\ No newline at end of file
tests/golden/builtin_parseJson.jsonnet.goldendiffbeforeafterboth--- a/tests/golden/builtin_parseJson.jsonnet.golden
+++ b/tests/golden/builtin_parseJson.jsonnet.golden
@@ -1,6 +1,6 @@
{
- "a": -1,
- "b": 1,
- "c": 3.141,
- "d": [ ]
+ "a": -1,
+ "b": 1,
+ "c": 3.141,
+ "d": [ ]
}
\ No newline at end of file
tests/golden/issue23.jsonnet.goldendiffbeforeafterboth--- a/tests/golden/issue23.jsonnet.golden
+++ b/tests/golden/issue23.jsonnet.golden
@@ -1,2 +1,2 @@
infinite recursion detected
- issue23.jsonnet:1:1-26: import "issue23.jsonnet"
\ No newline at end of file
+ issue23.jsonnet:1:1-26: import "issue23.jsonnet"
\ No newline at end of file
tests/golden/issue40.jsonnet.goldendiffbeforeafterboth--- a/tests/golden/issue40.jsonnet.golden
+++ b/tests/golden/issue40.jsonnet.golden
@@ -1,3 +1,3 @@
assert failed: is number
- issue40.jsonnet:6:10-31: assertion failure
- issue40.jsonnet:9:1-32: function <builtin_manifest_json_ex> call
\ No newline at end of file
+ issue40.jsonnet:6:10-31: assertion failure
+ issue40.jsonnet:9:1-32: function <builtin_manifest_json_ex> call
\ No newline at end of file
tests/golden/missing_binding.jsonnet.goldendiffbeforeafterboth--- a/tests/golden/missing_binding.jsonnet.golden
+++ b/tests/golden/missing_binding.jsonnet.golden
@@ -1,3 +1,3 @@
variable is not defined: sta
There is variable with similar name present: std
- missing_binding.jsonnet:1:1-5: variable <sta> access
\ No newline at end of file
+ missing_binding.jsonnet:1:1-5: variable <sta> access
\ No newline at end of file
tests/golden/object_comp.jsonnet.goldendiffbeforeafterboth--- a/tests/golden/object_comp.jsonnet.golden
+++ b/tests/golden/object_comp.jsonnet.golden
@@ -1,9 +1,9 @@
{
- "h1_2": "0a",
- "h1_3": "0a",
- "h1_4": "0a",
- "h2_3": "a1",
- "h2_4": "a1",
- "h3_2": "0a",
- "h3_4": "a1"
+ "h1_2": "0a",
+ "h1_3": "0a",
+ "h1_4": "0a",
+ "h2_3": "a1",
+ "h2_4": "a1",
+ "h3_2": "0a",
+ "h3_4": "a1"
}
\ No newline at end of file
tests/golden/test_assertThrow.jsonnet.goldendiffbeforeafterboth--- a/tests/golden/test_assertThrow.jsonnet.golden
+++ b/tests/golden/test_assertThrow.jsonnet.golden
@@ -1,2 +1,2 @@
runtime error: expected argument to throw on evaluation, but it returned instead
- test_assertThrow.jsonnet:2:1-26: function <assert_throw> call
\ No newline at end of file
+ test_assertThrow.jsonnet:2:1-26: function <assert_throw> call
\ No newline at end of file
tests/tests/common.rsdiffbeforeafterboth1use jrsonnet_evaluator::{2 error::Result,3 function::{builtin, FuncVal},4 throw, ObjValueBuilder, State, Thunk, Val,5};6use jrsonnet_stdlib::StateExt;78#[macro_export]9macro_rules! ensure_eq {10 ($a:expr, $b:expr $(,)?) => {{11 let a = &$a;12 let b = &$b;13 if a != b {14 ::jrsonnet_evaluator::throw!("assertion failed: a != b\na={:#?}\nb={:#?}", a, b)15 }16 }};17}1819#[macro_export]20macro_rules! ensure {21 ($v:expr $(,)?) => {22 if !$v {23 ::jrsonnet_evaluator::throw!("assertion failed: {}", stringify!($v))24 }25 };26}2728#[macro_export]29macro_rules! ensure_val_eq {30 ($a:expr, $b:expr) => {{31 if !::jrsonnet_evaluator::val::equals(&$a.clone(), &$b.clone())? {32 ::jrsonnet_evaluator::throw!(33 "assertion failed: a != b\na={:#?}\nb={:#?}",34 $a.to_json(35 2,36 #[cfg(feature = "exp-preserve-order")]37 false38 )?,39 $b.to_json(40 2,41 #[cfg(feature = "exp-preserve-order")]42 false43 )?,44 )45 }46 }};47}4849#[builtin]50fn assert_throw(lazy: Thunk<Val>, message: String) -> Result<bool> {51 match lazy.evaluate() {52 Ok(_) => {53 throw!("expected argument to throw on evaluation, but it returned instead")54 }55 Err(e) => {56 let error = format!("{}", e.error());57 ensure_eq!(message, error);58 }59 }60 Ok(true)61}6263#[allow(dead_code)]64pub fn with_test(s: &State) {65 let mut bobj = ObjValueBuilder::new();66 bobj.member("assertThrow".into())67 .hide()68 .value(Val::Func(FuncVal::StaticBuiltin(assert_throw::INST)))69 .expect("no error");7071 s.add_global("test".into(), Thunk::evaluated(Val::Obj(bobj.build())))72}1use jrsonnet_evaluator::{2 error::Result,3 function::{builtin, FuncVal},4 throw, ObjValueBuilder, State, Thunk, Val,5};6use jrsonnet_stdlib::StateExt;78#[macro_export]9macro_rules! ensure_eq {10 ($a:expr, $b:expr $(,)?) => {{11 let a = &$a;12 let b = &$b;13 if a != b {14 ::jrsonnet_evaluator::throw!("assertion failed: a != b\na={:#?}\nb={:#?}", a, b)15 }16 }};17}1819#[macro_export]20macro_rules! ensure {21 ($v:expr $(,)?) => {22 if !$v {23 ::jrsonnet_evaluator::throw!("assertion failed: {}", stringify!($v))24 }25 };26}2728#[macro_export]29macro_rules! ensure_val_eq {30 ($a:expr, $b:expr) => {{31 if !::jrsonnet_evaluator::val::equals(&$a.clone(), &$b.clone())? {32 use ::jrsonnet_evaluator::stdlib::manifest::JsonFormat;33 ::jrsonnet_evaluator::throw!(34 "assertion failed: a != b\na={:#?}\nb={:#?}",35 $a.manifest(JsonFormat::default())?,36 $b.manifest(JsonFormat::default())?,37 )38 }39 }};40}4142#[builtin]43fn assert_throw(lazy: Thunk<Val>, message: String) -> Result<bool> {44 match lazy.evaluate() {45 Ok(_) => {46 throw!("expected argument to throw on evaluation, but it returned instead")47 }48 Err(e) => {49 let error = format!("{}", e.error());50 ensure_eq!(message, error);51 }52 }53 Ok(true)54}5556#[allow(dead_code)]57pub fn with_test(s: &State) {58 let mut bobj = ObjValueBuilder::new();59 bobj.member("assertThrow".into())60 .hide()61 .value(Val::Func(FuncVal::StaticBuiltin(assert_throw::INST)))62 .expect("no error");6364 s.add_global("test".into(), Thunk::evaluated(Val::Obj(bobj.build())))65}tests/tests/golden.rsdiffbeforeafterboth--- a/tests/tests/golden.rs
+++ b/tests/tests/golden.rs
@@ -4,34 +4,36 @@
};
use jrsonnet_evaluator::{
- trace::{CompactFormat, PathResolver},
+ stdlib::manifest::JsonFormat,
+ trace::{CompactFormat, PathResolver, TraceFormat},
FileImportResolver, State,
};
use jrsonnet_stdlib::StateExt;
mod common;
-fn run(root: &Path, file: &Path) -> String {
+fn run(file: &Path) -> String {
let s = State::default();
- s.set_trace_format(CompactFormat {
- resolver: PathResolver::Relative(root.to_owned()),
- padding: 3,
- });
s.with_stdlib();
common::with_test(&s);
s.set_import_resolver(Box::new(FileImportResolver::default()));
+ let trace_format = CompactFormat {
+ resolver: PathResolver::FileName,
+ max_trace: 20,
+ padding: 4,
+ };
let v = match s.import(file) {
Ok(v) => v,
- Err(e) => return s.stringify_err(&e),
+ Err(e) => return trace_format.format(&e).unwrap(),
};
- match v.to_json(
- 3,
+ match v.manifest(
+ JsonFormat::default(),
#[cfg(feature = "exp-preserve-order")]
false,
) {
Ok(v) => v.to_string(),
- Err(e) => s.stringify_err(&e),
+ Err(e) => trace_format.format(&e).unwrap(),
}
}
@@ -46,7 +48,7 @@
continue;
}
- let result = run(&root, &entry.path());
+ let result = run(&entry.path());
let mut golden_path = entry.path();
golden_path.set_extension("jsonnet.golden");
tests/tests/sanity.rsdiffbeforeafterboth--- a/tests/tests/sanity.rs
+++ b/tests/tests/sanity.rs
@@ -1,4 +1,9 @@
-use jrsonnet_evaluator::{error::Result, throw, State, Val};
+use jrsonnet_evaluator::{
+ error::Result,
+ throw,
+ trace::{CompactFormat, TraceFormat},
+ State, Val,
+};
use jrsonnet_stdlib::StateExt;
mod common;
@@ -20,19 +25,20 @@
fn assert_negative() -> Result<()> {
let s = State::default();
s.with_stdlib();
+ let trace_format = CompactFormat::default();
{
let Err(e) = s.evaluate_snippet("snip".to_owned(), "assert 1 == 2: 'fail'; null") else {
throw!("assertion should fail");
};
- let e = s.stringify_err(&e);
+ let e = trace_format.format(&e).unwrap();
ensure!(e.starts_with("assert failed: fail\n"));
}
{
let Err(e) = s.evaluate_snippet("snip".to_owned(), "std.assertEqual(1, 2)") else {
throw!("assertion should fail")
};
- let e = s.stringify_err(&e);
+ let e = trace_format.format(&e).unwrap();
ensure!(e.starts_with("runtime error: Assertion failed. 1 != 2"))
}
tests/tests/suite.rsdiffbeforeafterboth--- a/tests/tests/suite.rs
+++ b/tests/tests/suite.rs
@@ -4,28 +4,29 @@
};
use jrsonnet_evaluator::{
- trace::{CompactFormat, PathResolver},
+ trace::{CompactFormat, TraceFormat},
FileImportResolver, State, Val,
};
use jrsonnet_stdlib::StateExt;
mod common;
-fn run(root: &Path, file: &Path) {
+fn run(file: &Path) {
let s = State::default();
- s.set_trace_format(CompactFormat {
- resolver: PathResolver::Relative(root.to_owned()),
- padding: 3,
- });
s.with_stdlib();
common::with_test(&s);
s.set_import_resolver(Box::new(FileImportResolver::default()));
+ let trace_format = CompactFormat::default();
match s.import(file) {
Ok(Val::Bool(true)) => {}
Ok(Val::Bool(false)) => panic!("test {} returned false", file.display()),
Ok(_) => panic!("test {} returned wrong type as result", file.display()),
- Err(e) => panic!("test {} failed:\n{}", file.display(), s.stringify_err(&e)),
+ Err(e) => panic!(
+ "test {} failed:\n{}",
+ file.display(),
+ trace_format.format(&e).unwrap()
+ ),
};
}
@@ -40,7 +41,7 @@
continue;
}
- run(&root, &entry.path());
+ run(&entry.path());
}
Ok(())