Skip to content

Commit

Permalink
test(c#): Add version runtime test (#814)
Browse files Browse the repository at this point in the history
* Add csharp test

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>

* Fix the test

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>

---------

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
  • Loading branch information
jsturtevant authored Jan 19, 2024
1 parent 7c9c462 commit 523f56e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/csharp/README.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// generate the c# and the component meta module

cargo run c-sharp --string-encoding utf8 --out-dir testing-csharp tests/codegen/floats.wit

// to run the runtime tests with Native AOT, you need some additional set up

// install emscripten
curl.exe -OL https://github.com/emscripten-core/emsdk/archive/refs/heads/main.zip
unzip main.zip
cd .\emsdk-main\main\emsdk-main
.\emsdk_env.ps1 activate 3.1.23 --permanant

// install wasi-sdk and set env
curl.exe -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0.m-mingw.tar.gz | tar xzvf -
$env:WASI_SDK_PATH="c:\users\jstur\wasi-sdk-20.0+m\"
46 changes: 46 additions & 0 deletions tests/runtime/versions/wasm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Diagnostics;
using v1 = wit_foo.wit.imports.test.dep.v0_1_0.Test;
using v2 = wit_foo.wit.imports.test.dep.v0_2_0.Test;

namespace wit_foo {

public class FooWorldImpl : IFooWorld
{
public static void TestImports()
{
Debug.Assert(v1.TestInterop.X() == 1.0f);
Debug.Assert(v1.TestInterop.Y(1.0f) == 2.0f);

Debug.Assert(v2.TestInterop.X() == 2.0f);
Debug.Assert(v2.TestInterop.Z(1.0f, 1.0f) == 4.0f);
}
}
}

namespace wit_foo.wit.exports.test.dep.v0_1_0.Test {


public class TestImpl : wit_foo.wit.exports.test.dep.v0_1_0.Test.ITest
{
public static float X() {
return 1.0f;
}

public static float Y(float a){
return a + 1.0f;
}
}
}

namespace wit_foo.wit.exports.test.dep.v0_2_0.Test {
public class TestImpl : wit_foo.wit.exports.test.dep.v0_2_0.Test.ITest
{
public static float X() {
return 2.0f;
}

public static float Z(float a, float b){
return a + b + 2.0f;
}
}
}

0 comments on commit 523f56e

Please sign in to comment.