From 93299802139012ba8e80a99ee406319430ef7277 Mon Sep 17 00:00:00 2001 From: Morgan Date: Mon, 3 Jun 2024 19:42:40 +0200 Subject: [PATCH] chore(gnovm): move invalid labels tests to tests/files/ (#2058) See-also https://github.com/gnolang/gno/pull/1877/files#r1568968846 --- gnovm/pkg/gnolang/gno_test.go | 86 --------------------------- gnovm/tests/files/invalid_labels0.gno | 14 +++++ gnovm/tests/files/invalid_labels1.gno | 12 ++++ gnovm/tests/files/invalid_labels2.gno | 15 +++++ gnovm/tests/files/invalid_labels3.gno | 12 ++++ 5 files changed, 53 insertions(+), 86 deletions(-) create mode 100644 gnovm/tests/files/invalid_labels0.gno create mode 100644 gnovm/tests/files/invalid_labels1.gno create mode 100644 gnovm/tests/files/invalid_labels2.gno create mode 100644 gnovm/tests/files/invalid_labels3.gno diff --git a/gnovm/pkg/gnolang/gno_test.go b/gnovm/pkg/gnolang/gno_test.go index 741b2158a08..24a92a81312 100644 --- a/gnovm/pkg/gnolang/gno_test.go +++ b/gnovm/pkg/gnolang/gno_test.go @@ -42,92 +42,6 @@ func BenchmarkStringLargeData(b *testing.B) { } } -func TestRunInvalidLabels(t *testing.T) { - tests := []struct { - code string - output string - }{ - { - code: ` - package test - func main(){} - func invalidLabel() { - FirstLoop: - for i := 0; i < 10; i++ { - } - for i := 0; i < 10; i++ { - break FirstLoop - } - } -`, - output: `cannot find branch label "FirstLoop"`, - }, - { - code: ` - package test - func main(){} - - func undefinedLabel() { - for i := 0; i < 10; i++ { - break UndefinedLabel - } - } -`, - output: `label UndefinedLabel undefined`, - }, - { - code: ` - package test - func main(){} - - func labelOutsideScope() { - for i := 0; i < 10; i++ { - continue FirstLoop - } - FirstLoop: - for i := 0; i < 10; i++ { - } - } -`, - output: `cannot find branch label "FirstLoop"`, - }, - { - code: ` - package test - func main(){} - - func invalidLabelStatement() { - if true { - break InvalidLabel - } - } -`, - output: `label InvalidLabel undefined`, - }, - } - - for n, s := range tests { - n := n - t.Run(fmt.Sprintf("%v\n", n), func(t *testing.T) { - defer func() { - if r := recover(); r != nil { - es := fmt.Sprintf("%v\n", r) - if !strings.Contains(es, s.output) { - t.Fatalf("invalid label test: `%v` missing expected error: %+v got: %v\n", n, s.output, es) - } - } else { - t.Fatalf("invalid label test: `%v` should have failed but didn't\n", n) - } - }() - - m := NewMachine("test", nil) - nn := MustParseFile("main.go", s.code) - m.RunFiles(nn) - m.RunMain() - }) - } -} - func TestBuiltinIdentifiersShadowing(t *testing.T) { t.Parallel() tests := map[string]string{} diff --git a/gnovm/tests/files/invalid_labels0.gno b/gnovm/tests/files/invalid_labels0.gno new file mode 100644 index 00000000000..14e5489ec21 --- /dev/null +++ b/gnovm/tests/files/invalid_labels0.gno @@ -0,0 +1,14 @@ +package main + +func main() {} +func invalidLabel() { +FirstLoop: + for i := 0; i < 10; i++ { + } + for i := 0; i < 10; i++ { + break FirstLoop + } +} + +// Error: +// main/files/invalid_labels0.gno:9: cannot find branch label "FirstLoop" diff --git a/gnovm/tests/files/invalid_labels1.gno b/gnovm/tests/files/invalid_labels1.gno new file mode 100644 index 00000000000..40513c338eb --- /dev/null +++ b/gnovm/tests/files/invalid_labels1.gno @@ -0,0 +1,12 @@ +package main + +func main() {} + +func undefinedLabel() { + for i := 0; i < 10; i++ { + break UndefinedLabel + } +} + +// Error: +// files/invalid_labels1.gno:7:9: label UndefinedLabel undefined diff --git a/gnovm/tests/files/invalid_labels2.gno b/gnovm/tests/files/invalid_labels2.gno new file mode 100644 index 00000000000..0f4a5305484 --- /dev/null +++ b/gnovm/tests/files/invalid_labels2.gno @@ -0,0 +1,15 @@ +package main + +func main() {} + +func labelOutsideScope() { + for i := 0; i < 10; i++ { + continue FirstLoop + } +FirstLoop: + for i := 0; i < 10; i++ { + } +} + +// Error: +// main/files/invalid_labels2.gno:7: cannot find branch label "FirstLoop" diff --git a/gnovm/tests/files/invalid_labels3.gno b/gnovm/tests/files/invalid_labels3.gno new file mode 100644 index 00000000000..3d36b010fa6 --- /dev/null +++ b/gnovm/tests/files/invalid_labels3.gno @@ -0,0 +1,12 @@ +package main + +func main() {} + +func invalidLabelStatement() { + if true { + break InvalidLabel + } +} + +// Error: +// files/invalid_labels3.gno:7:9: label InvalidLabel undefined