git.delta.rocks / jrsonnet / refs/commits / c58af2989051

difftreelog

test split tests

Yaroslav Bolyukin2022-04-22parent: #0843f20.patch.diff
in: master

45 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/format.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/format.rs
@@ -741,21 +741,51 @@
 
 	#[test]
 	fn octals() {
-		assert_eq!(format_arr("%#o", &[Val::Num(8.0)]).unwrap(), "010");
-		assert_eq!(format_arr("%#4o", &[Val::Num(8.0)]).unwrap(), " 010");
-		assert_eq!(format_arr("%4o", &[Val::Num(8.0)]).unwrap(), "  10");
-		assert_eq!(format_arr("%04o", &[Val::Num(8.0)]).unwrap(), "0010");
-		assert_eq!(format_arr("%+4o", &[Val::Num(8.0)]).unwrap(), " +10");
-		assert_eq!(format_arr("%+04o", &[Val::Num(8.0)]).unwrap(), "+010");
-		assert_eq!(format_arr("%-4o", &[Val::Num(8.0)]).unwrap(), "10  ");
-		assert_eq!(format_arr("%+-4o", &[Val::Num(8.0)]).unwrap(), "+10 ");
-		assert_eq!(format_arr("%+-04o", &[Val::Num(8.0)]).unwrap(), "+10 ");
+		let s = State::default();
+		assert_eq!(
+			format_arr(s.clone(), "%#o", &[Val::Num(8.0)]).unwrap(),
+			"010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%#4o", &[Val::Num(8.0)]).unwrap(),
+			" 010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%4o", &[Val::Num(8.0)]).unwrap(),
+			"  10"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%04o", &[Val::Num(8.0)]).unwrap(),
+			"0010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+4o", &[Val::Num(8.0)]).unwrap(),
+			" +10"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+04o", &[Val::Num(8.0)]).unwrap(),
+			"+010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%-4o", &[Val::Num(8.0)]).unwrap(),
+			"10  "
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+-4o", &[Val::Num(8.0)]).unwrap(),
+			"+10 "
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+-04o", &[Val::Num(8.0)]).unwrap(),
+			"+10 "
+		);
 	}
 
 	#[test]
 	fn percent_doesnt_consumes_values() {
+		let s = State::default();
 		assert_eq!(
 			format_arr(
+				s,
 				"How much error budget is left looking at our %.3f%% availability gurantees?",
 				&[Val::Num(4.0)]
 			)
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -381,8 +381,9 @@
 		.ext_natives
 		.get(&name)
 		.cloned()
-		.map(|v| Val::Func(FuncVal::Builtin(v.clone())))
-		.unwrap_or(Val::Null)))
+		.map_or(Val::Null, |v| {
+			Val::Func(FuncVal::Builtin(v.clone()))
+		})))
 }
 
 #[jrsonnet_macros::builtin]
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -649,608 +649,3 @@
 	assert!(weak_ptr_eq(aw1, aw2));
 	assert!(!weak_ptr_eq(aw3, bw));
 }
