Skip to content

Commit

Permalink
Fixed wasmer-cache unit tests and lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Mar 9, 2023
1 parent 4efe78e commit c62ee14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
7 changes: 5 additions & 2 deletions lib/cache/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ mod tests {
use super::*;

#[test]
fn hash_to_array_works() {
fn hash_is_displayed_as_hex() {
let original = [
0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x12, 0x65, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
0x12, 0x65, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x12, 0x65, 0xAA, 0xBB, 0xCC, 0xDD,
0xEE, 0xFF, 0x12, 0x65,
];
let hash = Hash::new(original);
assert_eq!(hash.to_array(), original);
assert_eq!(
hash.to_string(),
"aabbccddeeff1265aabbccddeeff1265aabbccddeeff1265aabbccddeeff1265"
);
}
}
24 changes: 12 additions & 12 deletions lib/cli/src/commands/run2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ impl Run2 {
runner.set_forward_host_env();
}
if runner.can_run_command(id, command).unwrap_or(false) {
return runner.run_cmd(&container, id).context("WASI runner failed");
return runner.run_cmd(container, id).context("WASI runner failed");
}

let (store, _compiler_type) = self.store.get_store()?;
let mut runner = wasmer_wasi::runners::emscripten::EmscriptenRunner::new(store);
runner.set_args(self.args.clone());
if runner.can_run_command(id, command).unwrap_or(false) {
return runner
.run_cmd(&container, id)
.run_cmd(container, id)
.context("Emscripten runner failed");
}

Expand All @@ -160,7 +160,7 @@ impl Run2 {
runner.config().forward_host_env();
}
if runner.can_run_command(id, command).unwrap_or(false) {
return runner.run_cmd(&container, id).context("WCGI runner failed");
return runner.run_cmd(container, id).context("WCGI runner failed");
}

anyhow::bail!(
Expand Down Expand Up @@ -334,17 +334,17 @@ enum PackageSource {

impl PackageSource {
fn infer(s: &str) -> Result<PackageSource, Error> {
if let Ok(url) = Url::parse(s) {
return Ok(PackageSource::Url(url));
}

let path = Path::new(s);
if path.is_file() {
return Ok(PackageSource::File(path.to_path_buf()));
} else if path.is_dir() {
return Ok(PackageSource::Dir(path.to_path_buf()));
}

if let Ok(url) = Url::parse(s) {
return Ok(PackageSource::Url(url));
}

if let Ok(pkg) = Package::from_str(s) {
return Ok(PackageSource::Package(pkg));
}
Expand Down Expand Up @@ -452,7 +452,7 @@ impl TargetOnDisk {
TargetOnDisk::Directory(dir) => {
// FIXME: Runners should be able to load directories directly
// instead of needing to compile to a WEBC file.
let webc = compile_directory_to_webc(&dir).with_context(|| {
let webc = compile_directory_to_webc(dir).with_context(|| {
format!("Unable to bundle \"{}\" as a WEBC package", dir.display())
})?;
let container = WapmContainer::from_bytes(webc.into())
Expand All @@ -463,7 +463,7 @@ impl TargetOnDisk {
TargetOnDisk::WebAssemblyBinary(path) => {
let wasm = std::fs::read(&path)
.with_context(|| format!("Unable to read \"{}\"", path.display()))?;
let module = compile_wasm_cached(&path, &wasm, cache, store)?;
let module = compile_wasm_cached(path, &wasm, cache, store)?;
Ok(ExecutableTarget::WebAssembly(module))
}
TargetOnDisk::Wat(path) => {
Expand All @@ -472,7 +472,7 @@ impl TargetOnDisk {
let wasm =
wasmer::wat2wasm(&wat).context("Unable to convert the WAT to WebAssembly")?;

let module = compile_wasm_cached(&path, &wasm, cache, store)?;
let module = compile_wasm_cached(path, &wasm, cache, store)?;
Ok(ExecutableTarget::WebAssembly(module))
}
TargetOnDisk::Artifact(artifact) => {
Expand All @@ -492,7 +492,7 @@ fn compile_wasm_cached(
cache: &mut ModuleCache,
store: &Store,
) -> Result<Module, Error> {
let hash = wasmer_cache::Hash::generate(&wasm);
let hash = wasmer_cache::Hash::generate(wasm);

unsafe {
match cache.load(store, hash) {
Expand Down Expand Up @@ -560,7 +560,7 @@ fn generate_coredump(err: &Error, source: &Path, coredump_path: &Path) -> Result

let coredump = coredump_builder
.serialize()
.map_err(|e| Error::msg(e))
.map_err(Error::msg)
.context("Coredump serializing failed")?;

std::fs::write(&coredump_path, &coredump).with_context(|| {
Expand Down

0 comments on commit c62ee14

Please sign in to comment.