Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(gnovm): migrate 'gno build' test to testscript #1103

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 6 additions & 12 deletions gnovm/cmd/gno/build_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package main

import "testing"
import (
"testing"

func TestBuildApp(t *testing.T) {
tc := []testMainCase{
{
args: []string{"build"},
errShouldBe: "flag: help requested",
},
"github.com/rogpeppe/go-internal/testscript"
)

// {args: []string{"build", "..."}, stdoutShouldContain: "..."},
// TODO: auto precompilation
// TODO: error handling
}
testMainCaseRun(t, tc)
func TestBuild(t *testing.T) {
testscript.Run(t, setupTestScript(t, "testdata/gno_build"))
}
6 changes: 6 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/empty_dir.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run gno build on an empty dir

gno build .

! stdout .+
! stderr .+
27 changes: 27 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/invalid_gno_files.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Run gno build with invalid gno files (still success)

gno build .

! stdout .+
! stderr .+

-- go.mod --
module gnobuild

-- file1.go --
package file1

-- main.gno --
package main

invalid

func main() {}

-- sub/sub.gno --
package sub

invalid

-- sub/file2.go --
package file2
30 changes: 30 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/invalid_go_files.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Run gno build with invalid go files

! gno build .

! stdout .+
stderr '\./file1\.go:3:1: syntax error: non-declaration statement outside function body'
stderr '\./\.: build pkg: std go compiler: exit status 1'
stderr 'sub/file2\.go:3:1: syntax error: non-declaration statement outside function body'
stderr '\./sub: build pkg: std go compiler: exit status 1'

-- go.mod --
module gnobuild

-- file1.go --
package file1

invalid1

-- main.gno --
package main

func main() {}

-- sub/sub.gno --
package sub

-- sub/file2.go --
package file2

invalid2
6 changes: 6 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/no_args.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run gno build without args

! gno build

! stdout .+
stderr 'flag: help requested'
12 changes: 12 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/no_gno_files.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Run gno build on a dir w/o gno files

gno build .

! stdout .+
! stderr .+

-- README --
Hello world

-- sub/README --
Hello world
19 changes: 19 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/no_go_files.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Run gno build in a dir without go files

! gno build .

! stdout .+
stderr -count=2 'no Go files in '$WORK
stderr '\./\.: build pkg: std go compiler: exit status 1'
stderr '\./sub: build pkg: std go compiler: exit status 1'

-- go.mod --
module gnobuild

-- main.gno --
package main

func main() {}

-- sub/sub.gno --
package sub
16 changes: 16 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/no_gomod.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Run gno build on a dir without go.mod

! gno build .

! stdout .+
stderr -count=2 'go: go.mod file not found in current directory or any parent directory'
stderr './.: build pkg: std go compiler: exit status 1'
stderr './sub: build pkg: std go compiler: exit status 1'

-- main.gno --
package main

func main() {}

-- sub/sub.gno --
package sub
23 changes: 23 additions & 0 deletions gnovm/cmd/gno/testdata/gno_build/ok.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Run gno build successfully

gno build .

! stdout .+
! stderr .+

-- go.mod --
module gnobuild

-- file1.go --
package file1

-- main.gno --
package main

func main() {}

-- sub/sub.gno --
package sub

-- sub/file2.go --
package file2
Loading