Skip to content

Commit 8cfb805

Browse files
authored
migrate versions test to new test framework (#1242)
Signed-off-by: James Sturtevant <[email protected]>
1 parent 19a2351 commit 8cfb805

File tree

13 files changed

+94
-159
lines changed

13 files changed

+94
-159
lines changed

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

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

crates/test/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,12 @@ impl Runner<'_> {
325325
dir: &Path,
326326
) -> Result<(config::WitConfig, Vec<Component>)> {
327327
let mut resolve = wit_parser::Resolve::default();
328-
let pkg = resolve
329-
.push_file(&wit)
330-
.context("failed to load `test.wit` in test directory")?;
328+
329+
let wit_path = if dir.join("deps").exists() { dir } else { wit };
330+
let (pkg, _files) = resolve.push_path(wit_path).context(format!(
331+
"failed to load `test.wit` in test directory: {:?}",
332+
&wit
333+
))?;
331334
let resolve = Arc::new(resolve);
332335

333336
let wit_contents = std::fs::read_to_string(wit)?;
@@ -378,7 +381,7 @@ impl Runner<'_> {
378381
args: Vec::new(),
379382
wit_config: wit_config.clone(),
380383
world: resolve.worlds[*world].name.clone(),
381-
wit_path: wit.to_path_buf(),
384+
wit_path: wit_path.to_path_buf(),
382385
};
383386
let component = self
384387
.parse_component(&path, *kind, bindgen)

tests/runtime-new/versions/runner.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using System.Diagnostics;
4+
using v1 = RunnerWorld.wit.imports.test.dep.v0_1_0;
5+
using v2 = RunnerWorld.wit.imports.test.dep.v0_2_0;
6+
using System.Text;
7+
8+
public class Program
9+
{
10+
public static void Main(string[] args){
11+
Debug.Assert(v1.TestInterop.X() == 1.0f);
12+
Debug.Assert(v1.TestInterop.Y(1.0f) == 2.0f);
13+
14+
Debug.Assert(v2.TestInterop.X() == 2.0f);
15+
Debug.Assert(v2.TestInterop.Z(1.0f, 1.0f) == 4.0f);
16+
}
17+
}

tests/runtime-new/versions/runner.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include!(env!("BINDINGS"));
2+
3+
fn main() {
4+
use test::dep0_1_0::test as v1;
5+
assert_eq!(v1::x(), 1.0);
6+
assert_eq!(v1::y(1.0), 2.0);
7+
8+
use test::dep0_2_0::test as v2;
9+
assert_eq!(v2::x(), 2.0);
10+
assert_eq!(v2::z(1.0, 1.0), 4.0);
11+
}

tests/runtime-new/versions/test.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Diagnostics;
2+
3+
namespace TestWorld.wit.exports.test.dep.v0_1_0 {
4+
public class TestImpl : TestWorld.wit.exports.test.dep.v0_1_0.ITest
5+
{
6+
public static float X() {
7+
return 1.0f;
8+
}
9+
10+
public static float Y(float a){
11+
return a + 1.0f;
12+
}
13+
}
14+
}
15+
16+
namespace TestWorld.wit.exports.test.dep.v0_2_0
17+
{
18+
public class TestImpl : TestWorld.wit.exports.test.dep.v0_2_0.ITest
19+
{
20+
public static float X() {
21+
return 2.0f;
22+
}
23+
24+
public static float Z(float a, float b){
25+
return a + b + 2.0f;
26+
}
27+
}
28+
}

tests/runtime-new/versions/test.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include!(env!("BINDINGS"));
2+
3+
use exports::test::dep0_1_0::test::Guest as v1;
4+
use exports::test::dep0_2_0::test::Guest as v2;
5+
6+
struct Component;
7+
8+
export!(Component);
9+
10+
impl v1 for Component {
11+
fn x() -> f32 {
12+
1.0
13+
}
14+
15+
fn y(a: f32) -> f32 {
16+
1.0 + a
17+
}
18+
}
19+
20+
impl v2 for Component {
21+
fn x() -> f32 {
22+
2.0
23+
}
24+
25+
fn z(a: f32, b: f32) -> f32 {
26+
2.0 + a + b
27+
}
28+
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package test:versions;
22

3-
world foo {
3+
world runner {
44
import test:dep/test@0.1.0;
55
import test:dep/test@0.2.0;
6+
}
67

8+
world test {
79
export test:dep/test@0.1.0;
810
export test:dep/test@0.2.0;
9-
export test-imports: func();
1011
}

tests/runtime/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ mod resource_into_inner;
2727
mod resource_with_lists;
2828
mod resources;
2929
mod results;
30-
mod versions;
3130

3231
struct MyCtx {}
3332

0 commit comments

Comments
 (0)