Skip to content

Commit

Permalink
feat(cmd/gno)!: remove flag -transpile from gno test (gnolang#2050)
Browse files Browse the repository at this point in the history
The `-transpile` flag in the `gno test` command duplicates the
functionality of the standalone `gno transpile` command. Removed the
unnecessary `-transpile` flag from the `gno test` command.

`gno test` should only be focused on testing!

Co-authored-by: Morgan <morgan@morganbaz.com>
  • Loading branch information
2 people authored and omarsy committed Jun 3, 2024
1 parent 0caee28 commit 696568c
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 101 deletions.
60 changes: 0 additions & 60 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type testCfg struct {
rootDir string
run string
timeout time.Duration
transpile bool // TODO: transpile should be the default, but it needs to automatically transpile dependencies in memory.
updateGoldenTests bool
printRuntimeMetrics bool
withNativeFallback bool
Expand Down Expand Up @@ -110,13 +109,6 @@ func (c *testCfg) RegisterFlags(fs *flag.FlagSet) {
"verbose output when running",
)

fs.BoolVar(
&c.transpile,
"transpile",
false,
"transpile gno to go before testing",
)

fs.BoolVar(
&c.updateGoldenTests,
"update-golden-tests",
Expand Down Expand Up @@ -165,21 +157,6 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error {
return flag.ErrHelp
}

verbose := cfg.verbose

tempdirRoot, err := os.MkdirTemp("", "gno-transpile")
if err != nil {
log.Fatal(err)
}
defer os.RemoveAll(tempdirRoot)

// go.mod
modPath := filepath.Join(tempdirRoot, "go.mod")
err = makeTestGoMod(modPath, transpiler.ImportPrefix, "1.21")
if err != nil {
return fmt.Errorf("write .mod file: %w", err)
}

// guess opts.RootDir
if cfg.rootDir == "" {
cfg.rootDir = gnoenv.RootDir()
Expand Down Expand Up @@ -209,43 +186,6 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error {
buildErrCount := 0
testErrCount := 0
for _, pkg := range subPkgs {
if cfg.transpile {
if verbose {
io.ErrPrintfln("=== PREC %s", pkg.Dir)
}
transpileOpts := newTranspileOptions(&transpileCfg{
output: tempdirRoot,
})
err := transpilePkg(importPath(pkg.Dir), transpileOpts)
if err != nil {
io.ErrPrintln(err)
io.ErrPrintln("FAIL")
io.ErrPrintfln("FAIL %s", pkg.Dir)
io.ErrPrintln("FAIL")

buildErrCount++
continue
}

if verbose {
io.ErrPrintfln("=== BUILD %s", pkg.Dir)
}
tempDir, err := ResolvePath(tempdirRoot, importPath(pkg.Dir))
if err != nil {
return errors.New("cannot resolve build dir")
}
err = goBuildFileOrPkg(tempDir, defaultTranspileCfg)
if err != nil {
io.ErrPrintln(err)
io.ErrPrintln("FAIL")
io.ErrPrintfln("FAIL %s", pkg.Dir)
io.ErrPrintln("FAIL")

buildErrCount++
continue
}
}

if len(pkg.TestGnoFiles) == 0 && len(pkg.FiletestGnoFiles) == 0 {
io.ErrPrintfln("? %s \t[no test files]", pkg.Dir)
continue
Expand Down
5 changes: 0 additions & 5 deletions gnovm/cmd/gno/testdata/gno_test/empty_gno1.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ gno test .
! stdout .+
stderr '\? \. \[no test files\]'

! gno test --transpile .

! stdout .+
stderr 'expected ''package'', found ''EOF'''

-- empty.gno --
5 changes: 0 additions & 5 deletions gnovm/cmd/gno/testdata/gno_test/empty_gno2.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
! stdout .+
stderr 'expected ''package'', found ''EOF'''

! gno test --transpile .

! stdout .+
stderr 'expected ''package'', found ''EOF'''

-- empty.gno --
-- empty_test.gno --
5 changes: 0 additions & 5 deletions gnovm/cmd/gno/testdata/gno_test/empty_gno3.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
! stdout .+
stderr 'expected ''package'', found ''EOF'''

! gno test --transpile .

! stdout .+
stderr 'expected ''package'', found ''EOF'''

-- empty.gno --
-- empty_filetest.gno --
8 changes: 0 additions & 8 deletions gnovm/cmd/gno/testdata/gno_test/failing_filetest.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ stdout 'Machine.RunMain\(\) panic: beep boop'
stderr '=== RUN file/failing_filetest.gno'
stderr 'panic: fail on failing_filetest.gno: got unexpected error: beep boop'

! gno test -v --transpile .

stdout 'Machine.RunMain\(\) panic: beep boop'
stderr '=== PREC \.'
stderr '=== BUILD \.'
stderr '=== RUN file/failing_filetest.gno'
stderr 'panic: fail on failing_filetest.gno: got unexpected error: beep boop'

-- failing.gno --
package failing

Expand Down
7 changes: 0 additions & 7 deletions gnovm/cmd/gno/testdata/gno_test/failing_test.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ stderr '=== RUN TestAlwaysFailing'
stderr '--- FAIL: TestAlwaysFailing'
stderr 'FAIL: 0 build errors, 1 test errors'

! gno test -v --transpile .

! stdout .+
stderr '=== RUN TestAlwaysFailing'
stderr '--- FAIL: TestAlwaysFailing'
stderr 'FAIL: 0 build errors, 1 test errors'

-- failing.gno --
package failing

Expand Down
5 changes: 0 additions & 5 deletions gnovm/cmd/gno/transpile.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ type transpileOptions struct {
transpiled map[importPath]struct{}
}

var defaultTranspileCfg = &transpileCfg{
verbose: false,
goBinary: "go",
}

func newTranspileOptions(cfg *transpileCfg) *transpileOptions {
return &transpileOptions{cfg, map[importPath]struct{}{}}
}
Expand Down
6 changes: 0 additions & 6 deletions gnovm/cmd/gno/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ func fmtDuration(d time.Duration) string {
return fmt.Sprintf("%.2fs", d.Seconds())
}

// makeTestGoMod creates the temporary go.mod for test
func makeTestGoMod(path string, packageName string, goversion string) error {
content := fmt.Sprintf("module %s\n\ngo %s\n", packageName, goversion)
return os.WriteFile(path, []byte(content), 0o644)
}

// getPathsFromImportSpec derive and returns ImportPaths
// without ImportPrefix from *ast.ImportSpec
func getPathsFromImportSpec(importSpec []*ast.ImportSpec) (importPaths []importPath) {
Expand Down

0 comments on commit 696568c

Please sign in to comment.