-
Notifications
You must be signed in to change notification settings - Fork 375
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): "*_filetest.gno" instructions #1023
test(gnovm): "*_filetest.gno" instructions #1023
Conversation
@@ -0,0 +1,17 @@ | |||
# Test Error instruction incorrect | |||
|
|||
! exec $GNO test -verbose -root-dir=$ROOTDIR . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The leading !
indicates the command is expected to fail (exit code != 0)
Conversely, when there's no !
the command is expected to succeed.
When the expections are wrong, the test fails ofc.
gnovm/tests/file_test.go
Outdated
rootDir := path.Dir(string(goModPath)) | ||
// Build a fresh gno binary in a temp directory | ||
gnoBin := path.Join(t.TempDir(), "gno") | ||
err = exec.Command("go", "build", "-o", gnoBin, path.Join(rootDir, "gnovm", "cmd", "gno")).Run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to override an existing gno
binary, so we compile a new one in a temp directory that will be removed at the end of the test.
} | ||
|
||
// Error: | ||
// oups |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each txtar file (txt is also an accepted extension) is executed in his own directory, so here the only file present for that test is x_filetest.gno
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great.
What do you think about moving this to gnovm/cmd/gno/testdata
, since it’s testing the CLI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Ideally, I think those tests should be added to gnovm/cmd/gno/test_test.go
, and so this whole file should be rewritten using testscripts
. Indeed I find the current format hard to read and maintain. The only good part is it fits in a single file, whereas with typescript there would be multiple small txtar files.
If it's OK I can do that in this PR, or an other one if you prefer.
db84131
to
918c3de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 💯
Really welcoming testscript
package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is really cool
Thank you for this addition 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you address this before: #1023 (comment), please?
Add tests for Output, Error and Realm instructions The change introduces a new test dependency github.com/rogpeppe/go-internal/testscripts, which allows to create tests bases on txtar files. This is very handy for this kind of tests, because: - you can easily creates a set of files that can be used for a command (here the `gno test` command) - you can assert stderr and stdout expectations in a very readable and maintainable way - you can compare files using the `cmp` command, which is very useful to assert of the `-update-golden-tests` behavior. These tests were added to help work on gnolang#1015, which will potentially alter the behavior of "*filetest.gno" instructions updates.
- rename txt to txtar - add comment for '!stdout .+' instruction - use filepath instead of path
- use a custom command for "gno" instead of env var - rebase on master so we can use "GNOROOT" instead of "-root-dir"
6a2ed63
to
1b1fddf
Compare
c20f39f
to
891929d
Compare
@moul the last commits address that :
Regarding
|
Add tests for Output, Error and Realm instructions
The change introduces a new test dependency: testscripts, which allows to create tests based on txtar files. This is very handy for testing
gno test
, because:gno test
command)cmp
command, which is very useful to assert of the-update-golden-tests
behavior.The tests can be run with the following command:
$ go test ./gnovm/tests/ -v -run TestRunFileTest
These tests were added to help work on #1015, which will potentially alter the behavior of "*_filetest.gno" instructions updates.
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description