diff --git a/mm0-rs/Cargo.lock b/mm0-rs/Cargo.lock index 1336ec78..8686982b 100644 --- a/mm0-rs/Cargo.lock +++ b/mm0-rs/Cargo.lock @@ -436,6 +436,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + [[package]] name = "hashbrown" version = "0.11.2" @@ -667,6 +673,7 @@ dependencies = [ "crossbeam", "debug_derive", "futures", + "glob", "if_chain", "im", "instant", diff --git a/mm0-rs/Cargo.toml b/mm0-rs/Cargo.toml index 1d1232c1..f8bda3a4 100644 --- a/mm0-rs/Cargo.toml +++ b/mm0-rs/Cargo.toml @@ -96,3 +96,6 @@ wasm-bindgen = "0.2" name = "mm0-rs" path = "src/main.rs" doc = false + +[dev-dependencies] +glob = "0.3.0" diff --git a/mm0-rs/src/compiler.rs b/mm0-rs/src/compiler.rs index e54072b2..79a4d550 100644 --- a/mm0-rs/src/compiler.rs +++ b/mm0-rs/src/compiler.rs @@ -55,7 +55,7 @@ enum FileCache { } #[derive(DeepSizeOf, Clone)] -pub(crate) enum FileContents { +pub enum FileContents { Ascii(Arc), #[cfg(not(target_arch = "wasm32"))] MMap(Arc), @@ -64,23 +64,23 @@ pub(crate) enum FileContents { impl FileContents { /// Constructs a new [`FileContents`] from source text. - pub(crate) fn new(text: String) -> Self { + pub fn new(text: String) -> Self { Self::Ascii(Arc::new(text.into())) } /// Constructs a new [`FileContents`] from a memory map. #[cfg(not(target_arch = "wasm32"))] - pub(crate) fn new_mmap(data: memmap::Mmap) -> Self { + pub fn new_mmap(data: memmap::Mmap) -> Self { Self::MMap(Arc::new(data)) } /// Constructs a new [`FileContents`] from a memory map. #[allow(unused)] - pub(crate) fn new_bin(data: Box<[u8]>) -> Self { + pub fn new_bin(data: Box<[u8]>) -> Self { Self::Bin(data.into()) } - pub(crate) fn new_bin_from_file(path: &std::path::Path) -> io::Result { + pub fn new_bin_from_file(path: &std::path::Path) -> io::Result { #[cfg(not(target_arch = "wasm32"))] { let file = fs::File::open(path)?; // Safety: Well, memory mapping files is never totally safe, but we're assuming @@ -94,17 +94,17 @@ impl FileContents { } } - pub(crate) fn try_ascii(&self) -> Option<&Arc> { + pub fn try_ascii(&self) -> Option<&Arc> { if let Self::Ascii(e) = self {Some(e)} else {None} } #[track_caller] - pub(crate) fn ascii(&self) -> &Arc { + pub fn ascii(&self) -> &Arc { self.try_ascii().expect("expected ASCII file") } #[allow(unused)] - pub(crate) fn ptr_eq(&self, other: &Self) -> bool { + pub fn ptr_eq(&self, other: &Self) -> bool { match (self, other) { (Self::Ascii(e1), Self::Ascii(e2)) => Arc::ptr_eq(e1, e2), #[cfg(not(target_arch = "wasm32"))] @@ -469,7 +469,7 @@ fn elaborate_and_send(path: FileRef, send: FSender>, rd: ArcList< /// Elaborate a file, and return the completed [`FrozenEnv`] result, along with the /// file contents. -pub(crate) fn elab_for_result(path: FileRef) -> io::Result<(FileContents, Option)> { +pub fn elab_for_result(path: FileRef) -> io::Result<(FileContents, Option)> { let (path, file) = VFS.get_or_insert(path)?; let env = match block_on(elaborate(path, Default::default()))? { ElabResult::Ok(_, _, env) => Some(env), diff --git a/mm0-rs/tests/common/mod.rs b/mm0-rs/tests/common/mod.rs new file mode 100644 index 00000000..959bfe1a --- /dev/null +++ b/mm0-rs/tests/common/mod.rs @@ -0,0 +1 @@ +// Common test code goes here diff --git a/mm0-rs/tests/integration_test.rs b/mm0-rs/tests/integration_test.rs new file mode 100644 index 00000000..1659c545 --- /dev/null +++ b/mm0-rs/tests/integration_test.rs @@ -0,0 +1,13 @@ +mod common; + +use mm0_rs::{compiler::elab_for_result, FileRef}; + +#[test] +fn elaborate_examples() { + for file in glob::glob("../examples/*.mm[01]").unwrap() { + let file = file.unwrap(); + println!("\n--- Elaborating {} ---", file.display()); + let file_ref = FileRef::from(file); + let (_, _) = elab_for_result(file_ref.clone()).expect(&format!("failed to elaborate {}", file_ref.clone())); + } +}