Skip to content

Commit c07fd71

Browse files
committed
Makefile, testdata, tests: set up test for #284
1 parent f3f981d commit c07fd71

File tree

8 files changed

+142
-0
lines changed

8 files changed

+142
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ test:
5353
tinygo test -target=wasip1 $(GOTESTARGS) $(GOTESTMODULES)
5454
tinygo test -target=wasip2 $(GOTESTARGS) $(GOTESTMODULES)
5555
tinygo test -target=wasip2 $(GOTESTARGS) ./tests/...
56+
57+
.PHONY: tests
58+
tests:
59+
tinygo test -target=wasip2 $(GOTESTARGS) ./tests/...

testdata/issues/issue284.wit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package issues:issue284;
2+
3+
interface i {
4+
type bool-s8-result = result<bool, s8>;
5+
}
6+
7+
world w {
8+
import i;
9+
}

testdata/issues/issue284.wit.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"worlds": [
3+
{
4+
"name": "w",
5+
"imports": {
6+
"interface-0": {
7+
"interface": {
8+
"id": 0
9+
}
10+
}
11+
},
12+
"exports": {},
13+
"package": 0
14+
}
15+
],
16+
"interfaces": [
17+
{
18+
"name": "i",
19+
"types": {
20+
"bool-s8-result": 0
21+
},
22+
"functions": {},
23+
"package": 0
24+
}
25+
],
26+
"types": [
27+
{
28+
"name": "bool-s8-result",
29+
"kind": {
30+
"result": {
31+
"ok": "bool",
32+
"err": "s8"
33+
}
34+
},
35+
"owner": {
36+
"interface": 0
37+
}
38+
}
39+
],
40+
"packages": [
41+
{
42+
"name": "issues:issue284",
43+
"interfaces": {
44+
"i": 0
45+
},
46+
"worlds": {
47+
"w": 0
48+
}
49+
}
50+
]
51+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package issues:issue284;
2+
3+
interface i {
4+
type bool-s8-result = result<bool, s8>;
5+
}
6+
7+
world w {
8+
import i;
9+
}

tests/generated/issues/issue284/i/i.wit.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/issues/issue284/w/w.wit.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package issue284
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"tests/generated/issues/issue284/i"
8+
9+
"go.bytecodealliance.org/cm"
10+
)
11+
12+
func TestIssue284(t *testing.T) {
13+
tests := []struct {
14+
isErr bool
15+
ok bool
16+
err int8
17+
}{
18+
{false, false, 0},
19+
{false, true, 0},
20+
{true, false, 0},
21+
{true, false, 1},
22+
{true, false, 5},
23+
{true, false, 126},
24+
{true, false, 127},
25+
}
26+
for _, tt := range tests {
27+
if !tt.isErr {
28+
t.Run(fmt.Sprintf("cm.OK[i.BoolS8Result](%t)", tt.ok), func(t *testing.T) {
29+
r := cm.OK[i.BoolS8Result](tt.ok)
30+
ok, _, isErr := r.Result()
31+
if isErr != tt.isErr {
32+
t.Errorf("isErr == %t, expected %t", isErr, tt.isErr)
33+
}
34+
if ok != tt.ok {
35+
t.Errorf("ok == %t, expected %t", ok, tt.ok)
36+
}
37+
})
38+
} else {
39+
t.Run(fmt.Sprintf("cm.Err[i.BoolS8Result](%d)", tt.err), func(t *testing.T) {
40+
r := cm.Err[i.BoolS8Result](tt.err)
41+
_, err, isErr := r.Result()
42+
if isErr != tt.isErr {
43+
t.Errorf("isErr == %t, expected %t", isErr, tt.isErr)
44+
}
45+
if err != tt.err {
46+
t.Errorf("err == %d, expected %d", err, tt.err)
47+
}
48+
})
49+
}
50+
}
51+
}

tests/tests.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ package tests
77
//go:generate rm -rf ./generated/*
88
//go:generate mkdir -p ./generated
99
//go:generate go run go.bytecodealliance.org/cmd/wit-bindgen-go generate --versioned -o ./generated ../testdata/wasi/cli.wit.json
10+
//go:generate go run go.bytecodealliance.org/cmd/wit-bindgen-go generate --versioned -o ./generated ../testdata/issues/issue284.wit

0 commit comments

Comments
 (0)