Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion gnovm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ _test.cmd:
.PHONY: test.cmd.coverage
test.cmd.coverage:
$(eval export TXTARCOVERDIR := $(shell mktemp -d --tmpdir gnovm-make.XXXXXXX))
go test ./cmd/... -covermode atomic -test.gocoverdir='$(TXTARCOVERDIR)' $(GOTEST_FLAGS)
go test ./cmd/... ./pkg/... -covermode atomic -test.gocoverdir='$(TXTARCOVERDIR)' $(GOTEST_FLAGS)
@echo "coverage results:"
go tool covdata percent -i="$(TXTARCOVERDIR)"
go tool covdata textfmt -v 1 -i="$(TXTARCOVERDIR)" -o '$(GOTEST_COVER_PROFILE)'
Expand Down
8 changes: 6 additions & 2 deletions gnovm/cmd/gno/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestMain_Gno(t *testing.T) {
}

type testMainCase struct {
name string
args []string
testDir string
simulateExternalRepo bool
Expand Down Expand Up @@ -58,8 +59,11 @@ func testMainCaseRun(t *testing.T, tc []testMainCase) {
stderrShouldBeEmpty := test.stderrShouldContain == "" && test.stderrShouldBe == ""
recoverShouldBeEmpty := test.recoverShouldContain == "" && test.recoverShouldBe == ""

testName := strings.Join(test.args, " ")
testName = strings.ReplaceAll(testName+test.testDir, "/", "~")
testName := test.name
if testName == "" {
testName := strings.Join(test.args, " ")
testName = strings.ReplaceAll(testName+test.testDir, "/", "~")
}

t.Run(testName, func(t *testing.T) {
mockOut := bytes.NewBufferString("")
Expand Down
84 changes: 84 additions & 0 deletions gnovm/cmd/gno/test_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package main

import "testing"

func TestTestApp(t *testing.T) {
tc := []testMainCase{
{
name: "basic test with pass and fail",
args: []string{"test", "-v", "../../tests/integ/test/basic"},
stderrShouldContain: "PASS: TestBasic/greater_than_one",
errShouldBe: "FAIL: 0 build errors, 1 test errors",
},
{
name: "basic test with pass only",
args: []string{"test", "-v", "-run", "TestBasic/greater.*", "../../tests/integ/test/basic"},
stderrShouldContain: "PASS: TestBasic/greater_than_one",
},
{
name: "basic file test with pass only",
args: []string{"test", "-v", "../../tests/integ/test/basic_ft"},
errShouldBe: "FAIL: 0 build errors, 1 test errors",
stdoutShouldContain: "Goodbye from filetest",
stderrShouldContain: "PASS: ../../tests/integ/test/basic_ft/pass_filetest.gno",
},
{
name: "basic file test with pass and fail",
args: []string{"test", "../../tests/integ/test/basic_ft"},
errShouldBe: "FAIL: 0 build errors, 1 test errors",
stderrShouldContain: "FAIL: ../../tests/integ/test/basic_ft/fail_filetest.gno",
},
{
name: "no package to test",
args: []string{"test"},
stderrShouldContain: "? . \t[no test files]",
},
{
name: "invalid pattern triggers targetsFromPatterns error",
args: []string{"test", "**[badpattern"},
errShouldContain: "list targets from patterns",
},
{
name: "nonexistent path results in no packages",
args: []string{"test", "../../tests/integ/test/empty/..."},
stderrShouldContain: "no packages to test",
},
// {
// name: "test times out",
// args: []string{"test", "-v", "-timeout=1ms", "../../tests/integ/test/infinite_loop"},
// stderrShouldContain: "test timed out after 1ms",
// },
{
name: "file in wrong language",
args: []string{"test", "../../tests/integ/test/wrong_lang/file.go"},
errShouldContain: "list sub packages: files must be .gno files",
},
{
name: "sub packages error with malformed modfile",
args: []string{"test", "../../tests/integ/test/broken_mod"},
stderrShouldContain: "WARNING: unable to read package path",
errShouldContain: "FAIL: 0 build errors, 1 test errors",
},
{
name: "directory with no test files",
args: []string{"test", "../../tests/integ/test/empty"},
stderrShouldContain: "../../tests/integ/test/empty \t[no test files]",
},
{
name: "directory with test files containing no tests",
args: []string{"test", "../../tests/integ/test/no_tests"},
stderrShouldContain: "testing: warning: no tests to run",
},
// {`
// name: "lint failure",
// args: []string{"test", "-v", "../../tests/integ/test/type_error"},
// errShouldContain: "FAIL: 0 build errors, 1 test errors", // or whatever type/lint error message you induce
// },`
// {
// name: "foundErr true (but no fatal lint error)",
// args: []string{"test", "-v", "../../tests/integ/test/found_err"},
// stderrShouldContain: "FAIL",
// },
}
testMainCaseRun(t, tc)
}
10 changes: 7 additions & 3 deletions gnovm/pkg/gnolang/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/gnolang/gno/tm2/pkg/store"
)

const (
NoRealmStr = "<no realm>"
)

//----------------------------------------
// Machine

Expand Down Expand Up @@ -1913,7 +1917,7 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue, is
// XXX move this into if debug { ... }
if !fv.IsCrossing() {
// panic; notcrossing
mrpath := "<no realm>"
mrpath := NoRealmStr
if m.Realm != nil {
mrpath = m.Realm.Path
}
Expand All @@ -1935,11 +1939,11 @@ func (m *Machine) PushFrameCall(cx *CallExpr, fv *FuncValue, recv TypedValue, is
// Illegal crossing to external realm.
// (the function was variable and run-time check was necessary).
// panic; not explicit
mrpath := "<no realm>"
mrpath := NoRealmStr
if m.Realm != nil {
mrpath = m.Realm.Path
}
prpath := "<no realm>"
prpath := NoRealmStr
if pv.Realm != nil {
prpath = pv.Realm.Path
}
Expand Down
7 changes: 7 additions & 0 deletions gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,18 @@ func ReadMemPackage(dir string, pkgPath string) (*std.MemPackage, error) {
// exceptions to allowedMemPackageFileExtensions
badFileExtensions := []string{".gen.go"}

// I (Loren) think there's a subtle potential bug here that the filter lets
// rejectedFileExtensions affect allowedFiles in addition to allowedFileExtensions
// when the comments don't indicate that... because none of these can be dynamically
// changed by the caller this bug isn't actually ever exposed.

if IsStdlib(pkgPath) {
// Allows transpilation to work on stdlibs with native fns.
allowedMemPackageFileExtensions = append(allowedMemPackageFileExtensions, ".go")
}

// Should we also filter out "hidden" files according to non-POSIX OSs?

list := make([]string, 0, len(files))
for _, file := range files {
// Ignore directories and hidden files, only include allowed files & extensions,
Expand Down
25 changes: 25 additions & 0 deletions gnovm/pkg/test/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package test_test

import (
"testing"

"github.com/gnolang/gno/gnovm/pkg/test"
)

func TestTestImportError_Error(t *testing.T) {
err := test.TestImportError{PkgPath: "gno.land/foo/bar"}
want := `unknown package path "gno.land/foo/bar"`

if got := err.Error(); got != want {
t.Errorf("Error() = %q, want %q", got, want)
}
}

func TestTestImportError_String(t *testing.T) {
err := test.TestImportError{PkgPath: "gno.land/foo/bar"}
want := `TestImportError("unknown package path \"gno.land/foo/bar\"")`

if got := err.String(); got != want {
t.Errorf("String() = %q, want %q", got, want)
}
}
3 changes: 3 additions & 0 deletions gnovm/pkg/test/filetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
// RunFiletest executes the program in source as a filetest.
// If opts.Sync is enabled, and the filetest's golden output has changed,
// the first string is set to the new generated content of the file.
//
// While runFiletest() is used in production, RunFiletest() is used
// exclusively for unit tests.
func (opts *TestOptions) RunFiletest(fname string, source []byte) (string, error) {
opts.outWriter.w = opts.Output
opts.outWriter.errW = opts.Error
Expand Down
Loading