diff --git a/gnovm/pkg/gnolang/debugger_test.go b/gnovm/pkg/gnolang/debugger_test.go index 16ecb91fb3c..fe059ba9f56 100644 --- a/gnovm/pkg/gnolang/debugger_test.go +++ b/gnovm/pkg/gnolang/debugger_test.go @@ -40,7 +40,7 @@ func evalTest(debugAddr, in, file string) (out, err, stacktrace string) { if r := recover(); r != nil { err = fmt.Sprintf("%v", r) } - out = strings.TrimSpace(out) + out = strings.TrimSuffix(out, "\n") err = strings.TrimSpace(strings.ReplaceAll(err, "../../tests/files/", "files/")) }() diff --git a/gnovm/pkg/gnolang/eval_test.go b/gnovm/pkg/gnolang/eval_test.go index 5aa5bcca462..ba93dd00396 100644 --- a/gnovm/pkg/gnolang/eval_test.go +++ b/gnovm/pkg/gnolang/eval_test.go @@ -1,8 +1,10 @@ package gnolang_test import ( + "io/fs" "os" - "path" + "path/filepath" + "regexp" "sort" "strings" "testing" @@ -10,17 +12,24 @@ import ( 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, wantStacktrace, ok := testData(dir, f) + err := fs.WalkDir(os.DirFS(dir), ".", func(path string, de fs.DirEntry, err error) error { + switch { + case err != nil: + return err + case path == "extern": + return fs.SkipDir + case de.IsDir(): + return nil + } + + fullPath := filepath.Join(dir, path) + wantOut, wantErr, wantStacktrace, ok := testData(fullPath) if !ok { - continue + return nil } - t.Run(f.Name(), func(t *testing.T) { - out, err, stacktrace := evalTest("", "", path.Join(dir, f.Name())) + + t.Run(path, func(t *testing.T) { + out, err, stacktrace := evalTest("", "", fullPath) if wantErr != "" && !strings.Contains(err, wantErr) || wantErr == "" && err != "" { @@ -34,15 +43,16 @@ func TestEvalFiles(t *testing.T) { t.Fatalf("unexpected output\nWant: %s\n Got: %s", wantOut, out) } }) + + return nil + }) + if err != nil { + t.Fatal(err) } } // testData returns the expected output and error string, and true if entry is valid. -func testData(dir string, f os.DirEntry) (testOut, testErr, testStacktrace string, ok bool) { - if f.IsDir() { - return - } - name := path.Join(dir, f.Name()) +func testData(name string) (testOut, testErr, testStacktrace string, ok bool) { if !strings.HasSuffix(name, ".gno") || strings.HasSuffix(name, "_long.gno") { return } @@ -54,8 +64,11 @@ func testData(dir string, f os.DirEntry) (testOut, testErr, testStacktrace strin if strings.Contains(str, "// PKGPATH:") { return } - - res := commentFrom(str, []string{"\n// Output:", "\n// Error:", "\n// Stacktrace:"}) + res := commentFrom(str, []string{ + "// Output:", + "// Error:", + "// Stacktrace:", + }) return res[0], res[1], res[2], true } @@ -66,12 +79,17 @@ type directive struct { index int } +// (?m) makes ^ and $ match start/end of string +var reCommentPrefix = regexp.MustCompile("(?m)^//(?: |$)") + // commentFrom returns the comments from s that are between the delimiters. func commentFrom(s string, delims []string) []string { directives := make([]directive, len(delims)) directivesFound := make([]*directive, 0, len(delims)) for i, delim := range delims { + // must find delim isolated on one line + delim = "\n" + delim + "\n" index := strings.Index(s, delim) directives[i] = directive{delim: delim, index: index} if index >= 0 { @@ -88,7 +106,10 @@ func commentFrom(s string, delims []string) []string { next = directivesFound[i+1].index } - directivesFound[i].res = strings.TrimSpace(strings.ReplaceAll(s[directivesFound[i].index+len(directivesFound[i].delim):next], "\n// ", "\n")) + parsed := reCommentPrefix.ReplaceAllLiteralString( + s[directivesFound[i].index+len(directivesFound[i].delim):next], + "") + directivesFound[i].res = strings.TrimSuffix(parsed, "\n") } res := make([]string, len(directives)) diff --git a/gnovm/pkg/gnolang/values_string.go b/gnovm/pkg/gnolang/values_string.go index 204fab62c86..a414f440e4e 100644 --- a/gnovm/pkg/gnolang/values_string.go +++ b/gnovm/pkg/gnolang/values_string.go @@ -170,6 +170,9 @@ func (fv *FuncValue) String() string { if fv.Type == nil { return fmt.Sprintf("incomplete-func ?%s(?)?", name) } + if name == "" { + return fmt.Sprintf("%s{...}", fv.Type.String()) + } return name } diff --git a/gnovm/tests/files/a31.gno b/gnovm/tests/files/a31.gno index d687b098e7c..052ab673cf2 100644 --- a/gnovm/tests/files/a31.gno +++ b/gnovm/tests/files/a31.gno @@ -2,10 +2,10 @@ package main func main() { for range []int{0, 1, 2} { - print("hello ") + print("hello,") } println("") } // Output: -// hello hello hello +// hello,hello,hello, diff --git a/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno index 583e2f12bd8..0c15ce1ae02 100644 --- a/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype5_filetest.gno @@ -34,8 +34,8 @@ func main() { // Output: // 1 (inc main.op) -// 0 +// 0 func(n int)( int){...} // -1 dec -// 0 ( main.op) +// 0 (func(n int)( int){...} main.op) // -1 dec // 1 inc diff --git a/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno b/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno index e14e64e4dfd..165dd8e18a4 100644 --- a/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno +++ b/gnovm/tests/files/assign_unnamed_type/unnamedtype5a_filetest.gno @@ -27,6 +27,7 @@ func main() { } // Output: +// func(n int)( int){...} // 1 -// ( main.op) +// (func(n int)( int){...} main.op) // -1 diff --git a/gnovm/tests/files/convert4.gno b/gnovm/tests/files/convert4.gno index d7ab4905f62..e03e1d07ce3 100644 --- a/gnovm/tests/files/convert4.gno +++ b/gnovm/tests/files/convert4.gno @@ -4,4 +4,5 @@ func main() { println(int(nil)) } -// Error: cannot convert (undefined) to int +// Error: +// main/files/convert4.gno:4:10: cannot convert (undefined) to int diff --git a/gnovm/tests/files/convert5.gno b/gnovm/tests/files/convert5.gno index 74063709110..e2e16c5eb83 100644 --- a/gnovm/tests/files/convert5.gno +++ b/gnovm/tests/files/convert5.gno @@ -6,4 +6,5 @@ func main() { println(ints) } -// Error: cannot convert (undefined) to int +// Error: +// main/files/convert5.gno:3:1: cannot convert (undefined) to int diff --git a/gnovm/tests/files/defer6.gno b/gnovm/tests/files/defer6.gno index 65a8d933996..fa0d61285c3 100644 --- a/gnovm/tests/files/defer6.gno +++ b/gnovm/tests/files/defer6.gno @@ -1,21 +1,21 @@ package main func f1() { - defer print("f1-begin ") + defer print("f1-begin,") f2() - defer print("f1-end ") + defer print("f1-end,") } func f2() { - defer print("f2-begin ") + defer print("f2-begin,") f3() - defer print("f2-end ") + defer print("f2-end,") } func f3() { - defer print("f3-begin ") - print("hello ") - defer print("f3-end ") + defer print("f3-begin,") + print("hello,") + defer print("f3-end,") } func main() { @@ -24,4 +24,4 @@ func main() { } // Output: -// hello f3-end f3-begin f2-end f2-begin f1-end f1-begin +// hello,f3-end,f3-begin,f2-end,f2-begin,f1-end,f1-begin, diff --git a/gnovm/tests/files/map15.gno b/gnovm/tests/files/map15.gno index 99e28fdeeda..1c1775fa30b 100644 --- a/gnovm/tests/files/map15.gno +++ b/gnovm/tests/files/map15.gno @@ -6,8 +6,8 @@ func main() { users := make(map[string]string) v := users["a"] - fmt.Println("v:", v) + fmt.Println("v:", v, ";") } // Output: -// v: +// v: ; diff --git a/gnovm/tests/files/method27.gno b/gnovm/tests/files/method27.gno index cb046d27449..ccb3c53d250 100644 --- a/gnovm/tests/files/method27.gno +++ b/gnovm/tests/files/method27.gno @@ -13,8 +13,8 @@ type AuthenticatedRequest struct { func main() { a := &AuthenticatedRequest{} - fmt.Println("ua:", a.UserAgent()) + fmt.Println("ua:", a.UserAgent(), ";") } // Output: -// ua: +// ua: ; diff --git a/gnovm/tests/files/types/cmp_iface_2.gno b/gnovm/tests/files/types/cmp_iface_2.gno index 5ad121f515b..f3bf14b2b7b 100644 --- a/gnovm/tests/files/types/cmp_iface_2.gno +++ b/gnovm/tests/files/types/cmp_iface_2.gno @@ -19,7 +19,7 @@ func (e Error) Error() string { func main() { var e0 E e0 = Error(0) - fmt.Printf("%T \n", e0) + fmt.Printf("%T\n", e0) if e0 == Error(0) { println("what the firetruck?") } else { diff --git a/gnovm/tests/files/types/eql_0f2d.gno b/gnovm/tests/files/types/eql_0f2d.gno index 5ad121f515b..f3bf14b2b7b 100644 --- a/gnovm/tests/files/types/eql_0f2d.gno +++ b/gnovm/tests/files/types/eql_0f2d.gno @@ -19,7 +19,7 @@ func (e Error) Error() string { func main() { var e0 E e0 = Error(0) - fmt.Printf("%T \n", e0) + fmt.Printf("%T\n", e0) if e0 == Error(0) { println("what the firetruck?") } else { diff --git a/gnovm/tests/files/types/eql_0f2e.gno b/gnovm/tests/files/types/eql_0f2e.gno index ea03028f5e1..c9c24dcd4eb 100644 --- a/gnovm/tests/files/types/eql_0f2e.gno +++ b/gnovm/tests/files/types/eql_0f2e.gno @@ -19,7 +19,7 @@ func (e Error) Error() string { func main() { var e0 E e0 = Error(0) - fmt.Printf("%T \n", e0) + fmt.Printf("%T\n", e0) if Error(0) == e0 { println("what the firetruck?") } else { diff --git a/gnovm/tests/files/types/runtime_a2.gno b/gnovm/tests/files/types/runtime_a2.gno index d53c9c4d970..0c1b8453591 100644 --- a/gnovm/tests/files/types/runtime_a2.gno +++ b/gnovm/tests/files/types/runtime_a2.gno @@ -8,7 +8,7 @@ func gen() interface{} { func main() { r := gen() - fmt.Printf("%T \n", r) + fmt.Printf("%T\n", r) } // Output: diff --git a/gnovm/tests/files/types/shift_a12.gno b/gnovm/tests/files/types/shift_a12.gno index 5735854d684..272373b19a6 100644 --- a/gnovm/tests/files/types/shift_a12.gno +++ b/gnovm/tests/files/types/shift_a12.gno @@ -6,7 +6,7 @@ func main() { a := uint(1) r := uint64(1) << a println(r) - fmt.Printf("%T \n", r) + fmt.Printf("%T\n", r) } // Output: diff --git a/gnovm/tests/files/types/shift_a13.gno b/gnovm/tests/files/types/shift_a13.gno index 7d70cc3589a..4ff5c6b7753 100644 --- a/gnovm/tests/files/types/shift_a13.gno +++ b/gnovm/tests/files/types/shift_a13.gno @@ -4,7 +4,7 @@ import "fmt" func main() { var r uint64 = 1 << int8(1) - fmt.Printf("%T \n", r) + fmt.Printf("%T\n", r) println(r) }