-
-#[cfg(test)]
-pub mod tests {
-	use std::{
-		path::{Path, PathBuf},
-		rc::Rc,
-	};
-
-	use gcmodule::{Cc, Trace};
-	use jrsonnet_parser::*;
-
-	use super::Val;
-	use crate::{
-		error::Error::*,
-		function::{BuiltinParam, CallLocation},
-		gc::TraceBox,
-		native::NativeCallbackHandler,
-		val::primitive_equals,
-		State,
-	};
-
-	#[test]
-	#[should_panic]
-	fn eval_state_stacktrace() {
-		let state = State::default();
-		state
-			.push(
-				CallLocation::new(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
-				|| "outer".to_owned(),
-				|| {
-					state.push(
-						CallLocation::new(&ExprLocation(
-							PathBuf::from("test2.jsonnet").into(),
-							30,
-							40,
-						)),
-						|| "inner".to_owned(),
-						|| Err(RuntimeError("".into()).into()),
-					)?;
-					Ok(Val::Null)
-				},
-			)
-			.unwrap();
-	}
-
-	#[test]
-	fn eval_state_standard() {
-		let state = State::default();
-		state.with_stdlib();
-		assert!(primitive_equals(
-			&state
-				.evaluate_snippet_raw(
-					PathBuf::from("raw.jsonnet").into(),
-					r#"std.assertEqual(std.base64("test"), "dGVzdA==")"#.into()
-				)
-				.unwrap(),
-			&Val::Bool(true),
-		)
-		.unwrap());
-	}
-
-	macro_rules! eval {
-		($str: expr) => {{
-			let evaluator = State::default();
-			evaluator.with_stdlib();
-			evaluator
-				.evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
-				.unwrap()
-		}};
-	}
-	macro_rules! eval_json {
-		($str: expr) => {{
-			let evaluator = State::default();
-			evaluator.with_stdlib();
-			evaluator
-				.evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
-				.unwrap()
-				.to_json(0)
-				.unwrap()
-				.replace("\n", "")
-		}};
-	}
-
-	/// Asserts given code returns `true`
-	macro_rules! assert_eval {
-		($str: expr) => {
-			assert!(primitive_equals(&eval!($str), &Val::Bool(true)).unwrap())
-		};
-	}
-
-	/// Asserts given code returns `false`
-	macro_rules! assert_eval_neg {
-		($str: expr) => {
-			assert!(primitive_equals(&eval!($str), &Val::Bool(false)).unwrap())
-		};
-	}
-	macro_rules! assert_json {
-		($str: expr, $out: expr) => {
-			assert_eq!(eval_json!($str), $out.replace("\t", ""))
-		};
-	}
-
-	/// Sanity checking, before trusting to another tests
-	#[test]
-	fn equality_operator() {
-		assert_eval!("2 == 2");
-		assert_eval_neg!("2 != 2");
-		assert_eval!("2 != 3");
-		assert_eval_neg!("2 == 3");
-		assert_eval!("'Hello' == 'Hello'");
-		assert_eval_neg!("'Hello' != 'Hello'");
-		assert_eval!("'Hello' != 'World'");
-		assert_eval_neg!("'Hello' == 'World'");
-	}
-
-	#[test]
-	fn math_evaluation() {
-		assert_eval!("2 + 2 * 2 == 6");
-		assert_eval!("3 + (2 + 2 * 2) == 9");
-	}
-
-	#[test]
-	fn string_concat() {
-		assert_eval!("'Hello' + 'World' == 'HelloWorld'");
-		assert_eval!("'Hello' * 3 == 'HelloHelloHello'");
-		assert_eval!("'Hello' + 'World' * 3 == 'HelloWorldWorldWorld'");
-	}
-
-	#[test]
-	fn faster_join() {
-		assert_eval!("std.join([0,0], [[1,2],[3,4],[5,6]]) == [1,2,0,0,3,4,0,0,5,6]");
-		assert_eval!("std.join(',', ['1','2','3','4']) == '1,2,3,4'");
-	}
-
-	#[test]
-	fn function_contexts() {
-		assert_eval!(
-			r#"
-				local k = {
-					t(name = self.h): [self.h, name],
-					h: 3,
-				};
-				local f = {
-					t: k.t(),
-					h: 4,
-				};
-				f.t[0] == f.t[1]
-			"#
-		);
-	}
-
-	#[test]
-	fn local() {
-		assert_eval!("local a = 2; local b = 3; a + b == 5");
-		assert_eval!("local a = 1, b = a + 1; a + b == 3");
-		assert_eval!("local a = 1; local a = 2; a == 2");
-	}
-
-	#[test]
-	fn object_lazyness() {
-		assert_json!("local a = {a:error 'test'}; {}", r#"{}"#);
-	}
-
-	#[test]
-	fn object_inheritance() {
-		assert_json!("{a: self.b} + {b:3}", r#"{"a": 3,"b": 3}"#);
-	}
-
-	#[test]
-	fn object_assertion_success() {
-		eval!("{assert \"a\" in self} + {a:2}");
-	}
-
-	#[test]
-	fn object_assertion_error() {
-		eval!("{assert \"a\" in self}");
-	}
-
-	#[test]
-	fn lazy_args() {
-		eval!("local test(a) = 2; test(error '3')");
-	}
-
-	#[test]
-	#[should_panic]
-	fn tailstrict_args() {
-		eval!("local test(a) = 2; test(error '3') tailstrict");
-	}
-
-	#[test]
-	#[should_panic]
-	fn no_binding_error() {
-		eval!("a");
-	}
-
-	#[test]
-	fn test_object() {
-		assert_json!("{a:2}", r#"{"a": 2}"#);
-		assert_json!("{a:2+2}", r#"{"a": 4}"#);
-		assert_json!("{a:2}+{b:2}", r#"{"a": 2,"b": 2}"#);
-		assert_json!("{b:3}+{b:2}", r#"{"b": 2}"#);
-		assert_json!("{b:3}+{b+:2}", r#"{"b": 5}"#);
-		assert_json!("local test='a'; {[test]:2}", r#"{"a": 2}"#);
-		assert_json!(
-			r#"
-				{
-					name: "Alice",
-					welcome: "Hello " + self.name + "!",
-				}
-			"#,
-			r#"{"name": "Alice","welcome": "Hello Alice!"}"#
-		);
-		assert_json!(
-			r#"
-				{
-					name: "Alice",
-					welcome: "Hello " + self.name + "!",
-				} + {
-					name: "Bob"
-				}
-			"#,
-			r#"{"name": "Bob","welcome": "Hello Bob!"}"#
-		);
-	}
-
-	#[test]
-	fn functions() {
-		assert_json!(r#"local a = function(b, c = 2) b + c; a(2)"#, "4");
-		assert_json!(
-			r#"local a = function(b, c = "Dear") b + c + d, d = "World"; a("Hello")"#,
-			r#""HelloDearWorld""#
-		);
-	}
-
-	#[test]
-	fn local_methods() {
-		assert_json!(r#"local a(b, c = 2) = b + c; a(2)"#, "4");
-		assert_json!(
-			r#"local a(b, c = "Dear") = b + c + d, d = "World"; a("Hello")"#,
-			r#""HelloDearWorld""#
-		);
-	}
-
-	#[test]
-	fn object_locals() {
-		assert_json!(r#"{local a = 3, b: a}"#, r#"{"b": 3}"#);
-		assert_json!(r#"{local a = 3, local c = a, b: c}"#, r#"{"b": 3}"#);
-		assert_json!(
-			r#"{local a = function (b) {[b]:4}, test: a("test")}"#,
-			r#"{"test": {"test": 4}}"#
-		);
-	}
-
-	#[test]
-	fn object_comp() {
-		assert_json!(
-			r#"{local t = "a", ["h"+i+"_"+z]: if "h"+(i-1)+"_"+z in self then t+1 else 0+t for i in [1,2,3] for z in [2,3,4] if z != i}"#,
-			"{\"h1_2\": \"0a\",\"h1_3\": \"0a\",\"h1_4\": \"0a\",\"h2_3\": \"a1\",\"h2_4\": \"a1\",\"h3_2\": \"0a\",\"h3_4\": \"a1\"}"
-		)
-	}
-
-	#[test]
-	fn direct_self() {
-		println!(
-			"{:#?}",
-			eval!(
-				r#"
-					{
-						local me = self,
-						a: 3,
-						b(): me.a,
-					}
-				"#
-			)
-		);
-	}
-
-	#[test]
-	fn indirect_self() {
-		// `self` assigned to `me` was lost when being
-		// referenced from field
-		eval!(
-			r#"{
-				local me = self,
-				a: 3,
-				b: me.a,
-			}.b"#
-		);
-	}
-
-	// We can't trust other tests (And official jsonnet testsuite), if assert is not working correctly
-	#[test]
-	fn std_assert_ok() {
-		eval!("std.assertEqual(4.5 << 2, 16)");
-	}
-
-	#[test]
-	#[should_panic]
-	fn std_assert_failure() {
-		eval!("std.assertEqual(4.5 << 2, 15)");
-	}
-
-	#[test]
-	fn string_is_string() {
-		assert!(primitive_equals(
-			&eval!("local arr = 'hello'; (!std.isArray(arr)) && (!std.isString(arr))"),
-			&Val::Bool(false),
-		)
-		.unwrap());
-	}
-
-	#[test]
-	fn base64_works() {
-		assert_json!(r#"std.base64("test")"#, r#""dGVzdA==""#);
-	}
-
-	#[test]
-	fn utf8_chars() {
-		assert_json!(
-			r#"local c="😎";{c:std.codepoint(c),l:std.length(c)}"#,
-			r#"{"c": 128526,"l": 1}"#
-		)
-	}
-
-	#[test]
-	fn json() {
-		assert_json!(
-			r#"std.manifestJsonEx({a:3, b:4, c:6},"")"#,
-			r#""{\n\"a\": 3,\n\"b\": 4,\n\"c\": 6\n}""#
-		);
-	}
-
-	#[test]
-	fn json_minified() {
-		assert_json!(
-			r#"std.manifestJsonMinified({a:3, b:4, c:6})"#,
-			r#""{\"a\":3,\"b\":4,\"c\":6}""#
-		);
-	}
-
-	#[test]
-	fn parse_json() {
-		assert_json!(
-			r#"std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')"#,
-			r#"{"a": -1,"b": 1,"c": 3.141,"d": []}"#
-		);
-	}
-
-	#[test]
-	fn test() {
-		assert_json!(
-			r#"[[a, b] for a in [1,2,3] for b in [4,5,6]]"#,
-			"[[1,4],[1,5],[1,6],[2,4],[2,5],[2,6],[3,4],[3,5],[3,6]]"
-		);
-	}
-
-	#[test]
-	fn sjsonnet() {
-		eval!(
-			r#"
-			local x0 = {k: 1};
-			local x1 = {k: x0.k + x0.k};
-			local x2 = {k: x1.k + x1.k};
-			local x3 = {k: x2.k + x2.k};
-			local x4 = {k: x3.k + x3.k};
-			local x5 = {k: x4.k + x4.k};
-			local x6 = {k: x5.k + x5.k};
-			local x7 = {k: x6.k + x6.k};
-			local x8 = {k: x7.k + x7.k};
-			local x9 = {k: x8.k + x8.k};
-			local x10 = {k: x9.k + x9.k};
-			local x11 = {k: x10.k + x10.k};
-			local x12 = {k: x11.k + x11.k};
-			local x13 = {k: x12.k + x12.k};
-			local x14 = {k: x13.k + x13.k};
-			local x15 = {k: x14.k + x14.k};
-			local x16 = {k: x15.k + x15.k};
-			local x17 = {k: x16.k + x16.k};
-			local x18 = {k: x17.k + x17.k};
-			local x19 = {k: x18.k + x18.k};
-			local x20 = {k: x19.k + x19.k};
-			local x21 = {k: x20.k + x20.k};
-			x21.k
-		"#
-		);
-	}
-
-	// This test is commented out by default, because of huge compilation slowdown
-	// #[bench]
-	// fn bench_codegen(b: &mut Bencher) {
-	// 	b.iter(|| {
-	// 		#[allow(clippy::all)]
-	// 		let stdlib = {
-	// 			use jrsonnet_parser::*;
-	// 			include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
-	// 		};
-	// 		stdlib
-	// 	})
-	// }
-
-	/*
-	#[bench]
-	fn bench_serialize(b: &mut Bencher) {
-		b.iter(|| {
-			bincode::deserialize::<jrsonnet_parser::LocExpr>(include_bytes!(concat!(
-				env!("OUT_DIR"),
-				"/stdlib.bincode"
-			)))
-			.expect("deserialize stdlib")
-		})
-	}
-
-	#[bench]
-	fn bench_parse(b: &mut Bencher) {
-		b.iter(|| {
-			jrsonnet_parser::parse(
-				jrsonnet_stdlib::STDLIB_STR,
-				&jrsonnet_parser::ParserSettings {
-					loc_data: true,
-					file_name: Rc::new(PathBuf::from("std.jsonnet")),
-				},
-			)
-		})
-	}
-	*/
-
-	#[test]
-	fn equality() {
-		println!(
-			"{:?}",
-			jrsonnet_parser::parse(
-				"{ x: 1, y: 2 } == { x: 1, y: 2 }",
-				&ParserSettings {
-					file_name: PathBuf::from("equality").into(),
-				}
-			)
-		);
-		assert_eval!("{ x: 1, y: 2 } == { x: 1, y: 2 }")
-	}
-
-	#[test]
-	fn native_ext() -> crate::error::Result<()> {
-		use super::native::NativeCallback;
-		let evaluator = State::default();
-
-		evaluator.with_stdlib();
-
-		#[derive(Trace)]
-		struct NativeAdd;
-		impl NativeCallbackHandler for NativeAdd {
-			fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> crate::error::Result<Val> {
-				assert_eq!(
-					&from.unwrap() as &Path,
-					&PathBuf::from("native_caller.jsonnet")
-				);
-				match (&args[0], &args[1]) {
-					(Val::Num(a), Val::Num(b)) => Ok(Val::Num(a + b)),
-					(_, _) => unreachable!(),
-				}
-			}
-		}
-		evaluator.settings_mut().ext_natives.insert(
-			"native_add".into(),
-			#[allow(deprecated)]
-			Cc::new(TraceBox(Box::new(NativeCallback::new(
-				vec![
-					BuiltinParam {
-						name: "a".into(),
-						has_default: false,
-					},
-					BuiltinParam {
-						name: "b".into(),
-						has_default: false,
-					},
-				],
-				TraceBox(Box::new(NativeAdd)),
-			)))),
-		);
-		dbg!(evaluator.settings().ext_natives.keys().collect::<Vec<_>>());
-		evaluator.evaluate_snippet_raw(
-			PathBuf::from("native_caller.jsonnet").into(),
-			"std.assertEqual(std.native(\"native_add\")(1, 2), 3)".into(),
-		)?;
-		dbg!(evaluator.settings().ext_natives.keys().collect::<Vec<_>>());
-		Ok(())
-	}
-
-	#[test]
-	fn constant_intrinsic() -> crate::error::Result<()> {
-		assert_eval!(
-			"local std2 = std; local std = std2 { primitiveEquals(a, b):: false }; 1 == 1"
-		);
-		Ok(())
-	}
-
-	#[test]
-	fn standalone_super() -> crate::error::Result<()> {
-		assert_eval!(
-			r#"
-			local obj = {
-				a: 1,
-				b: 2,
-				c: 3,
-			};
-			local test = obj + {
-				fields: std.objectFields(super),
-				d: 5,
-			};
-			test.fields == ['a', 'b', 'c']
-		"#
-		);
-		Ok(())
-	}
-
-	#[test]
-	fn comp_self() -> crate::error::Result<()> {
-		assert_eval!(
-			r#"
-			std.objectFields({
-				a:{
-					[name]: name for name in std.objectFields(self)
-				},
-				b: 2,
-				c: 3,
-			}.a) == ['a', 'b', 'c']
-			"#
-		);
-
-		Ok(())
-	}
-
-	struct TestImportResolver(Vec<u8>);
-	impl crate::import::ImportResolver for TestImportResolver {
-		fn resolve_file(&self, _: &Path, _: &Path) -> crate::error::Result<Rc<Path>> {
-			Ok(PathBuf::from("/test").into())
-		}
-
-		fn load_file_contents(&self, _: &Path) -> crate::error::Result<Vec<u8>> {
-			Ok(self.0.clone())
-		}
-
-		unsafe fn as_any(&self) -> &dyn std::any::Any {
-			panic!()
-		}
-
-		fn load_file_bin(&self, _resolved: &Path) -> crate::error::Result<Rc<[u8]>> {
-			panic!()
-		}
-	}
-
-	#[test]
-	fn issue_23() {
-		let state = State::default();
-		state.set_import_resolver(Box::new(TestImportResolver(r#"import "/test""#.into())));
-		let _ = state.evaluate_file_raw(&PathBuf::from("/test"));
-	}
-
-	#[test]
-	fn issue_40() {
-		let state = State::default();
-		state.with_stdlib();
-
-		let error = state
-			.evaluate_snippet_raw(
-				PathBuf::from("issue40.jsonnet").into(),
-				r#"
-				local conf = {
-					n: ""
-				};
-
-				local result = conf + {
-					assert std.isNumber(self.n): "is number"
-				};
-
-				std.manifestJsonEx(result, "")
-			"#
-				.into(),
-			)
-			.unwrap_err();
-		assert_eq!(error.error().to_string(), "assert failed: is number");
-	}
-
-	#[test]
-	fn test_ascii_upper_lower() {
-		assert_eval!(r#"std.assertEqual(std.asciiUpper("aBc😀"), "ABC😀")"#);
-		assert_eval!(r#"std.assertEqual(std.asciiLower("aBc😀"), "abc😀")"#);
-	}
-
-	#[test]
-	fn test_member() {
-		assert_eval!(r#"!std.member("", "")"#);
-		assert_eval!(r#"std.member("abc", "a")"#);
-		assert_eval!(r#"!std.member("abc", "d")"#);
-		assert_eval!(r#"!std.member([], "")"#);
-		assert_eval!(r#"std.member(["a", "b", "c"], "a")"#);
-		assert_eval!(r#"!std.member(["a", "b", "c"], "d")"#);
-	}
-
-	#[test]
-	fn test_count() {
-		assert_eval!(r#"std.assertEqual(std.count([], ""), 0)"#);
-		assert_eval!(r#"std.assertEqual(std.count(["a", "b", "a"], "d"), 0)"#);
-		assert_eval!(r#"std.assertEqual(std.count(["a", "b", "a"], "a"), 2)"#);
-	}
-}
modifiedcrates/jrsonnet-evaluator/tests/common.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/tests/common.rs
+++ b/crates/jrsonnet-evaluator/tests/common.rs
@@ -1,3 +1,8 @@
+use jrsonnet_evaluator::{
+	error::Result, function::builtin, throw_runtime, val::FuncVal, LazyVal, ObjValueBuilder, State,
+	Val,
+};
+
 #[macro_export]
 macro_rules! ensure_eq {
 	($a:expr, $b:expr $(,)?) => {{
@@ -32,3 +37,33 @@
 		}
 	}};
 }
+
+#[builtin]
+fn assert_throw(s: State, lazy: LazyVal, message: String) -> Result<bool> {
+	match lazy.evaluate(s) {
+		Ok(_) => {
+			throw_runtime!("expected argument to throw on evaluation, but it returned instead")
+		}
+		Err(e) => {
+			let error = format!("{}", e.error());
+			ensure_eq!(message, error);
+		}
+	}
+	Ok(true)
+}
+
+#[allow(dead_code)]
+pub fn with_test(s: &State) {
+	let mut bobj = ObjValueBuilder::new();
+	bobj.member("assertThrow".into())
+		.hide()
+		.value(
+			s.clone(),
+			Val::Func(FuncVal::StaticBuiltin(assert_throw::INST)),
+		)
+		.expect("no error");
+
+	s.settings_mut()
+		.globals
+		.insert("test".into(), Val::Obj(bobj.build()));
+}
addedcrates/jrsonnet-evaluator/tests/golden.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden.rs
@@ -0,0 +1,64 @@
+use std::{
+	fs, io,
+	path::{Path, PathBuf},
+};
+
+use jrsonnet_evaluator::{
+	trace::{CompactFormat, PathResolver},
+	FileImportResolver, State,
+};
+
+mod common;
+
+fn run(root: &Path, file: &Path) -> String {
+	let s = State::default();
+	s.set_trace_format(Box::new(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 v = match s.evaluate_file_raw(file) {
+		Ok(v) => v,
+		Err(e) => return s.stringify_err(&e),
+	};
+	match v.to_json(s.clone(), 3) {
+		Ok(v) => v.to_string(),
+		Err(e) => s.stringify_err(&e),
+	}
+}
+
+#[test]
+fn test() -> io::Result<()> {
+	let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+	root.push("tests/golden");
+
+	for entry in fs::read_dir(&root)? {
+		let entry = entry?;
+		if !entry.path().extension().map_or(false, |e| e == "jsonnet") {
+			continue;
+		}
+
+		let result = run(&root, &entry.path());
+
+		let mut golden_path = entry.path();
+		golden_path.set_extension("jsonnet.golden");
+
+		if !golden_path.exists() {
+			fs::write(golden_path, &result)?;
+		} else {
+			let golden = fs::read_to_string(golden_path)?;
+
+			assert_eq!(
+				result,
+				golden,
+				"golden didn't match for {}",
+				entry.path().display()
+			)
+		}
+	}
+
+	Ok(())
+}
addedcrates/jrsonnet-evaluator/tests/golden/array_comp.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/array_comp.jsonnet
@@ -0,0 +1 @@
+[[a, b] for a in [1, 2, 3] for b in [4, 5, 6]]
addedcrates/jrsonnet-evaluator/tests/golden/array_comp.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/array_comp.jsonnet.golden
@@ -0,0 +1,38 @@
+[
+   [
+      1,
+      4
+   ],
+   [
+      1,
+      5
+   ],
+   [
+      1,
+      6
+   ],
+   [
+      2,
+      4
+   ],
+   [
+      2,
+      5
+   ],
+   [
+      2,
+      6
+   ],
+   [
+      3,
+      4
+   ],
+   [
+      3,
+      5
+   ],
+   [
+      3,
+      6
+   ]
+]
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnet
@@ -0,0 +1 @@
+std.manifestJsonEx({ a: 3, b: 4, c: 6 }, '')
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnet.golden
@@ -0,0 +1 @@
+"{\n\"a\": 3,\n\"b\": 4,\n\"c\": 6\n}"
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnet
@@ -0,0 +1 @@
+std.manifestJsonMinified({ a: 3, b: 4, c: 6 })
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnet.golden
@@ -0,0 +1 @@
+"{\"a\":3,\"b\":4,\"c\":6}"
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnet
@@ -0,0 +1 @@
+std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')
addedcrates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnet.golden
@@ -0,0 +1,6 @@
+{
+   "a": -1,
+   "b": 1,
+   "c": 3.141,
+   "d": [ ]
+}
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/issue23.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue23.jsonnet
@@ -0,0 +1 @@
+import 'issue23.jsonnet'
addedcrates/jrsonnet-evaluator/tests/golden/issue23.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue23.jsonnet.golden
@@ -0,0 +1,202 @@
+stack overflow, try to reduce recursion, or set --max-stack to bigger value
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/issue40.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue40.jsonnet
@@ -0,0 +1,9 @@
+local conf = {
+  n: '',
+};
+
+local result = conf {
+  assert std.isNumber(self.n) : 'is number',
+};
+
+std.manifestJsonEx(result, '')
addedcrates/jrsonnet-evaluator/tests/golden/issue40.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue40.jsonnet.golden
@@ -0,0 +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
addedcrates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnet
@@ -0,0 +1 @@
+a
addedcrates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnet.golden
@@ -0,0 +1,2 @@
+variable is not defined: a
+   missing_binding.jsonnet:1:1-3: variable <a> access
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/object_comp.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/object_comp.jsonnet
@@ -0,0 +1 @@
+{ local t = 'a', ['h' + i + '_' + z]: if 'h' + (i - 1) + '_' + z in self then t + 1 else 0 + t for i in [1, 2, 3] for z in [2, 3, 4] if z != i }
addedcrates/jrsonnet-evaluator/tests/golden/object_comp.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/object_comp.jsonnet.golden
@@ -0,0 +1,9 @@
+{
+   "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
addedcrates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnet
@@ -0,0 +1,2 @@
+// Test that test.assertThrow will return error, if body is not errored
+test.assertThrow(1, '1')
addedcrates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnet.golden
@@ -0,0 +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
addedcrates/jrsonnet-evaluator/tests/suite.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite.rs
@@ -0,0 +1,46 @@
+use std::{
+	fs, io,
+	path::{Path, PathBuf},
+};
+
+use jrsonnet_evaluator::{
+	trace::{CompactFormat, PathResolver},
+	FileImportResolver, State, Val,
+};
+
+mod common;
+
+fn run(root: &Path, file: &Path) {
+	let s = State::default();
+	s.set_trace_format(Box::new(CompactFormat {
+		resolver: PathResolver::Relative(root.to_owned()),
+		padding: 3,
+	}));
+	s.with_stdlib();
+	common::with_test(&s);
+	s.set_import_resolver(Box::new(FileImportResolver::default()));
+
+	match s.evaluate_file_raw(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)),
+	};
+}
+
+#[test]
+fn test() -> io::Result<()> {
+	let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+	root.push("tests/suite");
+
+	for entry in fs::read_dir(&root)? {
+		let entry = entry?;
+		if !entry.path().extension().map_or(false, |e| e == "jsonnet") {
+			continue;
+		}
+
+		run(&root, &entry.path());
+	}
+
+	Ok(())
+}
addedcrates/jrsonnet-evaluator/tests/suite/builtin_ascii.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_ascii.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual(std.asciiUpper('aBc😀'), 'ABC😀') &&
+std.assertEqual(std.asciiLower('aBc😀'), 'abc😀') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_base64.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_base64.jsonnet
@@ -0,0 +1,2 @@
+std.assertEqual(std.base64('test'), 'dGVzdA==') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_chars.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_chars.jsonnet
@@ -0,0 +1,3 @@
+local c = '😎';
+std.assertEqual({ c: std.codepoint(c), l: std.length(c) }, { c: 128526, l: 1 }) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_constant.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_constant.jsonnet
@@ -0,0 +1,3 @@
+local std2 = std; local std = std2 { primitiveEquals(a, b):: false };
+// In jsonnet, this expression was failing because of being desugared to std.primitiveEquals(1, 1)
+std.assertEqual(1 == 1, true)
addedcrates/jrsonnet-evaluator/tests/suite/builtin_count.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_count.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual(std.count([], ''), 0) &&
+std.assertEqual(std.count(['a', 'b', 'a'], 'd'), 0) &&
+std.assertEqual(std.count(['a', 'b', 'a'], 'a'), 2) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_join.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_join.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual(std.join([0, 0], [[1, 2], [3, 4], [5, 6]]), [1, 2, 0, 0, 3, 4, 0, 0, 5, 6]) &&
+std.assertEqual(std.join(',', ['1', '2', '3', '4']), '1,2,3,4') &&
+std.assertEqual(std.join(',', ['1', null, '2', null, '3']), '1,2,3') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_member.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_member.jsonnet
@@ -0,0 +1,7 @@
+!std.member('', '') &&
+std.member('abc', 'a') &&
+!std.member('abc', 'd') &&
+!std.member([], '') &&
+std.member(['a', 'b', 'c'], 'a') &&
+!std.member(['a', 'b', 'c'], 'd') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/function_args.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/function_args.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual(local a = function(b, c=2) b + c; a(2), 4) &&
+std.assertEqual(local a = function(b, c='Dear') b + c + d, d = 'World'; a('Hello'), 'HelloDearWorld') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/function_context.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/function_context.jsonnet
@@ -0,0 +1,10 @@
+local k = {
+  t(name=self.h): [self.h, name],
+  h: 3,
+};
+local f = {
+  t: k.t(),
+  h: 4,
+};
+std.assertEqual(f.t[0], f.t[1]) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/function_lazy_args.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/function_lazy_args.jsonnet
@@ -0,0 +1,5 @@
+local fun(a) = 2;
+std.assertEqual(fun(error '3'), 2) &&
+// But in tailstrict mode arguments are evaluated eagerly
+test.assertThrow(fun(error '3') tailstrict, 'runtime error: 3') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/local.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/local.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual(local a = 2; local b = 3; a + b, 5) &&
+std.assertEqual(local a = 1, b = a + 1; a + b, 3) &&
+std.assertEqual(local a = 1; local a = 2; a, 2) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/math.jsonnetdiffbeforeafterboth

no changes

addedcrates/jrsonnet-evaluator/tests/suite/object_assertion.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_assertion.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual({ assert 'a' in self : 'missing a' } + { a: 2 }, { a: 2 }) &&
+test.assertThrow({ assert 'a' in self : 'missing a', b: 1 }.b, 'assert failed: missing a') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_comp_self.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_comp_self.jsonnet
@@ -0,0 +1,8 @@
+std.assertEqual(std.objectFields({
+  a: {
+    [name]: name
+    for name in std.objectFields(self)
+  },
+  b: 2,
+  c: 3,
+}.a), ['a', 'b', 'c'])
addedcrates/jrsonnet-evaluator/tests/suite/object_context.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_context.jsonnet
@@ -0,0 +1,13 @@
+// `self` assigned to `me` was lost when being
+// referenced from field
+std.assertEqual({
+  local me = self,
+  a: 3,
+  b: me.a,
+}.b, 3) &&
+std.assertEqual({
+  local me = self,
+  a: 3,
+  b(): me.a,
+}.b(), 3) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_fields.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_fields.jsonnet
@@ -0,0 +1,4 @@
+local a = 'a', b = null;
+std.assertEqual({ [a]: 2 }, { a: 2 }) &&
+std.assertEqual({ [b]: 2 }, {}) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_inheritance.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_inheritance.jsonnet
@@ -0,0 +1,17 @@
+std.assertEqual({ a: self.b } + { b: 3 }, { a: 3, b: 3 }) &&
+std.assertEqual(
+  {
+    name: 'Alice',
+    welcome: 'Hello ' + self.name + '!',
+  },
+  { name: 'Alice', welcome: 'Hello Alice!' },
+) &&
+std.assertEqual(
+  {
+    name: 'Alice',
+    welcome: 'Hello ' + self.name + '!',
+  } + {
+    name: 'Bob',
+  }, { name: 'Bob', welcome: 'Hello Bob!' }
+) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_locals.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_locals.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual({ local a = 3, b: a }, { b: 3 }) &&
+std.assertEqual({ local a = 3, local c = a, b: c }, { b: 3 }) &&
+std.assertEqual({ local a = function(b) { [b]: 4 }, test: a('test') }, { test: { test: 4 } }) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_super_standalone.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_super_standalone.jsonnet
@@ -0,0 +1,11 @@
+local obj = {
+  a: 1,
+  b: 2,
+  c: 3,
+};
+local test = obj + {
+  fields: std.objectFields(super),
+  d: 5,
+};
+std.assertEqual(test.fields, ['a', 'b', 'c']) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/string_concat.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/string_concat.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual('Hello' + 'World', 'HelloWorld') &&
+std.assertEqual('Hello' * 3, 'HelloHelloHello') &&
+std.assertEqual('Hello' + 'World' * 3, 'HelloWorldWorldWorld') &&
+true
modifiedcrates/jrsonnet-evaluator/tests/typed_obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/tests/typed_obj.rs
+++ b/crates/jrsonnet-evaluator/tests/typed_obj.rs
@@ -51,7 +51,7 @@
 	ensure_eq!(b, B { a: 1, b: 2 });
 	ensure_eq!(
 		&B::into_untyped(b.clone(), s.clone())?.to_string(s.clone())? as &str,
-		"{a: 1, c: 2}",
+		r#"{"a": 1, "c": 2}"#,
 	);
 	test_roundtrip(b.clone(), s.clone())?;
 	Ok(())