Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 142 additions & 35 deletions crates/go/src/lib.rs

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions crates/go/tests/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ use std::path::Path;
use std::process::Command;

macro_rules! codegen_test {
// TODO: should fix this test
(lift_lower_foreign $name:tt $test:tt) => {};
(unused_import $name:tt $test:tt) => {};
(issue544 $name:tt $test:tt) => {};
(issue551 $name:tt $test:tt) => {};

($id:ident $name:tt $test:tt) => {
#[test]
fn $id() {
Expand Down
10 changes: 10 additions & 0 deletions tests/codegen/zero-size-tuple.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package foo:foo

world bindings {
import component
}

interface component {
type value = tuple<>
query-eval: func(q: u64) -> list<value>
}
92 changes: 46 additions & 46 deletions tests/runtime/flavorful/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,122 +7,122 @@ import (
func init() {
n := &FlavorfulImpl{}
SetFlavorful(n)
SetExports(n)
SetExportsTestFlavorfulTest(n)
}

type FlavorfulImpl struct{}

func (f FlavorfulImpl) TestImports() {

ImportsFListInRecord1(ImportsListInRecord1{"list_in_record1"})
if ImportsFListInRecord2().A != "list_in_record2" {
panic("ImportsFListInRecord2")
TestFlavorfulTestFListInRecord1(TestFlavorfulTestListInRecord1{"list_in_record1"})
if TestFlavorfulTestFListInRecord2().A != "list_in_record2" {
panic("TestFlavorfulTestFListInRecord2")
}
if ImportsFListInRecord3(ImportsListInRecord3{"list_in_record3 input"}).A != "list_in_record3 output" {
panic("ImportsFListInRecord3")
if TestFlavorfulTestFListInRecord3(TestFlavorfulTestListInRecord3{"list_in_record3 input"}).A != "list_in_record3 output" {
panic("TestFlavorfulTestFListInRecord3")
}
if ImportsFListInRecord4(ImportsListInAlias{"input4"}).A != "result4" {
panic("ImportsFListInRecord4")
if TestFlavorfulTestFListInRecord4(TestFlavorfulTestListInAlias{"input4"}).A != "result4" {
panic("TestFlavorfulTestFListInRecord4")
}

var b Result[struct{}, string]
b.SetErr("bar")
ImportsFListInVariant1(Some[string]("foo"), b, ImportsListInVariant1V3F0("baz"))
if ImportsFListInVariant2().Unwrap() != "list_in_variant2" {
panic("ImportsFListInVariant2")
TestFlavorfulTestFListInVariant1(Some[string]("foo"), b, TestFlavorfulTestListInVariant1V3F0("baz"))
if TestFlavorfulTestFListInVariant2().Unwrap() != "list_in_variant2" {
panic("TestFlavorfulTestFListInVariant2")
}
if ImportsFListInVariant3(Some[string]("input3")).Unwrap() != "output3" {
panic("ImportsFListInVariant3")
if TestFlavorfulTestFListInVariant3(Some[string]("input3")).Unwrap() != "output3" {
panic("TestFlavorfulTestFListInVariant3")
}
if !ImportsErrnoResult().IsErr() {
panic("ImportsErrnoResult")
if !TestFlavorfulTestErrnoResult().IsErr() {
panic("TestFlavorfulTestErrnoResult")
}
ImportsMyErrnoA()
TestFlavorfulTestMyErrnoA()
// TODO: be able to print my_error_a

if !ImportsErrnoResult().IsOk() {
panic("ImportsErrnoResult")
if !TestFlavorfulTestErrnoResult().IsOk() {
panic("TestFlavorfulTestErrnoResult")
}

t1, t2 := ImportsListTypedefs("typedef1", []string{"typedef2"})
t1, t2 := TestFlavorfulTestListTypedefs("typedef1", []string{"typedef2"})
if len(t1) != 8 {
panic("ImportsListTypedefs")
panic("TestFlavorfulTestListTypedefs")
}
if len(t2) != 1 {
panic("ImportsListTypedefs")
panic("TestFlavorfulTestListTypedefs")
}
if t2[0] != "typedef4" {
panic("ImportsListTypedefs")
panic("TestFlavorfulTestListTypedefs")
}

var v2_ok Result[struct{}, struct{}]
v2_ok.Set(struct{}{})
var v2_err Result[struct{}, struct{}]
v2_err.SetErr(struct{}{})

v1, v2, v3 := ImportsListOfVariants(
v1, v2, v3 := TestFlavorfulTestListOfVariants(
[]bool{true, false},
[]Result[struct{}, struct{}]{v2_ok, v2_err},
[]ImportsMyErrno{ImportsMyErrnoSuccess(), ImportsMyErrnoA()},
[]TestFlavorfulTestMyErrno{TestFlavorfulTestMyErrnoSuccess(), TestFlavorfulTestMyErrnoA()},
)
if v1[0] != false {
panic("ImportsListOfVariants")
panic("TestFlavorfulTestListOfVariants")
}
if v1[1] != true {
panic("ImportsListOfVariants")
panic("TestFlavorfulTestListOfVariants")
}
if v2[0].IsOk() {
panic("ImportsListOfVariants")
panic("TestFlavorfulTestListOfVariants")
}
if v2[1].IsErr() {
panic("ImportsListOfVariants")
panic("TestFlavorfulTestListOfVariants")
}
if v3[0].Kind() != ImportsMyErrnoKindA {
panic("ImportsListOfVariants")
if v3[0].Kind() != TestFlavorfulTestMyErrnoKindA {
panic("TestFlavorfulTestListOfVariants")
}
if v3[1].Kind() != ImportsMyErrnoKindB {
panic("ImportsListOfVariants")
if v3[1].Kind() != TestFlavorfulTestMyErrnoKindB {
panic("TestFlavorfulTestListOfVariants")
}

}

func (f FlavorfulImpl) FListInRecord1(a ExportsListInRecord1) {
func (f FlavorfulImpl) FListInRecord1(a TestFlavorfulTestListInRecord1) {
if a.A != "list_in_record1" {
panic("FListInRecord1")
}
}

func (f FlavorfulImpl) FListInRecord2() ExportsListInRecord2 {
return ExportsListInRecord2{"list_in_record2"}
func (f FlavorfulImpl) FListInRecord2() TestFlavorfulTestListInRecord2 {
return TestFlavorfulTestListInRecord2{"list_in_record2"}
}

func (f FlavorfulImpl) FListInRecord3(a ExportsListInRecord3) ExportsListInRecord3 {
func (f FlavorfulImpl) FListInRecord3(a TestFlavorfulTestListInRecord3) TestFlavorfulTestListInRecord3 {
if a.A != "list_in_record3 input" {
panic("FListInRecord3")
}
return ExportsListInRecord3{"list_in_record3 output"}
return TestFlavorfulTestListInRecord3{"list_in_record3 output"}
}

func (f FlavorfulImpl) FListInRecord4(a ExportsListInRecord4) ExportsListInRecord4 {
func (f FlavorfulImpl) FListInRecord4(a TestFlavorfulTestListInRecord4) TestFlavorfulTestListInRecord4 {
if a.A != "input4" {
panic("FListInRecord4")
}
return ExportsListInRecord4{"result4"}
return TestFlavorfulTestListInRecord4{"result4"}
}

func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, string], c ExportsListInVariant1V3) {
func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, string], c TestFlavorfulTestListInVariant1V3) {
if a.Unwrap() != "foo" {
panic("FListInVariant1")
}
if b.UnwrapErr() != "bar" {
panic("FListInVariant1")
}
switch c.Kind() {
case ExportsListInVariant1V3KindF0:
case TestFlavorfulTestListInVariant1V3KindF0:
if c.GetF0() != "baz" {
panic("FListInVariant1")
}
case ExportsListInVariant1V3KindF1:
case TestFlavorfulTestListInVariant1V3KindF1:
panic("FListInVariant1")
}
}
Expand All @@ -138,9 +138,9 @@ func (f FlavorfulImpl) FListInVariant3(a Option[string]) Option[string] {
return Some[string]("output3")
}

func (f FlavorfulImpl) ErrnoResult() Result[struct{}, ExportsMyErrno] {
var res Result[struct{}, ExportsMyErrno]
res.SetErr(ExportsMyErrnoB())
func (f FlavorfulImpl) ErrnoResult() Result[struct{}, TestFlavorfulTestMyErrno] {
var res Result[struct{}, TestFlavorfulTestMyErrno]
res.SetErr(TestFlavorfulTestMyErrnoB())
return res
}

Expand All @@ -157,7 +157,7 @@ func (f FlavorfulImpl) ListTypedefs(a string, c []string) ([]uint8, []string) {
return []uint8("typedef3"), []string{"typedef4"}
}

func (f FlavorfulImpl) ListOfVariants(a []bool, b []Result[struct{}, struct{}], c []ExportsMyErrno) ([]bool, []Result[struct{}, struct{}], []ExportsMyErrno) {
func (f FlavorfulImpl) ListOfVariants(a []bool, b []Result[struct{}, struct{}], c []TestFlavorfulTestMyErrno) ([]bool, []Result[struct{}, struct{}], []TestFlavorfulTestMyErrno) {
return a, b, c
}

Expand Down
96 changes: 48 additions & 48 deletions tests/runtime/lists/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,123 +8,123 @@ import (
func init() {
a := ListImpl{}
SetLists(a)
SetExports(a)
SetExportsTestListsTest(a)
}

type ListImpl struct {
}

func (i ListImpl) TestImports() {
ImportsEmptyListParam([]uint8{})
ImportsEmptyStringParam("")
res := ImportsEmptyListResult()
TestListsTestEmptyListParam([]uint8{})
TestListsTestEmptyStringParam("")
res := TestListsTestEmptyListResult()
if len(res) != 0 {
panic("ImportsEmptyListResult")
panic("TestListsTestEmptyListResult")
}
res2 := ImportsEmptyStringResult()
res2 := TestListsTestEmptyStringResult()
if res2 != "" {
panic("ImportsEmptyStringResult")
panic("TestListsTestEmptyStringResult")
}
ImportsListParam([]uint8{1, 2, 3, 4})
ImportsListParam2("foo")
ImportsListParam3([]string{"foo", "bar", "baz"})
ImportsListParam4([][]string{{"foo", "bar"}, {"baz"}})
res3 := ImportsListResult()
TestListsTestListParam([]uint8{1, 2, 3, 4})
TestListsTestListParam2("foo")
TestListsTestListParam3([]string{"foo", "bar", "baz"})
TestListsTestListParam4([][]string{{"foo", "bar"}, {"baz"}})
res3 := TestListsTestListResult()
if len(res3) != 5 {
panic("ImportsListResult")
panic("TestListsTestListResult")
}
for i := range res3 {
if res3[i] != uint8(i+1) {
panic("ImportsListResult")
panic("TestListsTestListResult")
}
}
res4 := ImportsListResult2()
res4 := TestListsTestListResult2()
if res4 != "hello!" {
panic("ImportsListResult2")
panic("TestListsTestListResult2")
}
res5 := ImportsListResult3()
res5 := TestListsTestListResult3()
if len(res5) != 2 {
panic("ImportsListResult3")
panic("TestListsTestListResult3")
}
if res5[0] != "hello," {
panic("ImportsListResult3")
panic("TestListsTestListResult3")
}
if res5[1] != "world!" {
panic("ImportsListResult3")
panic("TestListsTestListResult3")
}

res6 := ImportsListRoundtrip([]uint8{})
res6 := TestListsTestListRoundtrip([]uint8{})
if len(res6) != 0 {
panic("ImportsListRoundtrip")
panic("TestListsTestListRoundtrip")
}
res7 := ImportsListRoundtrip([]uint8{1, 2, 3, 4, 5})
res7 := TestListsTestListRoundtrip([]uint8{1, 2, 3, 4, 5})
if len(res7) != 5 {
panic("ImportsListRoundtrip")
panic("TestListsTestListRoundtrip")
}

res8 := ImportsStringRoundtrip("")
res8 := TestListsTestStringRoundtrip("")
if res8 != "" {
panic("ImportsStringRoundtrip")
panic("TestListsTestStringRoundtrip")
}
res9 := ImportsStringRoundtrip("hello ⚑ world")
res9 := TestListsTestStringRoundtrip("hello ⚑ world")
if res9 != "hello ⚑ world" {
panic("ImportsStringRoundtrip")
panic("TestListsTestStringRoundtrip")
}

u8, i8 := ImportsListMinmax8([]uint8{0, math.MaxUint8}, []int8{math.MinInt8, math.MaxInt8})
u8, i8 := TestListsTestListMinmax8([]uint8{0, math.MaxUint8}, []int8{math.MinInt8, math.MaxInt8})
if u8[0] != uint8(0) {
panic("ImportsListMinmax8")
panic("TestListsTestListMinmax8")
}
if u8[1] != math.MaxUint8 {
panic("ImportsListMinmax8")
panic("TestListsTestListMinmax8")
}
if i8[0] != math.MinInt8 {
panic("ImportsListMinmax8")
panic("TestListsTestListMinmax8")
}
if i8[1] != math.MaxInt8 {
panic("ImportsListMinmax8")
panic("TestListsTestListMinmax8")
}

u16, i16 := ImportsListMinmax16([]uint16{0, math.MaxUint16}, []int16{math.MinInt16, math.MaxInt16})
u16, i16 := TestListsTestListMinmax16([]uint16{0, math.MaxUint16}, []int16{math.MinInt16, math.MaxInt16})
if u16[0] != uint16(0) {
panic("ImportsListMinmax16")
panic("TestListsTestListMinmax16")
}
if u16[1] != math.MaxUint16 {
panic("ImportsListMinmax16")
panic("TestListsTestListMinmax16")
}
if i16[0] != math.MinInt16 {
panic("ImportsListMinmax16")
panic("TestListsTestListMinmax16")
}
if i16[1] != math.MaxInt16 {
panic("ImportsListMinmax16")
panic("TestListsTestListMinmax16")
}

u32, i32 := ImportsListMinmax32([]uint32{0, math.MaxUint32}, []int32{math.MinInt32, math.MaxInt32})
u32, i32 := TestListsTestListMinmax32([]uint32{0, math.MaxUint32}, []int32{math.MinInt32, math.MaxInt32})
if u32[0] != uint32(0) {
panic("ImportsListMinmax32")
panic("TestListsTestListMinmax32")
}
if u32[1] != math.MaxUint32 {
panic("ImportsListMinmax32")
panic("TestListsTestListMinmax32")
}
if i32[0] != math.MinInt32 {
panic("ImportsListMinmax32")
panic("TestListsTestListMinmax32")
}
if i32[1] != math.MaxInt32 {
panic("ImportsListMinmax32")
panic("TestListsTestListMinmax32")
}

u64, i64 := ImportsListMinmax64([]uint64{0, math.MaxUint64}, []int64{math.MinInt64, math.MaxInt64})
u64, i64 := TestListsTestListMinmax64([]uint64{0, math.MaxUint64}, []int64{math.MinInt64, math.MaxInt64})
if u64[0] != uint64(0) {
panic("ImportsListMinmax64")
panic("TestListsTestListMinmax64")
}
if u64[1] != math.MaxUint64 {
panic("ImportsListMinmax64")
panic("TestListsTestListMinmax64")
}
if i64[0] != math.MinInt64 {
panic("ImportsListMinmax64")
panic("TestListsTestListMinmax64")
}
if i64[1] != math.MaxInt64 {
panic("ImportsListMinmax64")
panic("TestListsTestListMinmax64")
}

}
Expand Down
5 changes: 1 addition & 4 deletions tests/runtime/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ fn tests(name: &str) -> Result<Vec<PathBuf>> {
}

#[cfg(feature = "go")]
if !go.is_empty()
// FIXME: needs fixing after #545
&& false
{
if !go.is_empty() {
let world_name = &resolve.worlds[world].name;
let out_dir = out_dir.join(format!("go-{}", world_name));
drop(fs::remove_dir_all(&out_dir));
Expand Down
Loading