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

Commit

Permalink
Print descriptive error message on startup when TinyGo flags are not …
Browse files Browse the repository at this point in the history
…set (#12)
  • Loading branch information
anuraaga authored Jun 1, 2023
1 parent e828d17 commit 59403c7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion finalizer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright wasilibs authors
// SPDX-License-Identifier: MIT

//go:build nottinygc_finalizer
//go:build gc.custom && nottinygc_finalizer

package nottinygc

Expand Down
2 changes: 2 additions & 0 deletions gc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright wasilibs authors
// SPDX-License-Identifier: MIT

//go:build gc.custom

package nottinygc

import (
Expand Down
10 changes: 10 additions & 0 deletions gc_notcustom.go
Original file line number Diff line number Diff line change
@@ -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")
}
15 changes: 14 additions & 1 deletion magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package main

import (
"bytes"
"errors"
"fmt"
"io"
Expand All @@ -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 {
Expand Down

0 comments on commit 59403c7

Please sign in to comment.