Skip to content

Commit

Permalink
add stdlib tests back
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Nov 19, 2024
1 parent d351434 commit b236499
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: examples
on:
pull_request:
push:
branches: [ "master" ]
branches: ["master"]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down Expand Up @@ -48,6 +48,9 @@ jobs:
echo "LOG_PATH_DIR=$LOG_PATH_DIR" >> $GITHUB_ENV
- run: go install -v ./gnovm/cmd/gno
- run: go run ./gnovm/cmd/gno test -v -print-runtime-metrics -print-events ./examples/...
# TODO: move this to be a normal test within pkg/gnolang, after moving cmd/go's
# testing system to pkg/test.
- run: go run ./gnovm/cmd/gno test -v -print-runtime-metrics -print-events ./stdlibs/...
lint:
strategy:
fail-fast: false
Expand All @@ -70,7 +73,7 @@ jobs:
strategy:
fail-fast: false
matrix:
goversion: [ "1.22.x" ]
goversion: ["1.22.x"]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
Expand All @@ -86,7 +89,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [ "1.22.x" ]
go-version: ["1.22.x"]
# unittests: TODO: matrix with contracts
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down
43 changes: 22 additions & 21 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"path"
"path/filepath"
"runtime/debug"
"sort"
"strings"
"text/template"
Expand All @@ -28,6 +29,7 @@ import (
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/errors"
"github.com/gnolang/gno/tm2/pkg/random"
"github.com/gnolang/gno/tm2/pkg/store/types"

Check failure on line 32 in gnovm/cmd/gno/test.go

View workflow job for this annotation

GitHub Actions / Run Main / Go Linter / lint

ST1019: package "github.com/gnolang/gno/tm2/pkg/store/types" is being imported more than once (stylecheck)
storetypes "github.com/gnolang/gno/tm2/pkg/store/types"

Check failure on line 33 in gnovm/cmd/gno/test.go

View workflow job for this annotation

GitHub Actions / Run Main / Go Linter / lint

ST1019(related information): other import of "github.com/gnolang/gno/tm2/pkg/store/types" (stylecheck)
)

Expand Down Expand Up @@ -312,9 +314,15 @@ func (cfg testPkgCfg) gnoTestPkg(
}
testPkgName := getPkgNameFromFileset(ifiles)

// create a common cw/gs for both the `pkg` tests as well as the `pkg_test`
// tests. this allows us to "export" symbols from the pkg tests and
// import them from the `pkg_test` tests.
cw := cfg.baseStore.CacheWrap()
gs := cfg.testStore.BeginTransaction(cw, cw)

// run test files in pkg
if len(tfiles.Files) > 0 {
err := cfg.runTestFiles(memPkg, tfiles, memPkg.Name, memPkg.Path, runFlag)
err := cfg.runTestFiles(memPkg, tfiles, cw, gs, runFlag)
if err != nil {
errs = multierr.Append(errs, err)
}
Expand All @@ -335,7 +343,7 @@ func (cfg testPkgCfg) gnoTestPkg(
memPkg.Name = testPkgName
memPkg.Path = memPkg.Path + "_test"

err := cfg.runTestFiles(memPkg, ifiles, testPkgName, memPkg.Path, runFlag)
err := cfg.runTestFiles(memPkg, ifiles, cw, gs, runFlag)
if err != nil {
errs = multierr.Append(errs, err)
}
Expand Down Expand Up @@ -432,7 +440,7 @@ func pkgPathFromRootDir(pkgPath, rootDir string) string {
func (cfg *testPkgCfg) runTestFiles(
memPkg *gnovm.MemPackage,
files *gno.FileSet,
pkgName, pkgPath string,
cw types.Store, gs gno.TransactionStore,
runFlag string,
) (errs error) {
var m *gno.Machine
Expand All @@ -441,25 +449,26 @@ func (cfg *testPkgCfg) runTestFiles(
if st := m.ExceptionsStacktrace(); st != "" {
errs = multierr.Append(errors.New(st), errs)
}
errs = multierr.Append(fmt.Errorf("panic: %v\nstack:\n%v\ngno machine: %v", r, m.Stacktrace(), m.String()), errs)
errs = multierr.Append(
fmt.Errorf("panic: %v\ngo stacktrace:\n%v\ngno machine: %v\ngno stacktrace:\n%v",
r, string(debug.Stack()), m.String(), m.Stacktrace()),
errs,
)

Check warning on line 456 in gnovm/cmd/gno/test.go

View check run for this annotation

Codecov / codecov/patch

gnovm/cmd/gno/test.go#L449-L456

Added lines #L449 - L456 were not covered by tests
}
}()

testFuncs := &testFuncs{
PackageName: pkgName,
PackageName: memPkg.Name,
Verbose: cfg.verbose,
RunFlag: runFlag,
}
loadTestFuncs(pkgName, testFuncs, files)
loadTestFuncs(memPkg.Name, testFuncs, files)

testmain, err := formatTestmain(testFuncs)
if err != nil {
log.Fatal(err)
}

// Create a cache/tx wrap so we don't persist what happens in the test.
cw := cfg.baseStore.CacheWrap()
gs := cfg.testStore.BeginTransaction(cw, cw)
var alloc *gno.Allocator

// run package and write to upper cw / gs
Expand All @@ -468,24 +477,16 @@ func (cfg *testPkgCfg) runTestFiles(
}
// Check if we already have the package - it may have been eagerly
// loaded.
m = test.Machine(gs, cfg.outWriter, pkgPath)
m = test.Machine(gs, cfg.outWriter, memPkg.Path)
m.Alloc = alloc
if cfg.testStore.GetMemPackage(pkgPath) == nil {
if cfg.testStore.GetMemPackage(memPkg.Path) == nil {
m.RunMemPackage(memPkg, true)
} else {
// ensure to set the active
m.SetActivePackage(gs.GetPackage(pkgPath, false))
// ensure to set the active package.
m.SetActivePackage(gs.GetPackage(memPkg.Path, false))
}
pv := m.Package

// TODO(monday): a few problems so far:
// 1. One thing I forgot is that I should test to make sure non-monorepo
// workflows still work correctly.
// 2. The standard libraries test don't work properly. I think this is
// 3. We still need to add a workflow to test standard libraries.
// This could probably just be another test in pkg/gnolang/file_test.go,
// improving our coverage.

m.RunFiles(files.Files...)
n := gno.MustParseFile("main_test.gno", testmain)
m.RunFiles(n)
Expand Down

0 comments on commit b236499

Please sign in to comment.