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