From 9f128d5f5a17a64b96daa85d5ee751dceffd745a Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Mon, 25 Nov 2024 15:47:12 +0100 Subject: [PATCH] Apply code-review changes Co-Authored-By: Marc Vertes --- gnovm/pkg/gnolang/files_test.go | 2 +- gnovm/pkg/test/filetest.go | 29 ++++++++++++++--------------- gnovm/pkg/test/imports.go | 10 +++++----- gnovm/pkg/test/test.go | 21 ++++++++++++--------- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/gnovm/pkg/gnolang/files_test.go b/gnovm/pkg/gnolang/files_test.go index a02b8e1683b..f1bc87d21d8 100644 --- a/gnovm/pkg/gnolang/files_test.go +++ b/gnovm/pkg/gnolang/files_test.go @@ -61,7 +61,7 @@ func TestFiles(t *testing.T) { subTestName := path[len("files/"):] if strings.HasSuffix(path, "_long.gno") && testing.Short() { t.Run(subTestName, func(t *testing.T) { - t.Log("skipping in -short") + t.Skip("skipping in -short") }) return nil } diff --git a/gnovm/pkg/test/filetest.go b/gnovm/pkg/test/filetest.go index 5c8e170cc6e..12bc9ed7f28 100644 --- a/gnovm/pkg/test/filetest.go +++ b/gnovm/pkg/test/filetest.go @@ -73,10 +73,10 @@ func (opts *TestOptions) runFiletest(filename string, source []byte) (string, er // multiple mismatches occurred. updated := false var returnErr error - // verifies the content against dir.Content; if different, either updates - // dir.Content or appends a new returnErr. + // match verifies the content against dir.Content; if different, + // either updates dir.Content (for opts.Sync) or appends a new returnErr. match := func(dir *Directive, actual string) { - // remove end-of-line spaces, as these are removed from `fmt` in the filetests anyway. + // Remove end-of-line spaces, as these are removed from `fmt` in the filetests anyway. actual = reEndOfLineSpaces.ReplaceAllString(actual, "\n") if dir.Content != actual { if opts.Sync { @@ -93,7 +93,7 @@ func (opts *TestOptions) runFiletest(filename string, source []byte) (string, er // First, check if we have an error, whether we're supposed to get it. if result.Error != "" { - // ensure this error was supposed to happen. + // Ensure this error was supposed to happen. errDirective := dirs.First(DirectiveError) if errDirective == nil { return "", fmt.Errorf("unexpected panic: %s\noutput:\n%s\nstack:\n%v", @@ -185,7 +185,7 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte return runResult{Error: err.Error()} } - // reset and start capturing stdout. + // Reset and start capturing stdout. opts.filetestBuffer.Reset() revert := opts.outWriter.tee(&opts.filetestBuffer) defer revert() @@ -209,10 +209,10 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte } }() - // use last element after / (works also if slash is missing) + // Use last element after / (works also if slash is missing). pkgName := gno.Name(pkgPath[strings.LastIndexByte(pkgPath, '/')+1:]) if !gno.IsRealmPath(pkgPath) { - // simple case - pure package. + // Simple case - pure package. pn := gno.NewPackageNode(pkgName, pkgPath, &gno.FileSet{}) pv := pn.NewPackage() m.Store.SetBlockNode(pn) @@ -222,10 +222,10 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte m.RunFiles(n) m.RunStatement(gno.S(gno.Call(gno.X("main")))) } else { - // realm case. + // Realm case. gno.DisableDebug() // until main call. - // remove filetest from name, as that can lead to the package not being + // Remove filetest from name, as that can lead to the package not being // parsed correctly when using RunMemPackage. filename = strings.ReplaceAll(filename, "_filetest", "") @@ -242,9 +242,9 @@ func (opts *TestOptions) runTest(m *gno.Machine, pkgPath, filename string, conte } orig, tx := m.Store, m.Store.BeginTransaction(nil, nil) m.Store = tx - // run decls and init functions. + // Run decls and init functions. m.RunMemPackage(memPkg, true) - // clear store cache and reconstruct machine from committed info + // Clear store cache and reconstruct machine from committed info // (mimicking on-chain behaviour). tx.Write() m.Store = orig @@ -377,7 +377,7 @@ func ParseDirectives(source io.Reader) (Directives, error) { continue } - // Find if there is a colon (indicating a possible directive) + // Find if there is a colon (indicating a possible directive). subm := reDirectiveLine.FindStringSubmatch(comment) switch { case subm == nil: @@ -390,10 +390,9 @@ func ParseDirectives(source io.Reader) (Directives, error) { last := &parsed[len(parsed)-1] if last.Name == "" { last.Content += txt - continue + } else { + last.Content += comment + "\n" } - // append to last line's content. - last.Content += comment + "\n" case subm[1] != "": // output directive, with content on newlines parsed = append(parsed, Directive{Name: subm[1]}) default: // subm[2] != "", all caps diff --git a/gnovm/pkg/test/imports.go b/gnovm/pkg/test/imports.go index 8311557e786..dabb5644cdd 100644 --- a/gnovm/pkg/test/imports.go +++ b/gnovm/pkg/test/imports.go @@ -59,7 +59,7 @@ func Store( } // gonative exceptions. - // these are values available using gonative; eventually they should all be removed. + // These are values available using gonative; eventually they should all be removed. switch pkgPath { case "os": pkg := gno.NewPackageNode("os", pkgPath, nil) @@ -128,7 +128,7 @@ func Store( return pkg, pkg.NewPackage() } - // load normal stdlib. + // Load normal stdlib. pn, pv = loadStdlib(rootDir, pkgPath, store, stdout) if pn != nil { return @@ -157,7 +157,7 @@ func Store( } db := memdb.NewMemDB() baseStore = dbadapter.StoreConstructor(db, storetypes.StoreOptions{}) - // make a new store + // Make a new store. resStore = gno.NewStore(nil, baseStore, baseStore) resStore.SetPackageGetter(getPackage) resStore.SetNativeStore(teststdlibs.NativeStore) @@ -166,9 +166,9 @@ func Store( func loadStdlib(rootDir, pkgPath string, store gno.Store, stdout io.Writer) (*gno.PackageNode, *gno.PackageValue) { dirs := [...]string{ - // normal stdlib path. + // Normal stdlib path. filepath.Join(rootDir, "gnovm", "stdlibs", pkgPath), - // override path. definitions here override the previous if duplicate. + // Override path. Definitions here override the previous if duplicate. filepath.Join(rootDir, "gnovm", "tests", "stdlibs", pkgPath), } files := make([]string, 0, 32) // pre-alloc 32 as a likely high number of files diff --git a/gnovm/pkg/test/test.go b/gnovm/pkg/test/test.go index 09e8af3da9b..b83af284fa6 100644 --- a/gnovm/pkg/test/test.go +++ b/gnovm/pkg/test/test.go @@ -32,7 +32,8 @@ const ( DefaultHeight = 123 // DefaultTimestamp is the Timestamp value used by default in [Context]. DefaultTimestamp = 1234567890 - // DefaultCaller is the result of gno.DerivePkgAddr("user1.gno") + // DefaultCaller is the result of gno.DerivePkgAddr("user1.gno"), + // used as the default caller in [Context]. DefaultCaller crypto.Bech32Address = "g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm" ) @@ -179,17 +180,19 @@ func Test( var errs error // Stands for "test", "integration test", and "filetest". + // "integration test" are the test files with `package xxx_test` (they are + // not necessarily integration tests, it's just for our internal reference.) tset, itset, itfiles, ftfiles := parseMemPackageTests(opts.TestStore, memPkg) - // testing with *_test.gno + // Testing with *_test.gno if len(tset.Files)+len(itset.Files) > 0 { - // 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 + // 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 := opts.BaseStore.CacheWrap() gs := opts.TestStore.BeginTransaction(cw, cw) - // run test files in pkg + // Run test files in pkg. if len(tset.Files) > 0 { err := opts.runTestFiles(memPkg, tset, cw, gs) if err != nil { @@ -197,7 +200,7 @@ func Test( } } - // test xxx_test pkg + // Test xxx_test pkg. if len(itset.Files) > 0 { itPkg := &gnovm.MemPackage{ Name: memPkg.Name + "_test", @@ -212,7 +215,7 @@ func Test( } } - // testing with *_filetest.gno + // Testing with *_filetest.gno. if len(ftfiles) > 0 { filter := splitRegexp(opts.RunFlag) for _, testFile := range ftfiles { @@ -377,7 +380,7 @@ func (opts *TestOptions) runTestFiles( return errs } -// mirror of stdlibs/testing.Report +// report is a mirror of Gno's stdlibs/testing.Report. type report struct { Failed bool Skipped bool @@ -406,7 +409,7 @@ func loadTestFuncs(pkgName string, tfiles *gno.FileSet) (rt []testFunc) { return } -// parses test files (skipping filetests) in the memPkg. +// parseMemPackageTests parses test files (skipping filetests) in the memPkg. func parseMemPackageTests(store gno.Store, memPkg *gnovm.MemPackage) (tset, itset *gno.FileSet, itfiles, ftfiles []*gnovm.MemFile) { tset = &gno.FileSet{} itset = &gno.FileSet{}