From 35d5064179445f789ba3df5eb75014fe24d27acb Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Tue, 4 Jul 2023 02:05:51 +0530 Subject: [PATCH 01/15] Export and rename Pkg fields --- gno.land/cmd/gnoland/start.go | 2 +- gnovm/pkg/gnomod/pkg.go | 62 ++++++++++++----------------------- gnovm/pkg/gnomod/pkg_test.go | 24 +++++++------- 3 files changed, 34 insertions(+), 54 deletions(-) diff --git a/gno.land/cmd/gnoland/start.go b/gno.land/cmd/gnoland/start.go index c2a03c7b046..7257c9d6fa0 100644 --- a/gno.land/cmd/gnoland/start.go +++ b/gno.land/cmd/gnoland/start.go @@ -234,7 +234,7 @@ func makeGenesisDoc( for _, pkg := range nonDraftPkgs { // open files in directory as MemPackage. - memPkg := gno.ReadMemPackage(pkg.Path(), pkg.Name()) + memPkg := gno.ReadMemPackage(pkg.Dir, pkg.Name) var tx std.Tx tx.Msgs = []std.Msg{ vmm.MsgAddPackage{ diff --git a/gnovm/pkg/gnomod/pkg.go b/gnovm/pkg/gnomod/pkg.go index f74b92608c8..27a3f105c41 100644 --- a/gnovm/pkg/gnomod/pkg.go +++ b/gnovm/pkg/gnomod/pkg.go @@ -8,10 +8,10 @@ import ( ) type Pkg struct { - name string - path string - draft bool - requires []string + Dir string // absolute path to package dir + Name string // package name + Requires []string // dependencies + Draft bool // whether the package is a draft } type ( @@ -19,26 +19,6 @@ type ( SortedPkgList []Pkg ) -// Name returns the name of the package. -func (p Pkg) Name() string { - return p.name -} - -// Path returns the path of the package. -func (p Pkg) Path() string { - return p.path -} - -// Draft returns whether the package is a draft. -func (p Pkg) Draft() bool { - return p.draft -} - -// Requires returns the required packages of the package. -func (p Pkg) Requires() []string { - return p.requires -} - // sortPkgs sorts the given packages by their dependencies. func (pl PkgList) Sort() (SortedPkgList, error) { visited := make(map[string]bool) @@ -57,21 +37,21 @@ func (pl PkgList) Sort() (SortedPkgList, error) { // visitNode visits a package's and its dependencies dependencies and adds them to the sorted list. func visitPackage(pkg Pkg, pkgs []Pkg, visited, onStack map[string]bool, sortedPkgs *[]Pkg) error { - if onStack[pkg.name] { - return fmt.Errorf("cycle detected: %s", pkg.name) + if onStack[pkg.Name] { + return fmt.Errorf("cycle detected: %s", pkg.Name) } - if visited[pkg.name] { + if visited[pkg.Name] { return nil } - visited[pkg.name] = true - onStack[pkg.name] = true + visited[pkg.Name] = true + onStack[pkg.Name] = true // Visit package's dependencies - for _, req := range pkg.requires { + for _, req := range pkg.Requires { found := false for _, p := range pkgs { - if p.name != req { + if p.Name != req { continue } if err := visitPackage(p, pkgs, visited, onStack, sortedPkgs); err != nil { @@ -81,11 +61,11 @@ func visitPackage(pkg Pkg, pkgs []Pkg, visited, onStack map[string]bool, sortedP break } if !found { - return fmt.Errorf("missing dependency '%s' for package '%s'", req, pkg.name) + return fmt.Errorf("missing dependency '%s' for package '%s'", req, pkg.Name) } } - onStack[pkg.name] = false + onStack[pkg.Name] = false *sortedPkgs = append(*sortedPkgs, pkg) return nil } @@ -120,10 +100,10 @@ func ListPkgs(root string) (PkgList, error) { } pkgs = append(pkgs, Pkg{ - name: gnoMod.Module.Mod.Path, - path: path, - draft: gnoMod.Draft, - requires: func() []string { + Dir: path, + Name: gnoMod.Module.Mod.Path, + Draft: gnoMod.Draft, + Requires: func() []string { var reqs []string for _, req := range gnoMod.Require { reqs = append(reqs, req.Mod.Path) @@ -147,15 +127,15 @@ func (sp SortedPkgList) GetNonDraftPkgs() SortedPkgList { draft := make(map[string]bool) for _, pkg := range sp { - if pkg.draft { - draft[pkg.name] = true + if pkg.Draft { + draft[pkg.Name] = true continue } dependsOnDraft := false - for _, req := range pkg.requires { + for _, req := range pkg.Requires { if draft[req] { dependsOnDraft = true - draft[pkg.name] = true + draft[pkg.Name] = true break } } diff --git a/gnovm/pkg/gnomod/pkg_test.go b/gnovm/pkg/gnomod/pkg_test.go index e69c4f0351a..587a0bb8f81 100644 --- a/gnovm/pkg/gnomod/pkg_test.go +++ b/gnovm/pkg/gnomod/pkg_test.go @@ -197,7 +197,7 @@ func TestListAndNonDraftPkgs(t *testing.T) { require.NoError(t, err) assert.Equal(t, len(tc.outListPkgs), len(pkgs)) for _, p := range pkgs { - assert.Contains(t, tc.outListPkgs, p.name) + assert.Contains(t, tc.outListPkgs, p.Name) } // Sort packages @@ -208,7 +208,7 @@ func TestListAndNonDraftPkgs(t *testing.T) { nonDraft := sorted.GetNonDraftPkgs() assert.Equal(t, len(tc.outNonDraftPkgs), len(nonDraft)) for _, p := range nonDraft { - assert.Contains(t, tc.outNonDraftPkgs, p.name) + assert.Contains(t, tc.outNonDraftPkgs, p.Name) } }) } @@ -240,30 +240,30 @@ func TestSortPkgs(t *testing.T) { }, { desc: "no_dependencies", in: []Pkg{ - {name: "pkg1", path: "/path/to/pkg1", requires: []string{}}, - {name: "pkg2", path: "/path/to/pkg2", requires: []string{}}, - {name: "pkg3", path: "/path/to/pkg3", requires: []string{}}, + {Name: "pkg1", Dir: "/path/to/pkg1", Requires: []string{}}, + {Name: "pkg2", Dir: "/path/to/pkg2", Requires: []string{}}, + {Name: "pkg3", Dir: "/path/to/pkg3", Requires: []string{}}, }, expected: []string{"pkg1", "pkg2", "pkg3"}, }, { desc: "circular_dependencies", in: []Pkg{ - {name: "pkg1", path: "/path/to/pkg1", requires: []string{"pkg2"}}, - {name: "pkg2", path: "/path/to/pkg2", requires: []string{"pkg1"}}, + {Name: "pkg1", Dir: "/path/to/pkg1", Requires: []string{"pkg2"}}, + {Name: "pkg2", Dir: "/path/to/pkg2", Requires: []string{"pkg1"}}, }, shouldErr: true, }, { desc: "missing_dependencies", in: []Pkg{ - {name: "pkg1", path: "/path/to/pkg1", requires: []string{"pkg2"}}, + {Name: "pkg1", Dir: "/path/to/pkg1", Requires: []string{"pkg2"}}, }, shouldErr: true, }, { desc: "valid_dependencies", in: []Pkg{ - {name: "pkg1", path: "/path/to/pkg1", requires: []string{"pkg2"}}, - {name: "pkg2", path: "/path/to/pkg2", requires: []string{"pkg3"}}, - {name: "pkg3", path: "/path/to/pkg3", requires: []string{}}, + {Name: "pkg1", Dir: "/path/to/pkg1", Requires: []string{"pkg2"}}, + {Name: "pkg2", Dir: "/path/to/pkg2", Requires: []string{"pkg3"}}, + {Name: "pkg3", Dir: "/path/to/pkg3", Requires: []string{}}, }, expected: []string{"pkg3", "pkg2", "pkg1"}, }, @@ -275,7 +275,7 @@ func TestSortPkgs(t *testing.T) { } else { require.NoError(t, err) for i := range tc.expected { - assert.Equal(t, tc.expected[i], sorted[i].name) + assert.Equal(t, tc.expected[i], sorted[i].Name) } } }) From 022d434fdc92d588365658ff7fb3a38feff6015c Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Tue, 4 Jul 2023 20:05:03 +0530 Subject: [PATCH 02/15] Improv 'gno test' to test both pkgs and files --- gnovm/cmd/gno/test.go | 48 +++++++++-------- gnovm/cmd/gno/util.go | 62 ++++++++++++++++++++++ gnovm/pkg/gnomod/pkg.go | 112 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+), 25 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index f5e180e694a..b7f5c2a31bd 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -15,6 +15,7 @@ import ( "time" gno "github.com/gnolang/gno/gnovm/pkg/gnolang" + "github.com/gnolang/gno/gnovm/pkg/gnomod" "github.com/gnolang/gno/gnovm/tests" "github.com/gnolang/gno/tm2/pkg/commands" "github.com/gnolang/gno/tm2/pkg/errors" @@ -133,9 +134,9 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error { cfg.rootDir = guessRootDir() } - pkgPaths, err := gnoPackagesFromArgs(args) + paths, err := gnoPackagePathsFromPattern(args) if err != nil { - return fmt.Errorf("list packages from args: %w", err) + return fmt.Errorf("list package paths from args: %w", err) } if cfg.timeout > 0 { @@ -145,21 +146,26 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error { }() } + subPkgs, err := gnomod.SubPkgsFromPaths(paths) + if err != nil { + return fmt.Errorf("list sub packages: %w", err) + } + buildErrCount := 0 testErrCount := 0 - for _, pkgPath := range pkgPaths { + for _, pkg := range subPkgs { if cfg.precompile { if verbose { - io.ErrPrintfln("=== PREC %s", pkgPath) + io.ErrPrintfln("=== PREC %s", pkg.Dir) } precompileOpts := newPrecompileOptions(&precompileCfg{ output: tempdirRoot, }) - err := precompilePkg(importPath(pkgPath), precompileOpts) + err := precompilePkg(importPath(pkg.Dir), precompileOpts) if err != nil { io.ErrPrintln(err) io.ErrPrintln("FAIL") - io.ErrPrintfln("FAIL %s", pkgPath) + io.ErrPrintfln("FAIL %s", pkg.Dir) io.ErrPrintln("FAIL") buildErrCount++ @@ -167,9 +173,9 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error { } if verbose { - io.ErrPrintfln("=== BUILD %s", pkgPath) + io.ErrPrintfln("=== BUILD %s", pkg.Dir) } - tempDir, err := ResolvePath(tempdirRoot, importPath(pkgPath)) + tempDir, err := ResolvePath(tempdirRoot, importPath(pkg.Dir)) if err != nil { return errors.New("cannot resolve build dir") } @@ -177,7 +183,7 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error { if err != nil { io.ErrPrintln(err) io.ErrPrintln("FAIL") - io.ErrPrintfln("FAIL %s", pkgPath) + io.ErrPrintfln("FAIL %s", pkg.Dir) io.ErrPrintln("FAIL") buildErrCount++ @@ -185,35 +191,27 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error { } } - unittestFiles, err := filepath.Glob(filepath.Join(pkgPath, "*_test.gno")) - if err != nil { - log.Fatal(err) - } - filetestFiles, err := filepath.Glob(filepath.Join(pkgPath, "*_filetest.gno")) - if err != nil { - log.Fatal(err) - } - if len(unittestFiles) == 0 && len(filetestFiles) == 0 { - io.ErrPrintfln("? %s \t[no test files]", pkgPath) + if len(pkg.TestGnoFiles) == 0 && len(pkg.FiletestGnoFiles) == 0 { + io.ErrPrintfln("? %s \t[no test files]", pkg.Dir) continue } - sort.Strings(unittestFiles) - sort.Strings(filetestFiles) + sort.Strings(pkg.TestGnoFiles) + sort.Strings(pkg.FiletestGnoFiles) startedAt := time.Now() - err = gnoTestPkg(pkgPath, unittestFiles, filetestFiles, cfg, io) + err = gnoTestPkg(pkg.Dir, pkg.TestGnoFiles, pkg.FiletestGnoFiles, cfg, io) duration := time.Since(startedAt) dstr := fmtDuration(duration) if err != nil { - io.ErrPrintfln("%s: test pkg: %v", pkgPath, err) + io.ErrPrintfln("%s: test pkg: %v", pkg.Dir, err) io.ErrPrintfln("FAIL") - io.ErrPrintfln("FAIL %s \t%s", pkgPath, dstr) + io.ErrPrintfln("FAIL %s \t%s", pkg.Dir, dstr) io.ErrPrintfln("FAIL") testErrCount++ } else { - io.ErrPrintfln("ok %s \t%s", pkgPath, dstr) + io.ErrPrintfln("ok %s \t%s", pkg.Dir, dstr) } } if testErrCount > 0 || buildErrCount > 0 { diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 1bbdb968c45..bcdc0695957 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -100,6 +100,68 @@ func gnoPackagesFromArgs(args []string) ([]string, error) { return paths, nil } +func gnoPackagePathsFromPattern(patterns []string) ([]string, error) { + paths := []string{} + recursiveLookup := false + for _, p := range patterns { + // TODO: + // - Support more patterns + // - Move this logic to separate helper function? + if strings.HasSuffix(p, "/...") { + recursiveLookup = true + p = strings.TrimSuffix(p, "/...") + } + + info, err := os.Stat(p) + if err != nil { + return nil, fmt.Errorf("invalid file or package path: %w", err) + } + + // if the passed arg is a file, then we'll just add it to the list + if !info.IsDir() { + paths = append(paths, p) + continue + } + // if the passed arg is just dir not followed by /... + if !recursiveLookup { + paths = append(paths, p) + continue + } + + // the passed arg is a dir folllowed by /... then we'll walk the dir recursively + // and look for directories containing at least one .gno file. + visited := map[string]bool{} // used to run the builder only once per folder. + err = filepath.WalkDir(p, func(curpath string, f fs.DirEntry, err error) error { + if err != nil { + return fmt.Errorf("%s: walk dir: %w", p, err) + } + if f.IsDir() { + return nil // skip + } + if !isGnoFile(f) { + return nil // skip + } + + parentDir := filepath.Dir(curpath) + if _, found := visited[parentDir]; found { + return nil + } + visited[parentDir] = true + + // cannot use path.Join or filepath.Join, because we need + // to ensure that ./ is the prefix to pass to go build. + pkg := "./" + parentDir + paths = append(paths, pkg) + return nil + }) + if err != nil { + return nil, err + } + + } + return paths, nil +} + func fmtDuration(d time.Duration) string { return fmt.Sprintf("%.2fs", d.Seconds()) } diff --git a/gnovm/pkg/gnomod/pkg.go b/gnovm/pkg/gnomod/pkg.go index 27a3f105c41..df361695d4c 100644 --- a/gnovm/pkg/gnomod/pkg.go +++ b/gnovm/pkg/gnomod/pkg.go @@ -5,6 +5,7 @@ import ( "io/fs" "os" "path/filepath" + "strings" ) type Pkg struct { @@ -14,6 +15,27 @@ type Pkg struct { Draft bool // whether the package is a draft } +type SubPkg struct { + Dir string // absolute path to package dir + ImportPath string // import path of package + Root string // Root dir containing this package, i.e dir containing gno.mod file + Imports []string // imports used by this package + + GnoFiles []string // .gno source files (excluding TestGnoFiles, FiletestGnoFiles) + TestGnoFiles []string // _test.gno source files + FiletestGnoFiles []string // _filetest.gno source files +} + +// newEmptySubPkg returns a new empty SubPkg. +func newEmptySubPkg() *SubPkg { + return &SubPkg{ + Imports: make([]string, 0), + GnoFiles: make([]string, 0), + TestGnoFiles: make([]string, 0), + FiletestGnoFiles: make([]string, 0), + } +} + type ( PkgList []Pkg SortedPkgList []Pkg @@ -145,3 +167,93 @@ func (sp SortedPkgList) GetNonDraftPkgs() SortedPkgList { } return res } + +// SubPkgsFromPaths returns a list of subpackages from the given paths. +func SubPkgsFromPaths(paths []string) ([]*SubPkg, error) { + for _, path := range paths { + fi, err := os.Stat(path) + if err != nil { + return nil, err + } + if fi.IsDir() { + continue + } + if filepath.Ext(path) != ".gno" { + return nil, fmt.Errorf("files must be .gno files: %s", path) + } + + subPkg, err := GnoFileSubPkg(paths) + if err != nil { + return nil, err + } + return []*SubPkg{subPkg}, nil + } + + var subPkgs []*SubPkg + for _, path := range paths { + subPkg := newEmptySubPkg() + + matches, err := filepath.Glob(filepath.Join(path, "*.gno")) + if err != nil { + return nil, fmt.Errorf("failed to match pattern: %s", err) + } + + for _, match := range matches { + if strings.HasSuffix(match, "_test.gno") { + subPkg.TestGnoFiles = append(subPkg.TestGnoFiles, match) + continue + } + + if strings.HasSuffix(match, "_filetest.gno") { + subPkg.FiletestGnoFiles = append(subPkg.FiletestGnoFiles, match) + continue + } + subPkg.GnoFiles = append(subPkg.GnoFiles, match) + } + + subPkgs = append(subPkgs, subPkg) + } + + return subPkgs, nil +} + +// GnoFileSubPkg returns a subpackage from the given .gno files. +func GnoFileSubPkg(files []string) (*SubPkg, error) { + subPkg := newEmptySubPkg() + firstDir := "" + for _, file := range files { + if filepath.Ext(file) != ".gno" { + return nil, fmt.Errorf("files must be .gno files: %s", file) + } + + fi, err := os.Stat(file) + if err != nil { + return nil, err + } + if fi.IsDir() { + return nil, fmt.Errorf("%s is a directory, should be a Gno file", file) + } + + dir := filepath.Dir(file) + if firstDir == "" { + firstDir = dir + } + if dir != firstDir { + return nil, fmt.Errorf("all files must be in one directory; have %s and %s", firstDir, dir) + } + + if strings.HasSuffix(file, "_test.gno") { + subPkg.TestGnoFiles = append(subPkg.TestGnoFiles, file) + continue + } + + if strings.HasSuffix(file, "_filetest.gno") { + subPkg.FiletestGnoFiles = append(subPkg.FiletestGnoFiles, file) + continue + } + subPkg.GnoFiles = append(subPkg.GnoFiles, file) + } + subPkg.Dir = firstDir + + return subPkg, nil +} From 986a7c80db34cceb1d9d51f202925f840b397443 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Tue, 4 Jul 2023 22:03:29 +0530 Subject: [PATCH 03/15] fix lint errors --- gnovm/cmd/gno/util.go | 1 - gnovm/pkg/gnomod/pkg.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index bcdc0695957..50b2423ea4a 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -157,7 +157,6 @@ func gnoPackagePathsFromPattern(patterns []string) ([]string, error) { if err != nil { return nil, err } - } return paths, nil } diff --git a/gnovm/pkg/gnomod/pkg.go b/gnovm/pkg/gnomod/pkg.go index df361695d4c..90ccc33b13d 100644 --- a/gnovm/pkg/gnomod/pkg.go +++ b/gnovm/pkg/gnomod/pkg.go @@ -189,13 +189,13 @@ func SubPkgsFromPaths(paths []string) ([]*SubPkg, error) { return []*SubPkg{subPkg}, nil } - var subPkgs []*SubPkg + subPkgs := make([]*SubPkg, 0, len(paths)) for _, path := range paths { subPkg := newEmptySubPkg() matches, err := filepath.Glob(filepath.Join(path, "*.gno")) if err != nil { - return nil, fmt.Errorf("failed to match pattern: %s", err) + return nil, fmt.Errorf("failed to match pattern: %w", err) } for _, match := range matches { From 56aecb47611fd6d90299de2a14d4a5ae11c2e4e0 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Wed, 5 Jul 2023 08:57:38 +0530 Subject: [PATCH 04/15] Set subPkg Dir that was inadvertently omitted --- gnovm/pkg/gnomod/pkg.go | 1 + 1 file changed, 1 insertion(+) diff --git a/gnovm/pkg/gnomod/pkg.go b/gnovm/pkg/gnomod/pkg.go index 90ccc33b13d..a2c517c74d1 100644 --- a/gnovm/pkg/gnomod/pkg.go +++ b/gnovm/pkg/gnomod/pkg.go @@ -198,6 +198,7 @@ func SubPkgsFromPaths(paths []string) ([]*SubPkg, error) { return nil, fmt.Errorf("failed to match pattern: %w", err) } + subPkg.Dir = path for _, match := range matches { if strings.HasSuffix(match, "_test.gno") { subPkg.TestGnoFiles = append(subPkg.TestGnoFiles, match) From c037e22f0096924a45bcb0a949713823bafaca69 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Wed, 5 Jul 2023 09:16:31 +0530 Subject: [PATCH 05/15] remove `./` prefix from pkg paths --- gnovm/cmd/gno/util.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 50b2423ea4a..453305208e8 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -148,10 +148,7 @@ func gnoPackagePathsFromPattern(patterns []string) ([]string, error) { } visited[parentDir] = true - // cannot use path.Join or filepath.Join, because we need - // to ensure that ./ is the prefix to pass to go build. - pkg := "./" + parentDir - paths = append(paths, pkg) + paths = append(paths, parentDir) return nil }) if err != nil { From 07cc84230394962b9dc940d2e95b9d3f20120795 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Wed, 5 Jul 2023 09:18:53 +0530 Subject: [PATCH 06/15] fix `gno test` failing tests --- gnovm/cmd/gno/test_test.go | 43 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/gnovm/cmd/gno/test_test.go b/gnovm/cmd/gno/test_test.go index 9059bc365dc..9a835090c94 100644 --- a/gnovm/cmd/gno/test_test.go +++ b/gnovm/cmd/gno/test_test.go @@ -10,19 +10,20 @@ func TestTest(t *testing.T) { }, { args: []string{"test", "../../../examples/gno.land/p/demo/rand"}, - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/rand \t", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/rand \t", }, { args: []string{"test", "../../tests/integ/no-such-dir"}, errShouldContain: "no such file or directory", }, { - args: []string{"test", "../../tests/integ/empty-dir"}, + args: []string{"test", "../../tests/integ/empty-dir"}, + stderrShouldContain: "? ../../tests/integ/empty-dir \t[no test files]", }, { // FIXME: should have an output args: []string{"test", "../../tests/integ/minimalist-gno1"}, - stderrShouldBe: "? ./../../tests/integ/minimalist-gno1 \t[no test files]\n", + stderrShouldBe: "? ../../tests/integ/minimalist-gno1 \t[no test files]\n", }, { args: []string{"test", "../../tests/integ/minimalist-gno2"}, @@ -46,7 +47,7 @@ func TestTest(t *testing.T) { }, { args: []string{"test", "../../tests/integ/empty-gno1"}, - stderrShouldBe: "? ./../../tests/integ/empty-gno1 \t[no test files]\n", + stderrShouldBe: "? ../../tests/integ/empty-gno1 \t[no test files]\n", }, { args: []string{"test", "--precompile", "../../tests/integ/empty-gno1"}, @@ -90,82 +91,82 @@ func TestTest(t *testing.T) { }, { args: []string{"test", "--verbose", "--precompile", "../../tests/integ/failing2"}, - stderrShouldBe: "=== PREC ./../../tests/integ/failing2\n=== BUILD ./../../tests/integ/failing2\n=== RUN file/failing_filetest.gno\n", + stderrShouldBe: "=== PREC ../../tests/integ/failing2\n=== BUILD ../../tests/integ/failing2\n=== RUN file/failing_filetest.gno\n", recoverShouldBe: "fail on ../../tests/integ/failing2/failing_filetest.gno: got unexpected error: beep boop", }, { args: []string{"test", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "NoExists", "../../../examples/gno.land/p/demo/ufmt"}, - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/hello", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/hi", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/NoExists", "../../../examples/gno.land/p/demo/ufmt"}, - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/hello/NoExists", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "Sprintf/", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "Sprintf/.*", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "Sprintf/hello", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--timeout", "1000000s", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "../../tests/integ/native-lib"}, - recoverShouldContain: "./../../tests/integ/native-lib/contract.gno:1: unknown import path net", + recoverShouldContain: "../../tests/integ/native-lib/contract.gno:1: unknown import path net", }, { args: []string{"test", "--verbose", "--with-native-fallback", "../../tests/integ/native-lib"}, - stderrShouldContain: "ok ./../../tests/integ/native-lib", + stderrShouldContain: "ok ../../tests/integ/native-lib", }, { args: []string{"test", "--verbose", "../../tests/integ/unknown-lib"}, - recoverShouldContain: "./../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", + recoverShouldContain: "../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", }, { args: []string{"test", "--verbose", "--with-native-fallback", "../../tests/integ/unknown-lib"}, - recoverShouldContain: "./../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", + recoverShouldContain: "../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", }, { args: []string{"test", "--verbose", "--print-runtime-metrics", "../../../examples/gno.land/p/demo/ufmt"}, From 8c87cc617365e65d26479b324d308867ca6afcf5 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Wed, 5 Jul 2023 09:35:10 +0530 Subject: [PATCH 07/15] Fix makefiles and workflows --- .github/workflows/examples.yml | 2 +- examples/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 83167390254..3730dff0fe7 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -42,5 +42,5 @@ jobs: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v3 - run: go install -v ./gnovm/cmd/gno - - run: go run ./gnovm/cmd/gno test --verbose ./examples + - run: go run ./gnovm/cmd/gno test --verbose ./examples/... # TODO: track coverage diff --git a/examples/Makefile b/examples/Makefile index 59643b66ead..7f19fbdeefe 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -13,11 +13,11 @@ build: precompile .PHONY: test test: - go run ../gnovm/cmd/gno test --verbose . + go run ../gnovm/cmd/gno test --verbose ./... .PHONY: test.sync test.sync: - go run ../gnovm/cmd/gno test --verbose --update-golden-tests . + go run ../gnovm/cmd/gno test --verbose --update-golden-tests ./... .PHONY: clean clean: From 69110130e62635f16878cd4541d8e786d013d0ac Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sat, 8 Jul 2023 00:03:30 +0530 Subject: [PATCH 08/15] Combine conditional statements --- gnovm/cmd/gno/util.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 453305208e8..1b743e84f20 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -117,13 +117,11 @@ func gnoPackagePathsFromPattern(patterns []string) ([]string, error) { return nil, fmt.Errorf("invalid file or package path: %w", err) } - // if the passed arg is a file, then we'll just add it to the list - if !info.IsDir() { - paths = append(paths, p) - continue - } - // if the passed arg is just dir not followed by /... - if !recursiveLookup { + // if the pattern is: + // - a file + // - a dir not followed by /... + // then we'll just add it to the list + if !info.IsDir() || !recursiveLookup { paths = append(paths, p) continue } From 95a335d6263a02b21c018b6c09e0d0624a49a82e Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sat, 8 Jul 2023 00:08:03 +0530 Subject: [PATCH 09/15] Combine conditional stmts --- gnovm/cmd/gno/util.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 1b743e84f20..004963c5c05 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -133,10 +133,7 @@ func gnoPackagePathsFromPattern(patterns []string) ([]string, error) { if err != nil { return fmt.Errorf("%s: walk dir: %w", p, err) } - if f.IsDir() { - return nil // skip - } - if !isGnoFile(f) { + if f.IsDir() || !isGnoFile(f) { return nil // skip } From 1e6ce137ed32cede13816dfee81a893582c2e0ab Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Sat, 8 Jul 2023 00:10:30 +0530 Subject: [PATCH 10/15] reset recursiveLookup for every iteration --- gnovm/cmd/gno/util.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 004963c5c05..3b19cde6432 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -102,8 +102,9 @@ func gnoPackagesFromArgs(args []string) ([]string, error) { func gnoPackagePathsFromPattern(patterns []string) ([]string, error) { paths := []string{} - recursiveLookup := false for _, p := range patterns { + recursiveLookup := false + // TODO: // - Support more patterns // - Move this logic to separate helper function? From 7cb7960ce18941419650a84e717f77e2da166a02 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 13 Jul 2023 00:36:07 +0530 Subject: [PATCH 11/15] remove unnecessary newEmptySubPkg() --- gnovm/pkg/gnomod/pkg.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/gnovm/pkg/gnomod/pkg.go b/gnovm/pkg/gnomod/pkg.go index a2c517c74d1..f6fe7f60301 100644 --- a/gnovm/pkg/gnomod/pkg.go +++ b/gnovm/pkg/gnomod/pkg.go @@ -26,16 +26,6 @@ type SubPkg struct { FiletestGnoFiles []string // _filetest.gno source files } -// newEmptySubPkg returns a new empty SubPkg. -func newEmptySubPkg() *SubPkg { - return &SubPkg{ - Imports: make([]string, 0), - GnoFiles: make([]string, 0), - TestGnoFiles: make([]string, 0), - FiletestGnoFiles: make([]string, 0), - } -} - type ( PkgList []Pkg SortedPkgList []Pkg @@ -191,7 +181,7 @@ func SubPkgsFromPaths(paths []string) ([]*SubPkg, error) { subPkgs := make([]*SubPkg, 0, len(paths)) for _, path := range paths { - subPkg := newEmptySubPkg() + subPkg := SubPkg{} matches, err := filepath.Glob(filepath.Join(path, "*.gno")) if err != nil { @@ -212,7 +202,7 @@ func SubPkgsFromPaths(paths []string) ([]*SubPkg, error) { subPkg.GnoFiles = append(subPkg.GnoFiles, match) } - subPkgs = append(subPkgs, subPkg) + subPkgs = append(subPkgs, &subPkg) } return subPkgs, nil @@ -220,7 +210,7 @@ func SubPkgsFromPaths(paths []string) ([]*SubPkg, error) { // GnoFileSubPkg returns a subpackage from the given .gno files. func GnoFileSubPkg(files []string) (*SubPkg, error) { - subPkg := newEmptySubPkg() + subPkg := SubPkg{} firstDir := "" for _, file := range files { if filepath.Ext(file) != ".gno" { @@ -256,5 +246,5 @@ func GnoFileSubPkg(files []string) (*SubPkg, error) { } subPkg.Dir = firstDir - return subPkg, nil + return &subPkg, nil } From d96e536034547a03a73108985eff4ecbd0b2abcc Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 13 Jul 2023 20:39:17 +0530 Subject: [PATCH 12/15] Remove pattern support --- gnovm/cmd/gno/test.go | 2 +- gnovm/cmd/gno/util.go | 54 ------------------------------------------- 2 files changed, 1 insertion(+), 55 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index b7f5c2a31bd..3505e9ef2d5 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -134,7 +134,7 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error { cfg.rootDir = guessRootDir() } - paths, err := gnoPackagePathsFromPattern(args) + paths, err := gnoPackagesFromArgs(args) if err != nil { return fmt.Errorf("list package paths from args: %w", err) } diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 3b19cde6432..1bbdb968c45 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -100,60 +100,6 @@ func gnoPackagesFromArgs(args []string) ([]string, error) { return paths, nil } -func gnoPackagePathsFromPattern(patterns []string) ([]string, error) { - paths := []string{} - for _, p := range patterns { - recursiveLookup := false - - // TODO: - // - Support more patterns - // - Move this logic to separate helper function? - if strings.HasSuffix(p, "/...") { - recursiveLookup = true - p = strings.TrimSuffix(p, "/...") - } - - info, err := os.Stat(p) - if err != nil { - return nil, fmt.Errorf("invalid file or package path: %w", err) - } - - // if the pattern is: - // - a file - // - a dir not followed by /... - // then we'll just add it to the list - if !info.IsDir() || !recursiveLookup { - paths = append(paths, p) - continue - } - - // the passed arg is a dir folllowed by /... then we'll walk the dir recursively - // and look for directories containing at least one .gno file. - visited := map[string]bool{} // used to run the builder only once per folder. - err = filepath.WalkDir(p, func(curpath string, f fs.DirEntry, err error) error { - if err != nil { - return fmt.Errorf("%s: walk dir: %w", p, err) - } - if f.IsDir() || !isGnoFile(f) { - return nil // skip - } - - parentDir := filepath.Dir(curpath) - if _, found := visited[parentDir]; found { - return nil - } - visited[parentDir] = true - - paths = append(paths, parentDir) - return nil - }) - if err != nil { - return nil, err - } - } - return paths, nil -} - func fmtDuration(d time.Duration) string { return fmt.Sprintf("%.2fs", d.Seconds()) } From 9d42cc01491357726adb91224e9f286ad50b46b8 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 13 Jul 2023 21:14:23 +0530 Subject: [PATCH 13/15] Fix failing tests --- .github/workflows/examples.yml | 2 +- examples/Makefile | 4 ++-- gnovm/cmd/gno/test.go | 4 ++++ gnovm/cmd/gno/test_test.go | 42 +++++++++++++++++----------------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 3730dff0fe7..83167390254 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -42,5 +42,5 @@ jobs: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v3 - run: go install -v ./gnovm/cmd/gno - - run: go run ./gnovm/cmd/gno test --verbose ./examples/... + - run: go run ./gnovm/cmd/gno test --verbose ./examples # TODO: track coverage diff --git a/examples/Makefile b/examples/Makefile index 7f19fbdeefe..59643b66ead 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -13,11 +13,11 @@ build: precompile .PHONY: test test: - go run ../gnovm/cmd/gno test --verbose ./... + go run ../gnovm/cmd/gno test --verbose . .PHONY: test.sync test.sync: - go run ../gnovm/cmd/gno test --verbose --update-golden-tests ./... + go run ../gnovm/cmd/gno test --verbose --update-golden-tests . .PHONY: clean clean: diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 3505e9ef2d5..7abd605a293 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -138,6 +138,10 @@ func execTest(cfg *testCfg, args []string, io *commands.IO) error { if err != nil { return fmt.Errorf("list package paths from args: %w", err) } + if len(paths) == 0 { + io.ErrPrintln("no packages to test") + return nil + } if cfg.timeout > 0 { go func() { diff --git a/gnovm/cmd/gno/test_test.go b/gnovm/cmd/gno/test_test.go index 9a835090c94..7968938751d 100644 --- a/gnovm/cmd/gno/test_test.go +++ b/gnovm/cmd/gno/test_test.go @@ -10,7 +10,7 @@ func TestTest(t *testing.T) { }, { args: []string{"test", "../../../examples/gno.land/p/demo/rand"}, - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/rand \t", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/rand \t", }, { args: []string{"test", "../../tests/integ/no-such-dir"}, @@ -18,12 +18,12 @@ func TestTest(t *testing.T) { }, { args: []string{"test", "../../tests/integ/empty-dir"}, - stderrShouldContain: "? ../../tests/integ/empty-dir \t[no test files]", + stderrShouldContain: "no packages to test", }, { // FIXME: should have an output args: []string{"test", "../../tests/integ/minimalist-gno1"}, - stderrShouldBe: "? ../../tests/integ/minimalist-gno1 \t[no test files]\n", + stderrShouldBe: "? ./../../tests/integ/minimalist-gno1 \t[no test files]\n", }, { args: []string{"test", "../../tests/integ/minimalist-gno2"}, @@ -47,7 +47,7 @@ func TestTest(t *testing.T) { }, { args: []string{"test", "../../tests/integ/empty-gno1"}, - stderrShouldBe: "? ../../tests/integ/empty-gno1 \t[no test files]\n", + stderrShouldBe: "? ./../../tests/integ/empty-gno1 \t[no test files]\n", }, { args: []string{"test", "--precompile", "../../tests/integ/empty-gno1"}, @@ -91,82 +91,82 @@ func TestTest(t *testing.T) { }, { args: []string{"test", "--verbose", "--precompile", "../../tests/integ/failing2"}, - stderrShouldBe: "=== PREC ../../tests/integ/failing2\n=== BUILD ../../tests/integ/failing2\n=== RUN file/failing_filetest.gno\n", + stderrShouldBe: "=== PREC ./../../tests/integ/failing2\n=== BUILD ./../../tests/integ/failing2\n=== RUN file/failing_filetest.gno\n", recoverShouldBe: "fail on ../../tests/integ/failing2/failing_filetest.gno: got unexpected error: beep boop", }, { args: []string{"test", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "NoExists", "../../../examples/gno.land/p/demo/ufmt"}, - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/hello", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/hi", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/NoExists", "../../../examples/gno.land/p/demo/ufmt"}, - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", ".*/hello/NoExists", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "Sprintf/", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "Sprintf/.*", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--run", "Sprintf/hello", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "--timeout", "1000000s", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf", - stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, { args: []string{"test", "--verbose", "../../tests/integ/native-lib"}, - recoverShouldContain: "../../tests/integ/native-lib/contract.gno:1: unknown import path net", + recoverShouldContain: "./../../tests/integ/native-lib/contract.gno:1: unknown import path net", }, { args: []string{"test", "--verbose", "--with-native-fallback", "../../tests/integ/native-lib"}, - stderrShouldContain: "ok ../../tests/integ/native-lib", + stderrShouldContain: "ok ./../../tests/integ/native-lib", }, { args: []string{"test", "--verbose", "../../tests/integ/unknown-lib"}, - recoverShouldContain: "../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", + recoverShouldContain: "./../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", }, { args: []string{"test", "--verbose", "--with-native-fallback", "../../tests/integ/unknown-lib"}, - recoverShouldContain: "../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", + recoverShouldContain: "./../../tests/integ/unknown-lib/contract.gno:1: unknown import path foobarbaz", }, { args: []string{"test", "--verbose", "--print-runtime-metrics", "../../../examples/gno.land/p/demo/ufmt"}, From 65f9d1e4c1e46138cf7a1fb658e0f4224d0bd8bc Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 13 Jul 2023 21:35:51 +0530 Subject: [PATCH 14/15] append `./` only if path is not absolute --- gnovm/cmd/gno/util.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gnovm/cmd/gno/util.go b/gnovm/cmd/gno/util.go index 1bbdb968c45..d61f654dfd8 100644 --- a/gnovm/cmd/gno/util.go +++ b/gnovm/cmd/gno/util.go @@ -86,9 +86,14 @@ func gnoPackagesFromArgs(args []string) ([]string, error) { } visited[parentDir] = true - // cannot use path.Join or filepath.Join, because we need - // to ensure that ./ is the prefix to pass to go build. - pkg := "./" + parentDir + pkg := parentDir + if !filepath.IsAbs(parentDir) { + // cannot use path.Join or filepath.Join, because we need + // to ensure that ./ is the prefix to pass to go build. + // if not absolute. + pkg = "./" + parentDir + } + paths = append(paths, pkg) return nil }) From d2d04f62a5a98cca84b9fbbe7a32a63c994b1c96 Mon Sep 17 00:00:00 2001 From: Hariom Verma Date: Thu, 13 Jul 2023 21:40:08 +0530 Subject: [PATCH 15/15] Add test for _test.gno file --- gnovm/cmd/gno/test_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gnovm/cmd/gno/test_test.go b/gnovm/cmd/gno/test_test.go index 7968938751d..4ff218918ed 100644 --- a/gnovm/cmd/gno/test_test.go +++ b/gnovm/cmd/gno/test_test.go @@ -99,6 +99,11 @@ func TestTest(t *testing.T) { stdoutShouldContain: "RUN TestSprintf", stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", }, + { + args: []string{"test", "../../../examples/gno.land/p/demo/ufmt/ufmt_test.gno"}, + stdoutShouldContain: "RUN TestSprintf", + stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", + }, { args: []string{"test", "--verbose", "../../../examples/gno.land/p/demo/ufmt"}, stdoutShouldContain: "RUN TestSprintf",