â The only assertion library that works with TinyGo
The only assertion library that works with TinyGo.
Features:
go get github.com/orsinium-labs/tinytest
import (
"testing"
"github.com/orsinium-labs/tinytest/is"
)
func TestHello(t *testing.T) {
c := is.NewRelaxed(t)
is.Equal(c, hello(), "Hello world!")
}
Running tests:
tinygo test ./...
If you want to negate the check, wrap c
into is.Not:
// asserts that the string is not empty
is.Equal(is.Not(c), hello(), "")
If you want to provide an additional error message, use t.Log or t.Logf:
t.Log("greet Joe")
is.Equal(c, Greet("Joe"), "Hello, Joe")
Or t.Run to run a subtest with the given name:
t.Run("greet_joe", func(t *testing.T) {
is.Equal(c, Greet("Joe"), "Hello, Joe")
})
ð Check out documentation for the list of available assertions.
If you try to call t.FailNow from TinyGo tests, you'll get the following error message:
FailNow is incomplete, requires runtime.Goexit()
Which means that currently calling FailNow
does not interrupt the tests. For this reason, tinytest provides only NewRelaxed function that configures all assertions to use Fail
instead of FailNow
and do not interrupt tests on failures. In future versions, we might to find a workaround for this limitation and then tinytest will also provide a New
function that interrupts the tests immediately.
As a workaround, you can explicitly check at critical points if the test has failed and interrupt execution:
if t.Failed() {
return
}