Skip to content

Commit

Permalink
add validate test
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed May 2, 2024
1 parent dbcd7f4 commit fc397fe
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ strip = true
inherits = "dist"
opt-level = "z"

[profile.release]
panic = "abort"

[workspace]
members = [
"crates/kitsune-activitypub",
Expand Down
3 changes: 3 additions & 0 deletions lib/mrf-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ wasmparser = "0.206.0"

[lints]
workspace = true

[dev-dependencies]
wat = "1.206.0"
7 changes: 7 additions & 0 deletions lib/mrf-tool/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub struct DummyFs {
inner: HashMap<PathBuf, Vec<u8>>,
}

impl From<HashMap<PathBuf, Vec<u8>>> for DummyFs {
#[inline]
fn from(value: HashMap<PathBuf, Vec<u8>>) -> Self {
Self { inner: value }
}
}

#[inline]
fn file_not_found() -> io::Error {
io::Error::new(io::ErrorKind::NotFound, "file not found")
Expand Down
2 changes: 1 addition & 1 deletion lib/mrf-tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
use color_eyre::{eyre::bail, Result};
use std::{ffi::OsString, io::Write, path::Path};

pub use self::fs::{Filesystem, NativeFs};
pub use self::fs::{DummyFs, Filesystem, NativeFs};

mod args;
mod fs;
Expand Down
8 changes: 8 additions & 0 deletions lib/mrf-tool/tests/manifest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[test]
fn add() {}

#[test]
fn read() {}

#[test]
fn remove() {}
25 changes: 25 additions & 0 deletions lib/mrf-tool/tests/module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use mrf_tool::DummyFs;
use std::{collections::HashMap, io};

#[test]
fn validate() {
let mut value = HashMap::new();
value.insert("empty.wasm".into(), wat::parse_str("(module)").unwrap());
value.insert("empty.bin".into(), vec![0x00]);
let mut fs = DummyFs::from(value);

let result = mrf_tool::handle(
&mut fs,
&mut io::sink(),
["mrf-tool", "module", "validate", "empty.wasm"],
);
assert!(result.is_ok(), "{result:?}");

let error = mrf_tool::handle(
&mut fs,
&mut io::sink(),
["mrf-tool", "module", "validate", "empty.bin"],
)
.unwrap_err();
assert!(error.is::<wasmparser::BinaryReaderError>());
}

0 comments on commit fc397fe

Please sign in to comment.