Skip to content

Commit 6ff506c

Browse files
committed
test: extend bindgen-test-cases fixture with collision imports
Add deps/a-pkg/types.wit and deps/b-pkg/types.wit to the bindgen-test-cases WIT fixture. Both define an interface named "types", creating a name collision that exercises the disambiguation logic added in the previous commit. Extend the world to import both packages and add collision host tests to the existing bindgen_test_cases test module, covering: - distinct generated record types (collision_types_are_distinct) - separate host trait impl per colliding interface (collision_host_impl_compiles) Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent 0e17bfe commit 6ff506c

4 files changed

Lines changed: 87 additions & 0 deletions

File tree

src/hyperlight_host/tests/wit_test.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,71 @@ mod bindgen_test_cases {
487487
};
488488
assert_eq!(result.message, "executed");
489489
}
490+
491+
// Verify that the disambiguated types and record types exist
492+
// and can be instantiated. This confirms that two interfaces
493+
// both named "types" from different packages (a:pkg and b:pkg)
494+
// generate distinct trait members (APkgTypes vs BPkgTypes).
495+
#[test]
496+
fn collision_types_are_distinct() {
497+
let info = a::pkg::types::Info {
498+
name: String::from("hello"),
499+
value: 42,
500+
};
501+
let detail = b::pkg::types::Detail {
502+
label: String::from("world"),
503+
count: 99,
504+
};
505+
assert_eq!(info.name, "hello");
506+
assert_eq!(info.value, 42);
507+
assert_eq!(detail.label, "world");
508+
assert_eq!(detail.count, 99);
509+
}
510+
511+
// Verify the imports trait has distinct associated types for each
512+
// colliding interface, ensuring a host implementation can provide
513+
// separate implementations for each.
514+
struct CollisionHost;
515+
516+
impl a::pkg::Types for CollisionHost {
517+
fn get_info(&mut self) -> a::pkg::types::Info {
518+
a::pkg::types::Info {
519+
name: String::from("test-info"),
520+
value: 1,
521+
}
522+
}
523+
}
524+
525+
impl b::pkg::Types for CollisionHost {
526+
fn get_detail(&mut self) -> b::pkg::types::Detail {
527+
b::pkg::types::Detail {
528+
label: String::from("test-detail"),
529+
count: 2,
530+
}
531+
}
532+
}
533+
534+
#[allow(refining_impl_trait)]
535+
impl test::bindgen_test_cases::BindgenTestCasesImports for CollisionHost {
536+
type APkgTypes = Self;
537+
fn a_pkg_types(&mut self) -> &mut Self {
538+
self
539+
}
540+
type BPkgTypes = Self;
541+
fn b_pkg_types(&mut self) -> &mut Self {
542+
self
543+
}
544+
}
545+
546+
#[test]
547+
fn collision_host_impl_compiles() {
548+
// Verifies the generated trait has distinct associated types for each
549+
// colliding import. The existence of this test (and the fact it compiles)
550+
// is the assertion.
551+
let mut host = CollisionHost;
552+
let info = a::pkg::Types::get_info(&mut host);
553+
assert_eq!(info.name, "test-info");
554+
let detail = b::pkg::Types::get_detail(&mut host);
555+
assert_eq!(detail.label, "test-detail");
556+
}
490557
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package a:pkg;
2+
3+
interface types {
4+
record info {
5+
name: string,
6+
value: u32,
7+
}
8+
get-info: func() -> info;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package b:pkg;
2+
3+
interface types {
4+
record detail {
5+
label: string,
6+
count: u64,
7+
}
8+
get-detail: func() -> detail;
9+
}

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

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

33
world bindgen-test-cases {
4+
import a:pkg/types;
5+
import b:pkg/types;
46
export executor;
57
}
68

0 commit comments

Comments
 (0)