Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 59403c7

Browse files
authored
Print descriptive error message on startup when TinyGo flags are not set (#12)
1 parent e828d17 commit 59403c7

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

finalizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright wasilibs authors
22
// SPDX-License-Identifier: MIT
33

4-
//go:build nottinygc_finalizer
4+
//go:build gc.custom && nottinygc_finalizer
55

66
package nottinygc
77

gc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright wasilibs authors
22
// SPDX-License-Identifier: MIT
33

4+
//go:build gc.custom
5+
46
package nottinygc
57

68
import (

gc_notcustom.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright wasilibs authors
2+
// SPDX-License-Identifier: MIT
3+
4+
//go:build !gc.custom
5+
6+
package nottinygc
7+
8+
func init() {
9+
panic("nottinygc requires passing -gc=custom and -tags=custommalloc to TinyGo when compiling.\nhttps://github.com/wasilibs/nottinygc#usage")
10+
}

magefiles/magefile.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"bytes"
78
"errors"
89
"fmt"
910
"io"
@@ -27,7 +28,19 @@ func Test() error {
2728
tags = append(tags, "nottinygc_finalizer")
2829
}
2930

30-
return sh.RunV("tinygo", "test", "-gc=custom", fmt.Sprintf("-tags='%s'", strings.Join(tags, " ")), "-target=wasi", "-v", "-scheduler=none", "./...")
31+
if err := sh.RunV("tinygo", "test", "-gc=custom", fmt.Sprintf("-tags='%s'", strings.Join(tags, " ")), "-target=wasi", "-v", "-scheduler=none", "./..."); err != nil {
32+
return err
33+
}
34+
35+
var stdout bytes.Buffer
36+
if _, err := sh.Exec(map[string]string{}, &stdout, io.Discard, "tinygo", "test", "-target=wasi", "-v", "-scheduler=none", "./..."); err == nil {
37+
return errors.New("expected tinygo test to fail without -gc=custom")
38+
}
39+
if s := stdout.String(); !strings.Contains(s, "nottinygc requires passing -gc=custom and -tags=custommalloc to TinyGo when compiling") {
40+
return fmt.Errorf("unexpected error message: %s", s)
41+
}
42+
43+
return nil
3144
}
3245

3346
func Format() error {

0 commit comments

Comments
 (0)