Skip to content

Commit

Permalink
test(gnovm): migrate 'gno build' test to testscript (gnolang#1103)
Browse files Browse the repository at this point in the history
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.

Like the previous test, the new test can be run via

```
$ go test ./gnovm/cmd/gno -v -run Build
```

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
tbruyelle authored and thehowl committed Oct 21, 2023
1 parent 6425b1f commit 0a98417
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 12 deletions.
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

0 comments on commit 0a98417

Please sign in to comment.