diff --git a/finalizer.go b/finalizer.go index 7429922..56dfb9f 100644 --- a/finalizer.go +++ b/finalizer.go @@ -1,7 +1,7 @@ // Copyright wasilibs authors // SPDX-License-Identifier: MIT -//go:build nottinygc_finalizer +//go:build gc.custom && nottinygc_finalizer package nottinygc diff --git a/gc.go b/gc.go index 3378b59..7cbcc4f 100644 --- a/gc.go +++ b/gc.go @@ -1,6 +1,8 @@ // Copyright wasilibs authors // SPDX-License-Identifier: MIT +//go:build gc.custom + package nottinygc import ( diff --git a/gc_notcustom.go b/gc_notcustom.go new file mode 100644 index 0000000..f15c6bc --- /dev/null +++ b/gc_notcustom.go @@ -0,0 +1,10 @@ +// Copyright wasilibs authors +// SPDX-License-Identifier: MIT + +//go:build !gc.custom + +package nottinygc + +func init() { + panic("nottinygc requires passing -gc=custom and -tags=custommalloc to TinyGo when compiling.\nhttps://github.com/wasilibs/nottinygc#usage") +} diff --git a/magefiles/magefile.go b/magefiles/magefile.go index 56f5d31..15ca06f 100644 --- a/magefiles/magefile.go +++ b/magefiles/magefile.go @@ -4,6 +4,7 @@ package main import ( + "bytes" "errors" "fmt" "io" @@ -27,7 +28,19 @@ func Test() error { tags = append(tags, "nottinygc_finalizer") } - return sh.RunV("tinygo", "test", "-gc=custom", fmt.Sprintf("-tags='%s'", strings.Join(tags, " ")), "-target=wasi", "-v", "-scheduler=none", "./...") + if err := sh.RunV("tinygo", "test", "-gc=custom", fmt.Sprintf("-tags='%s'", strings.Join(tags, " ")), "-target=wasi", "-v", "-scheduler=none", "./..."); err != nil { + return err + } + + var stdout bytes.Buffer + if _, err := sh.Exec(map[string]string{}, &stdout, io.Discard, "tinygo", "test", "-target=wasi", "-v", "-scheduler=none", "./..."); err == nil { + return errors.New("expected tinygo test to fail without -gc=custom") + } + if s := stdout.String(); !strings.Contains(s, "nottinygc requires passing -gc=custom and -tags=custommalloc to TinyGo when compiling") { + return fmt.Errorf("unexpected error message: %s", s) + } + + return nil } func Format() error {