Skip to content

Commit 2118e26

Browse files
committed
Add very simple tests
1 parent 44edf6a commit 2118e26

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

example/example.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netcoreapp30;netstandard20</TargetFrameworks>
3+
<TargetFrameworks>netcoreapp31;netstandard20</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
</PropertyGroup>
66
</Project>

tests/test_common.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import pytest
2+
from subprocess import check_call
3+
import os
4+
from cffi import FFI
5+
NULL = FFI().NULL
6+
7+
@pytest.fixture(scope="session")
8+
def example_dll(tmpdir_factory):
9+
out = str(tmpdir_factory.mktemp("example"))
10+
proj_path = os.path.join(os.path.dirname(__file__), "../example")
11+
12+
check_call(["dotnet", "build", proj_path, "-o", out, "-f", "netcoreapp31"])
13+
14+
return out
15+
16+
17+
def test_mono(example_dll):
18+
from clr_loader import get_mono
19+
20+
mono = get_mono()
21+
asm = mono.get_assembly(os.path.join(example_dll, "example.dll"))
22+
23+
run_tests(asm)
24+
25+
26+
def test_coreclr(example_dll):
27+
from clr_loader import get_coreclr
28+
29+
coreclr = get_coreclr(os.path.join(example_dll, "example.runtimeconfig.json"))
30+
asm = coreclr.get_assembly(os.path.join(example_dll, "example.dll"))
31+
32+
run_tests(asm)
33+
34+
35+
def run_tests(asm):
36+
func = asm.get_function("Example.TestClass", "Test")
37+
test_data = b"testy mctestface"
38+
res = func(test_data)
39+
assert res == len(test_data)
40+

0 commit comments

Comments
 (0)