summaryrefslogtreecommitdiff
path: root/src/tests/mod.rs
blob: 97a3a29466763bf2676f79a1f9bda80b3df24a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
mod errors;
mod locations;
mod parsing;

fn do_tests_in_dir(
	dir: &str,
	ext: &str,
	test: impl Fn(&str) -> Result<(), Box<dyn std::error::Error>>,
) {
	let result = (|| -> Result<(), Box<dyn std::error::Error>> {
		let test_dir = format!("../tests/{dir}");
		let tests = std::fs::read_dir(&test_dir).map_err(|e| {
			format!(
				"error reading {test_dir}: {e} — try moving pom-rs to inside the main pom repository?"
			)
		})?;
		for test_entry in tests {
			let filename = test_entry
				.map_err(|e| format!("error reading tests directory {test_dir}: {e}"))?
				.file_name()
				.into_string()
				.expect("bad UTF-8 in test name (file in {test_dir})");
			if filename.ends_with(ext) {
				println!("Running test {dir}/{filename}...");
				test(&format!("{test_dir}/{filename}"))
					.map_err(|e| format!("{dir}/{filename}: {e}"))?;
			}
		}
		Ok(())
	})();
	if let Err(e) = result {
		panic!("Error: {e}");
	}
}