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

difftreelog

source

crates/jrsonnet-evaluator/tests/suite.rs1.0 KiBsourcehistory
1use std::{2	fs, io,3	path::{Path, PathBuf},4};56use jrsonnet_evaluator::{7	trace::{CompactFormat, PathResolver},8	FileImportResolver, State, Val,9};1011mod common;1213fn run(root: &Path, file: &Path) {14	let s = State::default();15	s.set_trace_format(Box::new(CompactFormat {16		resolver: PathResolver::Relative(root.to_owned()),17		padding: 3,18	}));19	s.with_stdlib();20	common::with_test(&s);21	s.set_import_resolver(Box::new(FileImportResolver::default()));2223	match s.import(file.to_owned()) {24		Ok(Val::Bool(true)) => {}25		Ok(Val::Bool(false)) => panic!("test {} returned false", file.display()),26		Ok(_) => panic!("test {} returned wrong type as result", file.display()),27		Err(e) => panic!("test {} failed:\n{}", file.display(), s.stringify_err(&e)),28	};29}3031#[test]32fn test() -> io::Result<()> {33	let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));34	root.push("tests/suite");3536	for entry in fs::read_dir(&root)? {37		let entry = entry?;38		if !entry.path().extension().map_or(false, |e| e == "jsonnet") {39			continue;40		}4142		run(&root, &entry.path());43	}4445	Ok(())46}