From b02db2da077be6200fa019fcfb536fb3e62d9d4e Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 09 Nov 2022 23:35:38 +0000 Subject: [PATCH] test: upgrade tests to new apis --- --- 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 --- 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 --- 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 --- 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 call \ No newline at end of file + issue40.jsonnet:6:10-31: assertion failure + issue40.jsonnet:9:1-32: function call \ No newline at end of file --- 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 access \ No newline at end of file + missing_binding.jsonnet:1:1-5: variable access \ No newline at end of file --- 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 --- 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 call \ No newline at end of file + test_assertThrow.jsonnet:2:1-26: function call \ No newline at end of file --- a/tests/tests/common.rs +++ b/tests/tests/common.rs @@ -29,18 +29,11 @@ macro_rules! ensure_val_eq { ($a:expr, $b:expr) => {{ if !::jrsonnet_evaluator::val::equals(&$a.clone(), &$b.clone())? { + use ::jrsonnet_evaluator::stdlib::manifest::JsonFormat; ::jrsonnet_evaluator::throw!( "assertion failed: a != b\na={:#?}\nb={:#?}", - $a.to_json( - 2, - #[cfg(feature = "exp-preserve-order")] - false - )?, - $b.to_json( - 2, - #[cfg(feature = "exp-preserve-order")] - false - )?, + $a.manifest(JsonFormat::default())?, + $b.manifest(JsonFormat::default())?, ) } }}; --- 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"); --- 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")) } --- 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(()) -- gitstuff