Skip to content
Draft
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
33 changes: 26 additions & 7 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ func execTest(cmd *testCmd, args []string, io commands.IO) error {
args = []string{"."}
}

ctx := context.Background()
var cancel context.CancelFunc
if cmd.timeout > 0 {
ctx, cancel = context.WithTimeout(context.Background(), cmd.timeout)
} else {
cancel = func() {}
}
defer cancel()

// Guess opts.RootDir.
if cmd.rootDir == "" {
cmd.rootDir = gnoenv.RootDir()
Expand All @@ -208,13 +217,6 @@ func execTest(cmd *testCmd, args []string, io commands.IO) error {
return nil
}

if cmd.timeout > 0 {
go func() {
time.Sleep(cmd.timeout)
panic("test timed out after " + cmd.timeout.String())
}()
}

// Set up options to run tests.
stdout := goio.Discard
if cmd.verbose {
Expand All @@ -228,6 +230,7 @@ func execTest(cmd *testCmd, args []string, io commands.IO) error {
opts.Events = cmd.printEvents
opts.Debug = cmd.debug
opts.FailfastFlag = cmd.failfast
opts.Context = ctx
cache := make(gno.TypeCheckCache, 64)

// test.ProdStore() is suitable for type-checking prod (non-test) files.
Expand All @@ -241,6 +244,12 @@ func execTest(cmd *testCmd, args []string, io commands.IO) error {
}

for _, pkg := range pkgs {
if ctx.Err() != nil {
io.ErrPrintfln("INFO: %v", ctx.Err()) // TODO: fix error msg
testErrCount++
return fail()
}

for _, err := range pkg.Errors {
io.ErrPrintfln("%s", err.Error())
buildErrCount++
Expand Down Expand Up @@ -337,6 +346,16 @@ func execTest(cmd *testCmd, args []string, io commands.IO) error {
// Print status with duration.
duration := time.Since(startedAt)
dstr := fmtDuration(duration)

if ctx.Err() == context.DeadlineExceeded {
io.ErrPrintfln("FAIL %s \ttimed out after %s", prettyDir, cmd.timeout.String())
testErrCount++
if cmd.failfast {
return fail()
}
continue
}

if didPanic || didError {
io.ErrPrintfln("FAIL %s \t%s", prettyDir, dstr)
testErrCount++
Expand Down
3 changes: 3 additions & 0 deletions gnovm/pkg/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package test

import (
"bytes"

Check failure on line 5 in gnovm/pkg/test/test.go

View workflow job for this annotation

GitHub Actions / Run GnoVM suite / Go Lint / lint

File is not properly formatted (goimports)

Check failure on line 5 in gnovm/pkg/test/test.go

View workflow job for this annotation

GitHub Actions / Run GnoVM suite / Go Lint / lint

File is not properly formatted (gofmt)
"encoding/json"
"errors"
"fmt"
Expand All @@ -14,6 +14,7 @@
"strconv"
"strings"
"time"
"context"

gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/gnovm/pkg/packages"
Expand Down Expand Up @@ -129,6 +130,8 @@
Error io.Writer
// Debug enables the interactive debugger on gno tests.
Debug bool
// TODO
Context context.Context

// Not set by NewTestOptions:

Expand Down
Loading