From 05ad1aaea4c8d259ef10e334e70ddb53dca4e17d Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 23 Sep 2019 11:04:31 -0700 Subject: [PATCH] Add test for Instance, fix tests for ImportObject --- CHANGELOG.md | 1 + lib/runtime-core/src/import.rs | 28 +++++++++++++++------------- lib/runtime-core/src/instance.rs | 12 ++++++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1651f7ffb..caa928792 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#807](https://github.com/wasmerio/wasmer/pull/807) Implement Send for `Instance`, breaking change on `ImportObject`, remove method `get_namespace` replaced with `with_namespace` and `maybe_with_namespace` - [#790](https://github.com/wasmerio/wasmer/pull/790) Fix flaky test failure with LLVM, switch to large code model. - [#788](https://github.com/wasmerio/wasmer/pull/788) Use union merge on the changelog file. - [#785](https://github.com/wasmerio/wasmer/pull/785) Include Apache license file for spectests. diff --git a/lib/runtime-core/src/import.rs b/lib/runtime-core/src/import.rs index ff09450fe..2cccf2325 100644 --- a/lib/runtime-core/src/import.rs +++ b/lib/runtime-core/src/import.rs @@ -266,12 +266,14 @@ mod test { imports1.extend(imports2); - let cat_ns = imports1.get_namespace("cat").unwrap(); - assert!(cat_ns.get_export("small").is_some()); + let small_cat_export = + imports1.maybe_with_namespace("cat", |cat_ns| cat_ns.get_export("small")); + assert!(small_cat_export.is_some()); - let dog_ns = imports1.get_namespace("dog").unwrap(); - assert!(dog_ns.get_export("happy").is_some()); - assert!(dog_ns.get_export("small").is_some()); + let entries = imports1.maybe_with_namespace("dog", |dog_ns| { + Some((dog_ns.get_export("happy")?, dog_ns.get_export("small")?)) + }); + assert!(entries.is_some()); } #[test] @@ -289,14 +291,14 @@ mod test { }; imports1.extend(imports2); - let dog_ns = imports1.get_namespace("dog").unwrap(); + let happy_dog_entry = imports1 + .maybe_with_namespace("dog", |dog_ns| dog_ns.get_export("happy")) + .unwrap(); - assert!( - if let Export::Global(happy_dog_global) = dog_ns.get_export("happy").unwrap() { - happy_dog_global.get() == Value::I32(4) - } else { - false - } - ); + assert!(if let Export::Global(happy_dog_global) = happy_dog_entry { + happy_dog_global.get() == Value::I32(4) + } else { + false + }); } } diff --git a/lib/runtime-core/src/instance.rs b/lib/runtime-core/src/instance.rs index 6f30b0a74..c6867d100 100644 --- a/lib/runtime-core/src/instance.rs +++ b/lib/runtime-core/src/instance.rs @@ -752,3 +752,15 @@ impl<'a> DynFunc<'a> { } } } + +#[cfg(test)] +mod test { + use super::*; + + fn is_send() {} + + #[test] + fn test_instance_is_send() { + is_send::(); + } +}