Skip to content

Commit f1bdaa7

Browse files
authored
Migrate resource_borrow_{simple,import,export} to wit-bindgen test (#1253)
Fold all these tests into one as they were very small tests to start off with and already had overlapping functionality.
1 parent 74f5bdc commit f1bdaa7

File tree

24 files changed

+90
-261
lines changed

24 files changed

+90
-261
lines changed

crates/test-rust-wasm/Cargo.toml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ test = false
5151
name = "resource_with_lists"
5252
test = false
5353

54-
[[bin]]
55-
name = "resource_borrow_import"
56-
test = false
57-
58-
[[bin]]
59-
name = "resource_borrow_export"
60-
test = false
61-
6254
[[bin]]
6355
name = "resource_alias"
6456
test = false
65-
66-
[[bin]]
67-
name = "resource_borrow_simple"
68-
test = false

crates/test-rust-wasm/src/bin/resource_borrow_export.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

crates/test-rust-wasm/src/bin/resource_borrow_import.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

crates/test-rust-wasm/src/bin/resource_borrow_simple.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <assert.h>
2+
#include "runner.h"
3+
4+
int main() {
5+
test_resource_borrow_to_test_own_thing_t thing;
6+
thing = test_resource_borrow_to_test_constructor_thing(42);
7+
8+
test_resource_borrow_to_test_borrow_thing_t borrow;
9+
borrow = test_resource_borrow_to_test_borrow_thing(thing);
10+
11+
uint32_t res = test_resource_borrow_to_test_foo(borrow);
12+
assert(res == 42 + 1 + 2);
13+
14+
test_resource_borrow_to_test_thing_drop_own(thing);
15+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using RunnerWorld.wit.imports.test.resourceBorrow;
2+
using System.Diagnostics;
3+
4+
public class RunnerWorldImpl {
5+
public static void Main() {
6+
uint ret = ToTestInterop.Foo(new IToTest.Thing(42));
7+
Debug.Assert(ret == 42 + 1 + 2);
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include!(env!("BINDINGS"));
2+
3+
use crate::test::resource_borrow::to_test::{foo, Thing};
4+
5+
fn main() {
6+
assert_eq!(foo(&Thing::new(42)), 42 + 1 + 2);
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ args = '--rename test:resource-borrow/to-test=test'
2+
3+
#include <assert.h>
4+
#include <stdlib.h>
5+
#include "test.h"
6+
7+
struct exports_test_thing_t {
8+
uint32_t my_state;
9+
};
10+
11+
exports_test_own_thing_t exports_test_constructor_thing(uint32_t v) {
12+
exports_test_thing_t *rep = malloc(sizeof(exports_test_thing_t));
13+
assert(rep != NULL);
14+
rep->my_state = v + 1;
15+
return exports_test_thing_new(rep);
16+
}
17+
18+
uint32_t exports_test_foo(exports_test_borrow_thing_t v) {
19+
return v->my_state + 2;
20+
}
21+
22+
void exports_test_thing_destructor(exports_test_thing_t *rep) {
23+
free(rep);
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace TestWorld.wit.exports.test.resourceBorrow
2+
{
3+
public class ToTestImpl : IToTest {
4+
public class Thing : IToTest.Thing, IToTest.IThing {
5+
public uint val;
6+
7+
public Thing(uint v) {
8+
this.val = v + 1;
9+
}
10+
}
11+
12+
public static uint Foo(IToTest.Thing v) {
13+
return ((Thing) v).val + 2;
14+
}
15+
}
16+
}

tests/runtime/resource_borrow_export/wasm.rs renamed to tests/runtime-new/resource-borrow/test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
wit_bindgen::generate!({
2-
path: "../../tests/runtime/resource_borrow_export",
3-
});
1+
include!(env!("BINDINGS"));
42

5-
use exports::test::resource_borrow_export::test::{Guest, GuestThing, ThingBorrow};
3+
use exports::test::resource_borrow::to_test::{Guest, GuestThing, ThingBorrow};
64

75
pub struct Test {}
86

0 commit comments

Comments
 (0)