From 23bf072d67acfdc5e2f99132d78a4c3bbcbdd473 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Wed, 6 Sep 2023 16:50:02 +0200 Subject: [PATCH] test(gnovm): migrate 'gno build' test to testscript Like done for 'gno test', use testscript and txtar files to define the different test cases. The previous test was only testing `gno build` without arguments and files, so this PR adds more cases. Interestingly, the gno files are only used to determine the directories where the 'go build' command will be passed. This means only go file syntax is checked (gno file syntax is ignored, as pictured in `invalid_gno_files.txtar' case). Also a `go.mod` is required or else the command fails. --- gnovm/cmd/gno/build_test.go | 18 ++++------- .../gno/testdata/gno_build/empty_dir.txtar | 6 ++++ .../gno_build/invalid_gno_files.txtar | 27 +++++++++++++++++ .../testdata/gno_build/invalid_go_files.txtar | 30 +++++++++++++++++++ .../cmd/gno/testdata/gno_build/no_args.txtar | 6 ++++ .../gno/testdata/gno_build/no_gno_files.txtar | 12 ++++++++ .../gno/testdata/gno_build/no_go_files.txtar | 19 ++++++++++++ .../cmd/gno/testdata/gno_build/no_gomod.txtar | 16 ++++++++++ gnovm/cmd/gno/testdata/gno_build/ok.txtar | 23 ++++++++++++++ 9 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 gnovm/cmd/gno/testdata/gno_build/empty_dir.txtar create mode 100644 gnovm/cmd/gno/testdata/gno_build/invalid_gno_files.txtar create mode 100644 gnovm/cmd/gno/testdata/gno_build/invalid_go_files.txtar create mode 100644 gnovm/cmd/gno/testdata/gno_build/no_args.txtar create mode 100644 gnovm/cmd/gno/testdata/gno_build/no_gno_files.txtar create mode 100644 gnovm/cmd/gno/testdata/gno_build/no_go_files.txtar create mode 100644 gnovm/cmd/gno/testdata/gno_build/no_gomod.txtar create mode 100644 gnovm/cmd/gno/testdata/gno_build/ok.txtar diff --git a/gnovm/cmd/gno/build_test.go b/gnovm/cmd/gno/build_test.go index 89339ee8a6e..5bb03ef0d35 100644 --- a/gnovm/cmd/gno/build_test.go +++ b/gnovm/cmd/gno/build_test.go @@ -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")) } diff --git a/gnovm/cmd/gno/testdata/gno_build/empty_dir.txtar b/gnovm/cmd/gno/testdata/gno_build/empty_dir.txtar new file mode 100644 index 00000000000..d346b6ad46f --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/empty_dir.txtar @@ -0,0 +1,6 @@ +# Run gno build on an empty dir + +gno build . + +! stdout .+ +! stderr .+ diff --git a/gnovm/cmd/gno/testdata/gno_build/invalid_gno_files.txtar b/gnovm/cmd/gno/testdata/gno_build/invalid_gno_files.txtar new file mode 100644 index 00000000000..617e12291be --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/invalid_gno_files.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/gno_build/invalid_go_files.txtar b/gnovm/cmd/gno/testdata/gno_build/invalid_go_files.txtar new file mode 100644 index 00000000000..6093bfdad00 --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/invalid_go_files.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/gno_build/no_args.txtar b/gnovm/cmd/gno/testdata/gno_build/no_args.txtar new file mode 100644 index 00000000000..b3f68676588 --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/no_args.txtar @@ -0,0 +1,6 @@ +# Run gno build without args + +! gno build + +! stdout .+ +stderr 'flag: help requested' diff --git a/gnovm/cmd/gno/testdata/gno_build/no_gno_files.txtar b/gnovm/cmd/gno/testdata/gno_build/no_gno_files.txtar new file mode 100644 index 00000000000..58261e77cda --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/no_gno_files.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/gno_build/no_go_files.txtar b/gnovm/cmd/gno/testdata/gno_build/no_go_files.txtar new file mode 100644 index 00000000000..ddc6aec4555 --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/no_go_files.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/gno_build/no_gomod.txtar b/gnovm/cmd/gno/testdata/gno_build/no_gomod.txtar new file mode 100644 index 00000000000..5eb8edeaad9 --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/no_gomod.txtar @@ -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 diff --git a/gnovm/cmd/gno/testdata/gno_build/ok.txtar b/gnovm/cmd/gno/testdata/gno_build/ok.txtar new file mode 100644 index 00000000000..9d70fd97904 --- /dev/null +++ b/gnovm/cmd/gno/testdata/gno_build/ok.txtar @@ -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