diff options
Diffstat (limited to 'src/tests/parsing.rs')
-rw-r--r-- | src/tests/parsing.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/tests/parsing.rs b/src/tests/parsing.rs new file mode 100644 index 0000000..2e701ed --- /dev/null +++ b/src/tests/parsing.rs @@ -0,0 +1,35 @@ +use crate::Configuration; + +static TEST_DIR: &str = "../tests/parsing"; + +fn single_test(flat_name: &str, complex_name: &str) -> Result<(), Box<dyn std::error::Error>> { + let config1 = Configuration::load_path(format!("{TEST_DIR}/{flat_name}"))?; + let config2 = Configuration::load_path(format!("{TEST_DIR}/{complex_name}"))?; + super::check_configs_equal(&config1, &config2) +} + +fn try_parsing() -> Result<(), Box<dyn std::error::Error>> { + 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(".flat.pom") { + single_test(&filename, filename.replace(".flat.pom", ".pom").as_ref())?; + } + } + Ok(()) +} + +#[test] +fn parsing() { + if let Err(e) = try_parsing() { + panic!("Error: {e}"); + } +} |