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
650 assert!(!weak_ptr_eq(aw3, bw));650 assert!(!weak_ptr_eq(aw3, bw));
651}651}
652
653#[cfg(test)]
654pub mod tests {
655 use std::{
656 path::{Path, PathBuf},
657 rc::Rc,
658 };
659
660 use gcmodule::{Cc, Trace};
661 use jrsonnet_parser::*;
662
663 use super::Val;
664 use crate::{
665 error::Error::*,
666 function::{BuiltinParam, CallLocation},
667 gc::TraceBox,
668 native::NativeCallbackHandler,
669 val::primitive_equals,
670 State,
671 };
672
673 #[test]
674 #[should_panic]
675 fn eval_state_stacktrace() {
676 let state = State::default();
677 state
678 .push(
679 CallLocation::new(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
680 || "outer".to_owned(),
681 || {
682 state.push(
683 CallLocation::new(&ExprLocation(
684 PathBuf::from("test2.jsonnet").into(),
685 30,
686 40,
687 )),
688 || "inner".to_owned(),
689 || Err(RuntimeError("".into()).into()),
690 )?;
691 Ok(Val::Null)
692 },
693 )
694 .unwrap();
695 }
696
697 #[test]
698 fn eval_state_standard() {
699 let state = State::default();
700 state.with_stdlib();
701 assert!(primitive_equals(
702 &state
703 .evaluate_snippet_raw(
704 PathBuf::from("raw.jsonnet").into(),
705 r#"std.assertEqual(std.base64("test"), "dGVzdA==")"#.into()
706 )
707 .unwrap(),
708 &Val::Bool(true),
709 )
710 .unwrap());
711 }
712
713 macro_rules! eval {
714 ($str: expr) => {{
715 let evaluator = State::default();
716 evaluator.with_stdlib();
717 evaluator
718 .evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
719 .unwrap()
720 }};
721 }
722 macro_rules! eval_json {
723 ($str: expr) => {{
724 let evaluator = State::default();
725 evaluator.with_stdlib();
726 evaluator
727 .evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
728 .unwrap()
729 .to_json(0)
730 .unwrap()
731 .replace("\n", "")
732 }};
733 }
734
735 /// Asserts given code returns `true`
736 macro_rules! assert_eval {
737 ($str: expr) => {
738 assert!(primitive_equals(&eval!($str), &Val::Bool(true)).unwrap())
739 };
740 }
741
742 /// Asserts given code returns `false`
743 macro_rules! assert_eval_neg {
744 ($str: expr) => {
745 assert!(primitive_equals(&eval!($str), &Val::Bool(false)).unwrap())
746 };
747 }
748 macro_rules! assert_json {
749 ($str: expr, $out: expr) => {
750 assert_eq!(eval_json!($str), $out.replace("\t", ""))
751 };
752 }
753
754 /// Sanity checking, before trusting to another tests
755 #[test]
756 fn equality_operator() {
757 assert_eval!("2 == 2");
758 assert_eval_neg!("2 != 2");
759 assert_eval!("2 != 3");
760 assert_eval_neg!("2 == 3");
761 assert_eval!("'Hello' == 'Hello'");
762 assert_eval_neg!("'Hello' != 'Hello'");
763 assert_eval!("'Hello' != 'World'");
764 assert_eval_neg!("'Hello' == 'World'");
765 }
766
767 #[test]
768 fn math_evaluation() {
769 assert_eval!("2 + 2 * 2 == 6");
770 assert_eval!("3 + (2 + 2 * 2) == 9");
771 }
772
773 #[test]
774 fn string_concat() {
775 assert_eval!("'Hello' + 'World' == 'HelloWorld'");
776 assert_eval!("'Hello' * 3 == 'HelloHelloHello'");
777 assert_eval!("'Hello' + 'World' * 3 == 'HelloWorldWorldWorld'");
778 }
779
780 #[test]
781 fn faster_join() {
782 assert_eval!("std.join([0,0], [[1,2],[3,4],[5,6]]) == [1,2,0,0,3,4,0,0,5,6]");
783 assert_eval!("std.join(',', ['1','2','3','4']) == '1,2,3,4'");
784 }
785
786 #[test]
787 fn function_contexts() {
788 assert_eval!(
789 r#"
790 local k = {
791 t(name = self.h): [self.h, name],
792 h: 3,
793 };
794 local f = {
795 t: k.t(),
796 h: 4,
797 };
798 f.t[0] == f.t[1]
799 "#
800 );
801 }
802
803 #[test]
804 fn local() {
805 assert_eval!("local a = 2; local b = 3; a + b == 5");
806 assert_eval!("local a = 1, b = a + 1; a + b == 3");
807 assert_eval!("local a = 1; local a = 2; a == 2");
808 }
809
810 #[test]
811 fn object_lazyness() {
812 assert_json!("local a = {a:error 'test'}; {}", r#"{}"#);
813 }
814
815 #[test]
816 fn object_inheritance() {
817 assert_json!("{a: self.b} + {b:3}", r#"{"a": 3,"b": 3}"#);
818 }
819
820 #[test]
821 fn object_assertion_success() {
822 eval!("{assert \"a\" in self} + {a:2}");
823 }
824
825 #[test]
826 fn object_assertion_error() {
827 eval!("{assert \"a\" in self}");
828 }
829
830 #[test]
831 fn lazy_args() {
832 eval!("local test(a) = 2; test(error '3')");
833 }
834
835 #[test]
836 #[should_panic]
837 fn tailstrict_args() {
838 eval!("local test(a) = 2; test(error '3') tailstrict");
839 }
840
841 #[test]
842 #[should_panic]
843 fn no_binding_error() {
844 eval!("a");
845 }
846
847 #[test]
848 fn test_object() {
849 assert_json!("{a:2}", r#"{"a": 2}"#);
850 assert_json!("{a:2+2}", r#"{"a": 4}"#);
851 assert_json!("{a:2}+{b:2}", r#"{"a": 2,"b": 2}"#);
852 assert_json!("{b:3}+{b:2}", r#"{"b": 2}"#);
853 assert_json!("{b:3}+{b+:2}", r#"{"b": 5}"#);
854 assert_json!("local test='a'; {[test]:2}", r#"{"a": 2}"#);
855 assert_json!(
856 r#"
857 {
858 name: "Alice",
859 welcome: "Hello " + self.name + "!",
860 }
861 "#,
862 r#"{"name": "Alice","welcome": "Hello Alice!"}"#
863 );
864 assert_json!(
865 r#"
866 {
867 name: "Alice",
868 welcome: "Hello " + self.name + "!",
869 } + {
870 name: "Bob"
871 }
872 "#,
873 r#"{"name": "Bob","welcome": "Hello Bob!"}"#
874 );
875 }
876
877 #[test]
878 fn functions() {
879 assert_json!(r#"local a = function(b, c = 2) b + c; a(2)"#, "4");
880 assert_json!(
881 r#"local a = function(b, c = "Dear") b + c + d, d = "World"; a("Hello")"#,
882 r#""HelloDearWorld""#
883 );
884 }
885
886 #[test]
887 fn local_methods() {
888 assert_json!(r#"local a(b, c = 2) = b + c; a(2)"#, "4");
889 assert_json!(
890 r#"local a(b, c = "Dear") = b + c + d, d = "World"; a("Hello")"#,
891 r#""HelloDearWorld""#
892 );
893 }
894
895 #[test]
896 fn object_locals() {
897 assert_json!(r#"{local a = 3, b: a}"#, r#"{"b": 3}"#);
898 assert_json!(r#"{local a = 3, local c = a, b: c}"#, r#"{"b": 3}"#);
899 assert_json!(
900 r#"{local a = function (b) {[b]:4}, test: a("test")}"#,
901 r#"{"test": {"test": 4}}"#
902 );
903 }
904
905 #[test]
906 fn object_comp() {
907 assert_json!(
908 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}"#,
909 "{\"h1_2\": \"0a\",\"h1_3\": \"0a\",\"h1_4\": \"0a\",\"h2_3\": \"a1\",\"h2_4\": \"a1\",\"h3_2\": \"0a\",\"h3_4\": \"a1\"}"
910 )
911 }
912
913 #[test]
914 fn direct_self() {
915 println!(
916 "{:#?}",
917 eval!(
918 r#"
919 {
920 local me = self,
921 a: 3,
922 b(): me.a,
923 }
924 "#
925 )
926 );
927 }
928
929 #[test]
930 fn indirect_self() {
931 // `self` assigned to `me` was lost when being
932 // referenced from field
933 eval!(
934 r#"{
935 local me = self,
936 a: 3,
937 b: me.a,
938 }.b"#
939 );
940 }
941
942 // We can't trust other tests (And official jsonnet testsuite), if assert is not working correctly
943 #[test]
944 fn std_assert_ok() {
945 eval!("std.assertEqual(4.5 << 2, 16)");
946 }
947
948 #[test]
949 #[should_panic]
950 fn std_assert_failure() {
951 eval!("std.assertEqual(4.5 << 2, 15)");
952 }
953
954 #[test]
955 fn string_is_string() {
956 assert!(primitive_equals(
957 &eval!("local arr = 'hello'; (!std.isArray(arr)) && (!std.isString(arr))"),
958 &Val::Bool(false),
959 )
960 .unwrap());
961 }
962
963 #[test]
964 fn base64_works() {
965 assert_json!(r#"std.base64("test")"#, r#""dGVzdA==""#);
966 }
967
968 #[test]
969 fn utf8_chars() {
970 assert_json!(
971 r#"local c="😎";{c:std.codepoint(c),l:std.length(c)}"#,
972 r#"{"c": 128526,"l": 1}"#
973 )
974 }
975
976 #[test]
977 fn json() {
978 assert_json!(
979 r#"std.manifestJsonEx({a:3, b:4, c:6},"")"#,
980 r#""{\n\"a\": 3,\n\"b\": 4,\n\"c\": 6\n}""#
981 );
982 }
983
984 #[test]
985 fn json_minified() {
986 assert_json!(
987 r#"std.manifestJsonMinified({a:3, b:4, c:6})"#,
988 r#""{\"a\":3,\"b\":4,\"c\":6}""#
989 );
990 }
991
992 #[test]
993 fn parse_json() {
994 assert_json!(
995 r#"std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')"#,
996 r#"{"a": -1,"b": 1,"c": 3.141,"d": []}"#
997 );
998 }
999
1000 #[test]
1001 fn test() {
1002 assert_json!(
1003 r#"[[a, b] for a in [1,2,3] for b in [4,5,6]]"#,
1004 "[[1,4],[1,5],[1,6],[2,4],[2,5],[2,6],[3,4],[3,5],[3,6]]"
1005 );
1006 }
1007
1008 #[test]
1009 fn sjsonnet() {
1010 eval!(
1011 r#"
1012 local x0 = {k: 1};
1013 local x1 = {k: x0.k + x0.k};
1014 local x2 = {k: x1.k + x1.k};
1015 local x3 = {k: x2.k + x2.k};
1016 local x4 = {k: x3.k + x3.k};
1017 local x5 = {k: x4.k + x4.k};
1018 local x6 = {k: x5.k + x5.k};
1019 local x7 = {k: x6.k + x6.k};
1020 local x8 = {k: x7.k + x7.k};
1021 local x9 = {k: x8.k + x8.k};
1022 local x10 = {k: x9.k + x9.k};
1023 local x11 = {k: x10.k + x10.k};
1024 local x12 = {k: x11.k + x11.k};
1025 local x13 = {k: x12.k + x12.k};
1026 local x14 = {k: x13.k + x13.k};
1027 local x15 = {k: x14.k + x14.k};
1028 local x16 = {k: x15.k + x15.k};
1029 local x17 = {k: x16.k + x16.k};
1030 local x18 = {k: x17.k + x17.k};
1031 local x19 = {k: x18.k + x18.k};
1032 local x20 = {k: x19.k + x19.k};
1033 local x21 = {k: x20.k + x20.k};
1034 x21.k
1035 "#
1036 );
1037 }
1038
1039 // This test is commented out by default, because of huge compilation slowdown
1040 // #[bench]
1041 // fn bench_codegen(b: &mut Bencher) {
1042 // b.iter(|| {
1043 // #[allow(clippy::all)]
1044 // let stdlib = {
1045 // use jrsonnet_parser::*;
1046 // include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
1047 // };
1048 // stdlib
1049 // })
1050 // }
1051
1052 /*
1053 #[bench]
1054 fn bench_serialize(b: &mut Bencher) {
1055 b.iter(|| {
1056 bincode::deserialize::<jrsonnet_parser::LocExpr>(include_bytes!(concat!(
1057 env!("OUT_DIR"),
1058 "/stdlib.bincode"
1059 )))
1060 .expect("deserialize stdlib")
1061 })
1062 }
1063
1064 #[bench]
1065 fn bench_parse(b: &mut Bencher) {
1066 b.iter(|| {
1067 jrsonnet_parser::parse(
1068 jrsonnet_stdlib::STDLIB_STR,
1069 &jrsonnet_parser::ParserSettings {
1070 loc_data: true,
1071 file_name: Rc::new(PathBuf::from("std.jsonnet")),
1072 },
1073 )
1074 })
1075 }
1076 */
1077
1078 #[test]
1079 fn equality() {
1080 println!(
1081 "{:?}",
1082 jrsonnet_parser::parse(
1083 "{ x: 1, y: 2 } == { x: 1, y: 2 }",
1084 &ParserSettings {
1085 file_name: PathBuf::from("equality").into(),
1086 }
1087 )
1088 );
1089 assert_eval!("{ x: 1, y: 2 } == { x: 1, y: 2 }")
1090 }
1091
1092 #[test]
1093 fn native_ext() -> crate::error::Result<()> {
1094 use super::native::NativeCallback;
1095 let evaluator = State::default();
1096
1097 evaluator.with_stdlib();
1098
1099 #[derive(Trace)]
1100 struct NativeAdd;
1101 impl NativeCallbackHandler for NativeAdd {
1102 fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> crate::error::Result<Val> {
1103 assert_eq!(
1104 &from.unwrap() as &Path,
1105 &PathBuf::from("native_caller.jsonnet")
1106 );
1107 match (&args[0], &args[1]) {
1108 (Val::Num(a), Val::Num(b)) => Ok(Val::Num(a + b)),
1109 (_, _) => unreachable!(),
1110 }
1111 }
1112 }
1113 evaluator.settings_mut().ext_natives.insert(
1114 "native_add".into(),
1115 #[allow(deprecated)]
1116 Cc::new(TraceBox(Box::new(NativeCallback::new(
1117 vec![
1118 BuiltinParam {
1119 name: "a".into(),
1120 has_default: false,
1121 },
1122 BuiltinParam {
1123 name: "b".into(),
1124 has_default: false,
1125 },
1126 ],
1127 TraceBox(Box::new(NativeAdd)),
1128 )))),
1129 );
1130 dbg!(evaluator.settings().ext_natives.keys().collect::<Vec<_>>());
1131 evaluator.evaluate_snippet_raw(
1132 PathBuf::from("native_caller.jsonnet").into(),
1133 "std.assertEqual(std.native(\"native_add\")(1, 2), 3)".into(),
1134 )?;
1135 dbg!(evaluator.settings().ext_natives.keys().collect::<Vec<_>>());
1136 Ok(())
1137 }
1138
1139 #[test]
1140 fn constant_intrinsic() -> crate::error::Result<()> {
1141 assert_eval!(
1142 "local std2 = std; local std = std2 { primitiveEquals(a, b):: false }; 1 == 1"
1143 );
1144 Ok(())
1145 }
1146
1147 #[test]
1148 fn standalone_super() -> crate::error::Result<()> {
1149 assert_eval!(
1150 r#"
1151 local obj = {
1152 a: 1,
1153 b: 2,
1154 c: 3,
1155 };
1156 local test = obj + {
1157 fields: std.objectFields(super),
1158 d: 5,
1159 };
1160 test.fields == ['a', 'b', 'c']
1161 "#
1162 );
1163 Ok(())
1164 }
1165
1166 #[test]
1167 fn comp_self() -> crate::error::Result<()> {
1168 assert_eval!(
1169 r#"
1170 std.objectFields({
1171 a:{
1172 [name]: name for name in std.objectFields(self)
1173 },
1174 b: 2,
1175 c: 3,
1176 }.a) == ['a', 'b', 'c']
1177 "#
1178 );
1179
1180 Ok(())
1181 }
1182
1183 struct TestImportResolver(Vec<u8>);
1184 impl crate::import::ImportResolver for TestImportResolver {
1185 fn resolve_file(&self, _: &Path, _: &Path) -> crate::error::Result<Rc<Path>> {
1186 Ok(PathBuf::from("/test").into())
1187 }
1188
1189 fn load_file_contents(&self, _: &Path) -> crate::error::Result<Vec<u8>> {
1190 Ok(self.0.clone())
1191 }
1192
1193 unsafe fn as_any(&self) -> &dyn std::any::Any {
1194 panic!()
1195 }
1196
1197 fn load_file_bin(&self, _resolved: &Path) -> crate::error::Result<Rc<[u8]>> {
1198 panic!()
1199 }
1200 }
1201
1202 #[test]
1203 fn issue_23() {
1204 let state = State::default();
1205 state.set_import_resolver(Box::new(TestImportResolver(r#"import "/test""#.into())));
1206 let _ = state.evaluate_file_raw(&PathBuf::from("/test"));
1207 }
1208
1209 #[test]
1210 fn issue_40() {
1211 let state = State::default();
1212 state.with_stdlib();
1213
1214 let error = state
1215 .evaluate_snippet_raw(
1216 PathBuf::from("issue40.jsonnet").into(),
1217 r#"
1218 local conf = {
1219 n: ""
1220 };
1221
1222 local result = conf + {
1223 assert std.isNumber(self.n): "is number"
1224 };
1225
1226 std.manifestJsonEx(result, "")
1227 "#
1228 .into(),
1229 )
1230 .unwrap_err();
1231 assert_eq!(error.error().to_string(), "assert failed: is number");
1232 }
1233
1234 #[test]
1235 fn test_ascii_upper_lower() {
1236 assert_eval!(r#"std.assertEqual(std.asciiUpper("aBc😀"), "ABC😀")"#);
1237 assert_eval!(r#"std.assertEqual(std.asciiLower("aBc😀"), "abc😀")"#);
1238 }
1239
1240 #[test]
1241 fn test_member() {
1242 assert_eval!(r#"!std.member("", "")"#);
1243 assert_eval!(r#"std.member("abc", "a")"#);
1244 assert_eval!(r#"!std.member("abc", "d")"#);
1245 assert_eval!(r#"!std.member([], "")"#);
1246 assert_eval!(r#"std.member(["a", "b", "c"], "a")"#);
1247 assert_eval!(r#"!std.member(["a", "b", "c"], "d")"#);
1248 }
1249
1250 #[test]
1251 fn test_count() {
1252 assert_eval!(r#"std.assertEqual(std.count([], ""), 0)"#);
1253 assert_eval!(r#"std.assertEqual(std.count(["a", "b", "a"], "d"), 0)"#);
1254 assert_eval!(r#"std.assertEqual(std.count(["a", "b", "a"], "a"), 2)"#);
1255 }
1256}
1257652
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
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/math.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual(2 + 2 * 2, 6) &&
+std.assertEqual(3 + (2 + 2 * 2), 9) &&
+true
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(())