forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(gnovm): "*_filetest.gno" instructions
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.
- Loading branch information
Showing
12 changed files
with
375 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Test Error instruction correct | ||
|
||
exec $GNO test -verbose -root-dir=$ROOTDIR . | ||
|
||
stdout 'Machine\.RunMain\(\) panic: oups' | ||
stderr '=== RUN file/x_filetest.gno' | ||
stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' | ||
stderr 'ok \./\. \d\.\d\ds' | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
// oups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Test Error instruction incorrect | ||
|
||
! exec $GNO test -verbose -root-dir=$ROOTDIR . | ||
|
||
stdout 'Machine\.RunMain\(\) panic: oups' | ||
stderr '=== RUN file/x_filetest.gno' | ||
stderr 'panic: fail on x_filetest.gno: got "oups", want: "xxx"' | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
// xxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Test Error instruction updated | ||
# NOTE: unlike Output and Realm instruction updates, Error update is not driven | ||
# by the '-update-golden-tests' flag. The Error is only updated when it is | ||
# empty. | ||
|
||
! exec $GNO test -verbose -root-dir=$ROOTDIR . | ||
|
||
cmp x_filetest.gno x_filetest.gno.golden | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
|
||
-- x_filetest.gno.golden -- | ||
package main | ||
|
||
func main() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
// oups | ||
// *** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, DELETE THIS LINE AND RUN TEST AGAIN *** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Test Output instruction correct | ||
|
||
exec $GNO test -verbose -root-dir=$ROOTDIR . | ||
|
||
! stdout .+ | ||
stderr '=== RUN file/x_filetest.gno' | ||
stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' | ||
stderr 'ok \./\. \d\.\d\ds' | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
println("hey") | ||
println("hru?") | ||
} | ||
|
||
// Output: | ||
// hey | ||
// hru? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Test Output instruction incorrect | ||
|
||
! exec $GNO test -verbose -root-dir=$ROOTDIR . | ||
|
||
! stdout .+ | ||
stderr '=== RUN file/x_filetest.gno' | ||
stderr 'panic: fail on x_filetest.gno: diff:' | ||
stderr '--- Expected' | ||
stderr '\+\+\+ Actual' | ||
stderr '@@ -1,2 \+1 @@' | ||
stderr 'hey' | ||
stderr '-hru?' | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
println("hey") | ||
} | ||
|
||
// Output: | ||
// hey | ||
// hru? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Test Output instruction updated | ||
|
||
exec $GNO test -verbose -root-dir=$ROOTDIR . -update-golden-tests | ||
|
||
cmp x_filetest.gno x_filetest.gno.golden | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
println("hey") | ||
println("hru?") | ||
} | ||
|
||
// Output: | ||
// hey | ||
|
||
-- x_filetest.gno.golden -- | ||
package main | ||
|
||
func main() { | ||
println("hey") | ||
println("hru?") | ||
} | ||
|
||
// Output: | ||
// hey | ||
// hru? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Test Realm instruction correct | ||
|
||
exec $GNO test -verbose -root-dir=$ROOTDIR . | ||
|
||
! stdout .+ | ||
stderr '=== RUN file/x_filetest.gno' | ||
stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' | ||
stderr 'ok \./\. \d\.\d\ds' | ||
|
||
-- x_filetest.gno -- | ||
// PKGPATH: gno.land/r/x | ||
package x | ||
|
||
var x int | ||
|
||
func main() { | ||
x = 1 | ||
} | ||
|
||
// Realm: | ||
// switchrealm["gno.land/r/x"] | ||
// u[58cde29876a8d185e30c727361981efb068f4726:2]={ | ||
// "Blank": {}, | ||
// "ObjectInfo": { | ||
// "ID": "58cde29876a8d185e30c727361981efb068f4726:2", | ||
// "IsEscaped": true, | ||
// "ModTime": "3", | ||
// "RefCount": "2" | ||
// }, | ||
// "Parent": null, | ||
// "Source": { | ||
// "@type": "/gno.RefNode", | ||
// "BlockNode": null, | ||
// "Location": { | ||
// "File": "", | ||
// "Line": "0", | ||
// "Nonce": "0", | ||
// "PkgPath": "gno.land/r/x" | ||
// } | ||
// }, | ||
// "Values": [ | ||
// { | ||
// "T": { | ||
// "@type": "/gno.FuncType", | ||
// "Params": [], | ||
// "Results": [] | ||
// }, | ||
// "V": { | ||
// "@type": "/gno.FuncValue", | ||
// "Closure": { | ||
// "@type": "/gno.RefValue", | ||
// "Escaped": true, | ||
// "ObjectID": "58cde29876a8d185e30c727361981efb068f4726:3" | ||
// }, | ||
// "FileName": "main.gno", | ||
// "IsMethod": false, | ||
// "Name": "main", | ||
// "PkgPath": "gno.land/r/x", | ||
// "Source": { | ||
// "@type": "/gno.RefNode", | ||
// "BlockNode": null, | ||
// "Location": { | ||
// "File": "main.gno", | ||
// "Line": "6", | ||
// "Nonce": "0", | ||
// "PkgPath": "gno.land/r/x" | ||
// } | ||
// }, | ||
// "Type": { | ||
// "@type": "/gno.FuncType", | ||
// "Params": [], | ||
// "Results": [] | ||
// } | ||
// } | ||
// }, | ||
// { | ||
// "N": "AQAAAAAAAAA=", | ||
// "T": { | ||
// "@type": "/gno.PrimitiveType", | ||
// "value": "32" | ||
// } | ||
// } | ||
// ] | ||
// } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Test Realm instruction incorrect | ||
|
||
! exec $GNO test -verbose -root-dir=$ROOTDIR . | ||
|
||
! stdout .+ | ||
stderr '=== RUN file/x_filetest.gno' | ||
stderr 'panic: fail on x_filetest.gno: diff:' | ||
stderr '--- Expected' | ||
stderr '\+\+\+ Actual' | ||
stderr '@@ -1 \+1,64 @@' | ||
stderr '-xxx' | ||
stderr '\+switchrealm\["gno.land/r/x"\]' | ||
|
||
-- x_filetest.gno -- | ||
// PKGPATH: gno.land/r/x | ||
package x | ||
|
||
var x int | ||
|
||
func main() { | ||
x = 1 | ||
} | ||
|
||
// Realm: | ||
// xxxx | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Test Realm instruction updated | ||
|
||
exec $GNO test -verbose -root-dir=$ROOTDIR . -update-golden-tests | ||
|
||
cmp x_filetest.gno x_filetest.gno.golden | ||
|
||
-- x_filetest.gno -- | ||
// PKGPATH: gno.land/r/x | ||
package x | ||
|
||
var x int | ||
|
||
func main() { | ||
x = 1 | ||
} | ||
|
||
// Realm: | ||
// xxx | ||
|
||
-- x_filetest.gno.golden -- | ||
// PKGPATH: gno.land/r/x | ||
package x | ||
|
||
var x int | ||
|
||
func main() { | ||
x = 1 | ||
} | ||
|
||
// Realm: | ||
// switchrealm["gno.land/r/x"] | ||
// u[58cde29876a8d185e30c727361981efb068f4726:2]={ | ||
// "Blank": {}, | ||
// "ObjectInfo": { | ||
// "ID": "58cde29876a8d185e30c727361981efb068f4726:2", | ||
// "IsEscaped": true, | ||
// "ModTime": "3", | ||
// "RefCount": "2" | ||
// }, | ||
// "Parent": null, | ||
// "Source": { | ||
// "@type": "/gno.RefNode", | ||
// "BlockNode": null, | ||
// "Location": { | ||
// "File": "", | ||
// "Line": "0", | ||
// "Nonce": "0", | ||
// "PkgPath": "gno.land/r/x" | ||
// } | ||
// }, | ||
// "Values": [ | ||
// { | ||
// "T": { | ||
// "@type": "/gno.FuncType", | ||
// "Params": [], | ||
// "Results": [] | ||
// }, | ||
// "V": { | ||
// "@type": "/gno.FuncValue", | ||
// "Closure": { | ||
// "@type": "/gno.RefValue", | ||
// "Escaped": true, | ||
// "ObjectID": "58cde29876a8d185e30c727361981efb068f4726:3" | ||
// }, | ||
// "FileName": "main.gno", | ||
// "IsMethod": false, | ||
// "Name": "main", | ||
// "PkgPath": "gno.land/r/x", | ||
// "Source": { | ||
// "@type": "/gno.RefNode", | ||
// "BlockNode": null, | ||
// "Location": { | ||
// "File": "main.gno", | ||
// "Line": "6", | ||
// "Nonce": "0", | ||
// "PkgPath": "gno.land/r/x" | ||
// } | ||
// }, | ||
// "Type": { | ||
// "@type": "/gno.FuncType", | ||
// "Params": [], | ||
// "Results": [] | ||
// } | ||
// } | ||
// }, | ||
// { | ||
// "N": "AQAAAAAAAAA=", | ||
// "T": { | ||
// "@type": "/gno.PrimitiveType", | ||
// "value": "32" | ||
// } | ||
// } | ||
// ] | ||
// } | ||
|
Oops, something went wrong.