Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/c-api/tests/component/linker.cc
2459 views
1
#include <gtest/gtest.h>
2
#include <wasmtime.h>
3
#include <wasmtime/component.hh>
4
5
using namespace wasmtime::component;
6
7
TEST(Linker, allow_shadowing) {
8
wasmtime::Engine engine;
9
Linker linker(engine);
10
auto m = wasmtime::Module::compile(engine, "(module)").unwrap();
11
12
linker.root().add_module("x", m).unwrap();
13
linker.root().add_module("x", m).err();
14
linker.allow_shadowing(true);
15
linker.root().add_module("x", m).unwrap();
16
}
17
18
TEST(Linker, unknown_imports_trap) {
19
wasmtime::Engine engine;
20
Linker linker(engine);
21
wasmtime::Store store(engine);
22
23
auto c = Component::compile(engine, R"(
24
(component
25
(import "a" (func))
26
)
27
)")
28
.unwrap();
29
30
EXPECT_FALSE(linker.instantiate(store, c));
31
EXPECT_TRUE(linker.define_unknown_imports_as_traps(c));
32
EXPECT_TRUE(linker.instantiate(store, c));
33
}
34
35