-
Notifications
You must be signed in to change notification settings - Fork 374
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
fix(gnovm): PrevRealm in _test files #896
Conversation
Hmm.. unfortunately It doesn't work on my side.
|
@r3v4s Sorry to ask, but are you sure that you recompiled the |
@tbruyelle Yep, I did. can you share me pre-built |
If you run |
Can you also check how it goes with external repos? (Not using examples/)? Will give a deeper look of the diff later, thank you. |
Thank you. Do you have any example of external repos that contains gno packages ? |
3f95ce1
to
18eb207
Compare
@moul So thanks to yesterday meeting I found the gnodaos external repo and I tried to use the After a couple of changes :
I was able to run the tests successfully ✔️ Note that So the plan for this PR is to wait for #682, then use the |
On the master branch, the following command works fine, but on this PR I get the following error.
I'm not sure, but could these two IDs be different?
|
@anarcher wow thank you for pointing that, it appears this only happens when the So the fix for that is the following : diff --git a/gnovm/stdlibs/testing/match.gno b/gnovm/stdlibs/testing/match.gno
index 5b7f509d..13a7edd4 100644
--- a/gnovm/stdlibs/testing/match.gno
+++ b/gnovm/stdlibs/testing/match.gno
@@ -166,13 +166,13 @@ func isSpace(r rune) bool {
return false
}
-var (
- matchPat string
- matchRe *regexp.Regexp
-)
-
// based on testing/internal/testdeps.TestDeps.MatchString.
func matchString(pat, str string) (result bool, err error) {
+ var (
+ matchPat string
+ matchRe *regexp.Regexp
+ )
+
if matchRe == nil || matchPat != pat {
matchPat = pat
matchRe, err = regexp.Compile(matchPat) (this patch should be reworked, there's no reason to turn the global var into local var like that, but that's for the demo) The funny thing behind this fix is :
You can have the same behavior by calling a realm that calls a package that mutates its own global variables. So that means with this PR, we can no longer have global variables in |
To keep track of the previous discussion: When persisting the snapshot of the finished state, exclude globals from |
3b9001b
to
caa1fc5
Compare
@moul I reverted the last change so now when the tx is finalized, the realm's global variables that come from That works for test files, and for the template file generated at runtime (because it has been renamed from I didn't find a way to determine that On the other hand, I found some other gno code imported from the stdlib, where the global variables are commented with the label |
Thinking out loud, what about ignoring files importing « testing »? |
I believe no production code would import |
b90c4fb
to
ded4971
Compare
@moul I was able to ignore the |
not so well and add too much diff
This reverts commit 763ac29.
88d71b4
to
7798dfb
Compare
@@ -70,6 +70,9 @@ func newDirs(dirs []string, modDirs []string) *bfsDirs { | |||
|
|||
// tries to parse gno mod file given the filename, using Parse and Validate from | |||
// the gnomod package | |||
// | |||
// TODO(tb): replace by `gnomod.ParseAt` ? The key difference is the latter |
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.
yes, and later, gnomod.ParseAt
can also support new ways to guess a module when there is no gno.mod
file.
@@ -1121,6 +1121,10 @@ func copyValueWithRefs(parent Object, val Value) Value { | |||
} | |||
case *FuncValue: | |||
source := toRefNode(cv.Source) | |||
if strings.HasSuffix(source.Location.File, "_test.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.
if strings.HasSuffix(source.Location.File, "_test.gno") { | |
func (v Val) InTestFile() bool {return strings.HasSuffix(source.Location.File, "_test.gno")} | |
if val.InTestFile()) { |
can be done later
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 have to change it now. I created an issue so that we can track it for later discussion.
Dose this mean if someone deployed a realm package with a source file named xyz_test.gno it will be ignored by the VM? If that is the case, it means we should include this file naming convention to the VM specs.
Also If we do not allow _test.gno files in the realm package, we should guarded it before we parse the file and load it to VM, instead of at the persistent stage.
If this purely serves the purpose for off chain realm testing, would sticking with realm file test be a better option?
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
`TestPackages` wasn't actually reporting test failures, due to a bug in the underlying function `machine.TestMemPackage()`. `TestMemPackage` was running the gno tests by just calling the test function with a new `testing.T`, but then it's not possible to detect if there's any failure, because `testing.T` has only private fields. The fix is to change that to a call to `testing.RunTest()` function, which is already used by `gno test`, and returns a `testing.Report` on which we can detect failures. A test has been added (see `TestMachineTestMemPackage()`) in gnovm/tests folder (because a `TestStore` is needed). On master, this test is failing. ``` go test ./gnovm/tests -v -run TestMachineTestMemPackage ``` The next step should be to merge the 2 ways that currently exists to run gno tests, i.e. `gno test` and `go test -run TestPackages`. Potentially this could fix #896. ## Contributors Checklist - [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](../.benchmarks/README.md). ## Maintainers Checklist - [x] Checked that the author followed the guidelines in `CONTRIBUTING.md` - [x] Checked the conventional-commit (especially PR title and verb, presence of `BREAKING CHANGE:` in the body) - [x] Ensured that this PR is not a significant change or confirmed that the review/consideration process was appropriate for the change </details> --------- Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
<!-- please provide a detailed description of the changes made in this pull request. --> Asked by @jaekwon in #896 (comment) Add a long description for `gno test -h`, that explains the different files, `*_test.gno` and `*_filetest.gno`, and gives the list of instructions related to the latter. Thanks in advance for correcting my frenglish :) <details><summary>Contributors' checklist...</summary> - [ ] 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 - [ ] 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> --------- Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com> Co-authored-by: Morgan <git@howl.moe>
Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
`TestPackages` wasn't actually reporting test failures, due to a bug in the underlying function `machine.TestMemPackage()`. `TestMemPackage` was running the gno tests by just calling the test function with a new `testing.T`, but then it's not possible to detect if there's any failure, because `testing.T` has only private fields. The fix is to change that to a call to `testing.RunTest()` function, which is already used by `gno test`, and returns a `testing.Report` on which we can detect failures. A test has been added (see `TestMachineTestMemPackage()`) in gnovm/tests folder (because a `TestStore` is needed). On master, this test is failing. ``` go test ./gnovm/tests -v -run TestMachineTestMemPackage ``` The next step should be to merge the 2 ways that currently exists to run gno tests, i.e. `gno test` and `go test -run TestPackages`. Potentially this could fix gnolang#896. ## Contributors Checklist - [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](../.benchmarks/README.md). ## Maintainers Checklist - [x] Checked that the author followed the guidelines in `CONTRIBUTING.md` - [x] Checked the conventional-commit (especially PR title and verb, presence of `BREAKING CHANGE:` in the body) - [x] Ensured that this PR is not a significant change or confirmed that the review/consideration process was appropriate for the change </details> --------- Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com>
<!-- please provide a detailed description of the changes made in this pull request. --> Asked by @jaekwon in gnolang#896 (comment) Add a long description for `gno test -h`, that explains the different files, `*_test.gno` and `*_filetest.gno`, and gives the list of instructions related to the latter. Thanks in advance for correcting my frenglish :) <details><summary>Contributors' checklist...</summary> - [ ] 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 - [ ] 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> --------- Co-authored-by: Manfred Touron <94029+moul@users.noreply.github.com> Co-authored-by: Morgan <git@howl.moe>
Description
Related to #667 #891
When _test files are executed, the name of the package is set to the real path to those files, which starts by
./examples/gno.land/...
. This leads to interpreting the tested package as a non-realm, because a realm must start withgno.land/r
.Because of that, when calling
PrevRealm
, a tested package is never considered as a realm.The fix truncates the./examples
prefix from the tested package, which ensures it is well detected as a realm when required.The fix replaces the usage of the package directory
/examples/gno.land/...
by a real gno package path.To determine it, we try to read a
gno.mod
in the directory passed in argument or in its parents:gno.mod
.gno.land/r/
(so it will be considered as a realm).Tests
A test
TestPrevRealm
has been added:Contributors Checklist
BREAKING CHANGE: xxx
message was included in the descriptionMaintainers Checklist
CONTRIBUTING.md
BREAKING CHANGE:
in the body)