Skip to content

Commit 265ffc3

Browse files
committed
test: cover WIT import collision cases
Extend the bindgen-test-cases fixture with colliding package, versioned, hyphenated, and bare import cases, plus export-name coverage. Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent a9a23bf commit 265ffc3

9 files changed

Lines changed: 188 additions & 0 deletions

File tree

src/hyperlight_host/tests/wit_test.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,53 @@ mod bindgen_test_cases {
487487
};
488488
assert_eq!(result.message, "executed");
489489
}
490+
491+
#[allow(dead_code)]
492+
struct ExportHost;
493+
494+
impl test::bindgen_test_cases::Executor for ExportHost {
495+
fn execute(&mut self) -> test::bindgen_test_cases::executor::ExecutionResult {
496+
test::bindgen_test_cases::executor::ExecutionResult {
497+
message: String::from("executed"),
498+
}
499+
}
500+
}
501+
502+
impl test::bindgen_test_cases::Types for ExportHost {
503+
fn get_status(&mut self) -> test::bindgen_test_cases::types::Status {
504+
test::bindgen_test_cases::types::Status {
505+
message: String::from("ok"),
506+
}
507+
}
508+
}
509+
510+
impl test::bindgen_test_cases::UsesExportedTypes<test::bindgen_test_cases::types::Status>
511+
for ExportHost
512+
{
513+
fn get_status(&mut self) -> test::bindgen_test_cases::types::Status {
514+
test::bindgen_test_cases::types::Status {
515+
message: String::from("ok"),
516+
}
517+
}
518+
}
519+
520+
#[allow(refining_impl_trait)]
521+
impl<I: test::bindgen_test_cases::BindgenTestCasesImports + Send>
522+
test::bindgen_test_cases::BindgenTestCasesExports<I> for ExportHost
523+
{
524+
type Executor = Self;
525+
fn executor(&mut self) -> &mut Self {
526+
self
527+
}
528+
529+
type Types = Self;
530+
fn types(&mut self) -> &mut Self {
531+
self
532+
}
533+
534+
type UsesExportedTypes = Self;
535+
fn uses_exported_types(&mut self) -> &mut Self {
536+
self
537+
}
538+
}
490539
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package a:bc;
2+
3+
interface types {
4+
resource thing;
5+
6+
record plain-bc-info {
7+
label: string,
8+
}
9+
get-plain-bc-info: func() -> plain-bc-info;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package a:b-c;
2+
3+
interface types {
4+
resource thing;
5+
6+
record bc-info {
7+
label: string,
8+
}
9+
get-bc-info: func() -> bc-info;
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package a:pkg;
2+
3+
interface types {
4+
resource thing;
5+
6+
record info {
7+
name: string,
8+
value: u32,
9+
}
10+
get-info: func() -> info;
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package a-b:c;
2+
3+
interface types {
4+
resource thing;
5+
6+
record ab-c-info {
7+
tag: string,
8+
}
9+
get-ab-c-info: func() -> ab-c-info;
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package b:pkg;
2+
3+
interface types {
4+
resource thing;
5+
6+
record detail {
7+
label: string,
8+
count: u64,
9+
}
10+
get-detail: func() -> detail;
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package c:pkg@1.0.0;
2+
3+
interface types {
4+
resource thing;
5+
6+
record info {
7+
value: u32,
8+
}
9+
get-info: func() -> info;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package c:pkg@2.0.0;
2+
3+
interface types {
4+
resource thing;
5+
6+
record info {
7+
value: u32,
8+
}
9+
get-info: func() -> info;
10+
}

src/tests/rust_guests/witguest/bindgen-test-cases/world.wit

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,61 @@
11
package test:bindgen-test-cases;
22

33
world bindgen-test-cases {
4+
import types: interface {
5+
get-status: func() -> string;
6+
}
7+
import a:pkg/types;
8+
import b:pkg/types;
9+
import c:pkg/types@1.0.0;
10+
import c:pkg/types@2.0.0;
11+
import a:bc/types;
12+
import a:b-c/types;
13+
import a-b:c/types;
14+
import uses-a-pkg-resource;
15+
import uses-b-pkg-resource;
16+
import uses-c-pkg-v1-resource;
17+
import uses-c-pkg-v2-resource;
18+
import uses-a-bc-plain-resource;
19+
import uses-a-bc-resource;
20+
import uses-ab-c-resource;
421
export executor;
22+
export types;
23+
export uses-exported-types;
24+
}
25+
26+
interface uses-a-pkg-resource {
27+
use a:pkg/types.{thing};
28+
use-thing: func(x: borrow<thing>);
29+
}
30+
31+
interface uses-b-pkg-resource {
32+
use b:pkg/types.{thing};
33+
use-thing: func(x: borrow<thing>);
34+
}
35+
36+
interface uses-c-pkg-v1-resource {
37+
use c:pkg/types@1.0.0.{thing};
38+
use-thing: func(x: borrow<thing>);
39+
}
40+
41+
interface uses-c-pkg-v2-resource {
42+
use c:pkg/types@2.0.0.{thing};
43+
use-thing: func(x: borrow<thing>);
44+
}
45+
46+
interface uses-a-bc-plain-resource {
47+
use a:bc/types.{thing};
48+
use-thing: func(x: borrow<thing>);
49+
}
50+
51+
interface uses-a-bc-resource {
52+
use a:b-c/types.{thing};
53+
use-thing: func(x: borrow<thing>);
54+
}
55+
56+
interface uses-ab-c-resource {
57+
use a-b:c/types.{thing};
58+
use-thing: func(x: borrow<thing>);
559
}
660

761
interface executor {
@@ -11,3 +65,16 @@ interface executor {
1165

1266
execute: func() -> execution-result;
1367
}
68+
69+
interface types {
70+
record status {
71+
message: string,
72+
}
73+
74+
get-status: func() -> status;
75+
}
76+
77+
interface uses-exported-types {
78+
use types.{status};
79+
get-status: func() -> status;
80+
}

0 commit comments

Comments
 (0)