difftreelog
test upgrade tests to new apis
in: master
11 files changed
tests/golden/array_comp.jsonnet.goldendiffbeforeafterboth1[1[2 [2 [3 1,3 1,4 44 45 ],5 ],6 [6 [7 1,7 1,8 58 59 ],9 ],10 [10 [11 1,11 1,12 612 613 ],13 ],14 [14 [15 2,15 2,16 416 417 ],17 ],18 [18 [19 2,19 2,20 520 521 ],21 ],22 [22 [23 2,23 2,24 624 625 ],25 ],26 [26 [27 3,27 3,28 428 429 ],29 ],30 [30 [31 3,31 3,32 532 533 ],33 ],34 [34 [35 3,35 3,36 636 637 ]37 ]38]38]tests/golden/builtin_parseJson.jsonnet.goldendiffbeforeafterboth1{1{2 "a": -1,2 "a": -1,3 "b": 1,3 "b": 1,4 "c": 3.141,4 "c": 3.141,5 "d": [ ]5 "d": [ ]6}6}tests/golden/issue23.jsonnet.goldendiffbeforeafterboth1infinite recursion detected1infinite recursion detected2 issue23.jsonnet:1:1-26: import "issue23.jsonnet"2 issue23.jsonnet:1:1-26: import "issue23.jsonnet"tests/golden/issue40.jsonnet.goldendiffbeforeafterboth1assert failed: is number1assert failed: is number2 issue40.jsonnet:6:10-31: assertion failure2 issue40.jsonnet:6:10-31: assertion failure3 issue40.jsonnet:9:1-32: function <builtin_manifest_json_ex> call3 issue40.jsonnet:9:1-32: function <builtin_manifest_json_ex> calltests/golden/missing_binding.jsonnet.goldendiffbeforeafterboth1variable is not defined: sta1variable is not defined: sta2There is variable with similar name present: std2There is variable with similar name present: std3 missing_binding.jsonnet:1:1-5: variable <sta> access3 missing_binding.jsonnet:1:1-5: variable <sta> accesstests/golden/object_comp.jsonnet.goldendiffbeforeafterboth1{1{2 "h1_2": "0a",2 "h1_2": "0a",3 "h1_3": "0a",3 "h1_3": "0a",4 "h1_4": "0a",4 "h1_4": "0a",5 "h2_3": "a1",5 "h2_3": "a1",6 "h2_4": "a1",6 "h2_4": "a1",7 "h3_2": "0a",7 "h3_2": "0a",8 "h3_4": "a1"8 "h3_4": "a1"9}9}tests/golden/test_assertThrow.jsonnet.goldendiffbeforeafterboth1runtime error: expected argument to throw on evaluation, but it returned instead1runtime error: expected argument to throw on evaluation, but it returned instead2 test_assertThrow.jsonnet:2:1-26: function <assert_throw> call2 test_assertThrow.jsonnet:2:1-26: function <assert_throw> calltests/tests/common.rsdiffbeforeafterboth29macro_rules! ensure_val_eq {29macro_rules! ensure_val_eq {30 ($a:expr, $b:expr) => {{30 ($a:expr, $b:expr) => {{31 if !::jrsonnet_evaluator::val::equals(&$a.clone(), &$b.clone())? {31 if !::jrsonnet_evaluator::val::equals(&$a.clone(), &$b.clone())? {32 ::jrsonnet_evaluator::throw!(32 use ::jrsonnet_evaluator::stdlib::manifest::JsonFormat;33 ::jrsonnet_evaluator::throw!(33 "assertion failed: a != b\na={:#?}\nb={:#?}",34 "assertion failed: a != b\na={:#?}\nb={:#?}",34 $a.to_json(35 $a.manifest(JsonFormat::default())?,35 2,36 #[cfg(feature = "exp-preserve-order")]37 false38 )?,39 $b.to_json(36 $b.manifest(JsonFormat::default())?,40 2,41 #[cfg(feature = "exp-preserve-order")]42 false43 )?,44 )37 )45 }38 }tests/tests/golden.rsdiffbeforeafterboth4};4};556use jrsonnet_evaluator::{6use jrsonnet_evaluator::{7 stdlib::manifest::JsonFormat,7 trace::{CompactFormat, PathResolver},8 trace::{CompactFormat, PathResolver, TraceFormat},8 FileImportResolver, State,9 FileImportResolver, State,9};10};10use jrsonnet_stdlib::StateExt;11use jrsonnet_stdlib::StateExt;111212mod common;13mod common;131414fn run(root: &Path, file: &Path) -> String {15fn run(file: &Path) -> String {15 let s = State::default();16 let s = State::default();16 s.set_trace_format(CompactFormat {17 resolver: PathResolver::Relative(root.to_owned()),18 padding: 3,19 });20 s.with_stdlib();17 s.with_stdlib();21 common::with_test(&s);18 common::with_test(&s);22 s.set_import_resolver(Box::new(FileImportResolver::default()));19 s.set_import_resolver(Box::new(FileImportResolver::default()));20 let trace_format = CompactFormat {21 resolver: PathResolver::FileName,22 max_trace: 20,23 padding: 4,24 };232524 let v = match s.import(file) {26 let v = match s.import(file) {25 Ok(v) => v,27 Ok(v) => v,26 Err(e) => return s.stringify_err(&e),28 Err(e) => return trace_format.format(&e).unwrap(),27 };29 };28 match v.to_json(30 match v.manifest(29 3,31 JsonFormat::default(),30 #[cfg(feature = "exp-preserve-order")]32 #[cfg(feature = "exp-preserve-order")]31 false,33 false,32 ) {34 ) {33 Ok(v) => v.to_string(),35 Ok(v) => v.to_string(),34 Err(e) => s.stringify_err(&e),36 Err(e) => trace_format.format(&e).unwrap(),35 }37 }36}38}373946 continue;48 continue;47 }49 }485049 let result = run(&root, &entry.path());51 let result = run(&entry.path());505251 let mut golden_path = entry.path();53 let mut golden_path = entry.path();52 golden_path.set_extension("jsonnet.golden");54 golden_path.set_extension("jsonnet.golden");tests/tests/sanity.rsdiffbeforeafterboth1use jrsonnet_evaluator::{error::Result, throw, State, Val};1use jrsonnet_evaluator::{2 error::Result,3 throw,4 trace::{CompactFormat, TraceFormat},5 State, Val,6};2use jrsonnet_stdlib::StateExt;7use jrsonnet_stdlib::StateExt;3820fn assert_negative() -> Result<()> {25fn assert_negative() -> Result<()> {21 let s = State::default();26 let s = State::default();22 s.with_stdlib();27 s.with_stdlib();28 let trace_format = CompactFormat::default();232924 {30 {25 let Err(e) = s.evaluate_snippet("snip".to_owned(), "assert 1 == 2: 'fail'; null") else {31 let Err(e) = s.evaluate_snippet("snip".to_owned(), "assert 1 == 2: 'fail'; null") else {26 throw!("assertion should fail");32 throw!("assertion should fail");27 };33 };28 let e = s.stringify_err(&e);34 let e = trace_format.format(&e).unwrap();29 ensure!(e.starts_with("assert failed: fail\n"));35 ensure!(e.starts_with("assert failed: fail\n"));30 }36 }31 {37 {32 let Err(e) = s.evaluate_snippet("snip".to_owned(), "std.assertEqual(1, 2)") else {38 let Err(e) = s.evaluate_snippet("snip".to_owned(), "std.assertEqual(1, 2)") else {33 throw!("assertion should fail")39 throw!("assertion should fail")34 };40 };35 let e = s.stringify_err(&e);41 let e = trace_format.format(&e).unwrap();36 ensure!(e.starts_with("runtime error: Assertion failed. 1 != 2"))42 ensure!(e.starts_with("runtime error: Assertion failed. 1 != 2"))37 }43 }3844tests/tests/suite.rsdiffbeforeafterboth4};4};556use jrsonnet_evaluator::{6use jrsonnet_evaluator::{7 trace::{CompactFormat, PathResolver},7 trace::{CompactFormat, TraceFormat},8 FileImportResolver, State, Val,8 FileImportResolver, State, Val,9};9};10use jrsonnet_stdlib::StateExt;10use jrsonnet_stdlib::StateExt;111112mod common;12mod common;131314fn run(root: &Path, file: &Path) {14fn run(file: &Path) {15 let s = State::default();15 let s = State::default();16 s.set_trace_format(CompactFormat {17 resolver: PathResolver::Relative(root.to_owned()),18 padding: 3,19 });20 s.with_stdlib();16 s.with_stdlib();21 common::with_test(&s);17 common::with_test(&s);22 s.set_import_resolver(Box::new(FileImportResolver::default()));18 s.set_import_resolver(Box::new(FileImportResolver::default()));19 let trace_format = CompactFormat::default();232024 match s.import(file) {21 match s.import(file) {25 Ok(Val::Bool(true)) => {}22 Ok(Val::Bool(true)) => {}26 Ok(Val::Bool(false)) => panic!("test {} returned false", file.display()),23 Ok(Val::Bool(false)) => panic!("test {} returned false", file.display()),27 Ok(_) => panic!("test {} returned wrong type as result", file.display()),24 Ok(_) => panic!("test {} returned wrong type as result", file.display()),28 Err(e) => panic!("test {} failed:\n{}", file.display(), s.stringify_err(&e)),25 Err(e) => panic!(26 "test {} failed:\n{}",27 file.display(),28 trace_format.format(&e).unwrap()29 ),29 };30 };30}31}40 continue;41 continue;41 }42 }424343 run(&root, &entry.path());44 run(&entry.path());44 }45 }454646 Ok(())47 Ok(())