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): improve gnovm/pkg/gnolang test coverage (gnolang#2143)
No new tests have been added yet, but existing tests in gnovm/tests/files are now executed in the context of the package which contains the relevant interpreter virtual machine and parser code. We have now a better baseline to measure and complete the code coverage. This represents more than 800 tests, which takes 10s on my macbook air m1. Those tests are actually run twice, as I haven't yet removed the original execution from gnovm/tests. The testing code is substantially simplified compared to its counterpart in gnovm/tests, but has not yet been deduplicated. This will be done in further commits. In `gnovm/pkg/golang`, `go test -cover` went from 34.2% to 66.7%. Related to gnolang#1121, gnolang#1145 and probably more <!-- please provide a detailed description of the changes made in this pull request. --> <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>
- Loading branch information
Showing
12 changed files
with
114 additions
and
35 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,62 @@ | ||
package gnolang_test | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestEvalFiles(t *testing.T) { | ||
dir := "../../tests/files" | ||
files, err := os.ReadDir(dir) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, f := range files { | ||
wantOut, wantErr, ok := testData(dir, f) | ||
if !ok { | ||
continue | ||
} | ||
t.Run(f.Name(), func(t *testing.T) { | ||
out, err := evalTest("", "", path.Join(dir, f.Name())) | ||
|
||
if wantErr != "" && !strings.Contains(err, wantErr) || | ||
wantErr == "" && err != "" { | ||
t.Fatalf("unexpected error\nWant: %s\n Got: %s", wantErr, err) | ||
} | ||
if wantOut != "" && out != wantOut { | ||
t.Fatalf("unexpected output\nWant: %s\n Got: %s", wantOut, out) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// testData returns the expected output and error string, and true if entry is valid. | ||
func testData(dir string, f os.DirEntry) (testOut, testErr string, ok bool) { | ||
if f.IsDir() { | ||
return "", "", false | ||
} | ||
name := path.Join(dir, f.Name()) | ||
if !strings.HasSuffix(name, ".gno") || strings.HasSuffix(name, "_long.gno") { | ||
return "", "", false | ||
} | ||
buf, err := os.ReadFile(name) | ||
if err != nil { | ||
return "", "", false | ||
} | ||
str := string(buf) | ||
if strings.Contains(str, "// PKGPATH:") { | ||
return "", "", false | ||
} | ||
return commentFrom(str, "\n// Output:"), commentFrom(str, "\n// Error:"), true | ||
} | ||
|
||
// commentFrom returns the content from a trailing comment block in s starting with delim. | ||
func commentFrom(s, delim string) string { | ||
index := strings.Index(s, delim) | ||
if index < 0 { | ||
return "" | ||
} | ||
return strings.TrimSpace(strings.ReplaceAll(s[index+len(delim):], "\n// ", "\n")) | ||
} |
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
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
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 |
---|---|---|
|
@@ -7,4 +7,4 @@ func main() { | |
} | ||
|
||
// Error: | ||
// 5:2: fallthrough statement out of place | ||
// fallthrough statement out of place |
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 |
---|---|---|
|
@@ -12,4 +12,4 @@ func main() { | |
} | ||
|
||
// Error: | ||
// 7:3: fallthrough statement out of place | ||
// fallthrough statement out of place |
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ func main() { | |
} | ||
|
||
// Error: | ||
// 9:3: cannot fallthrough in type switch | ||
// cannot fallthrough in type switch |
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