mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 18:53:29 +00:00
main: add interp tests
This one needed more advanced checking of the error messages, because we don't want to hardcode things like `!dbg !10` in the output.
This commit is contained in:
committed by
Ron Evans
parent
e409950492
commit
a5f78a3900
@@ -17,6 +17,7 @@ import (
|
|||||||
func TestErrors(t *testing.T) {
|
func TestErrors(t *testing.T) {
|
||||||
for _, name := range []string{
|
for _, name := range []string{
|
||||||
"cgo",
|
"cgo",
|
||||||
|
"interp",
|
||||||
"loader-importcycle",
|
"loader-importcycle",
|
||||||
"loader-invaliddep",
|
"loader-invaliddep",
|
||||||
"loader-invalidpackage",
|
"loader-invalidpackage",
|
||||||
|
|||||||
@@ -417,6 +417,10 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
|
|||||||
} else {
|
} else {
|
||||||
locals[inst.localIndex] = literalValue{uint8(0)}
|
locals[inst.localIndex] = literalValue{uint8(0)}
|
||||||
}
|
}
|
||||||
|
case callFn.name == "__tinygo_interp_raise_test_error":
|
||||||
|
// Special function that will trigger an error.
|
||||||
|
// This is used to test error reporting.
|
||||||
|
return nil, mem, r.errorAt(inst, errors.New("test error"))
|
||||||
case strings.HasSuffix(callFn.name, ".$typeassert"):
|
case strings.HasSuffix(callFn.name, ".$typeassert"):
|
||||||
if r.debug {
|
if r.debug {
|
||||||
fmt.Fprintln(os.Stderr, indent+"interface assert:", operands[1:])
|
fmt.Fprintln(os.Stderr, indent+"interface assert:", operands[1:])
|
||||||
|
|||||||
Vendored
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import _ "unsafe"
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func foo() {
|
||||||
|
interp_test_error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a function that always causes an error in interp, for testing.
|
||||||
|
//
|
||||||
|
//go:linkname interp_test_error __tinygo_interp_raise_test_error
|
||||||
|
func interp_test_error()
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// ERROR: # main
|
||||||
|
// ERROR: {{.*testdata[\\/]errors[\\/]interp\.go}}:10:19: test error
|
||||||
|
// ERROR: call void @__tinygo_interp_raise_test_error{{.*}}
|
||||||
|
// ERROR: {{}}
|
||||||
|
// ERROR: traceback:
|
||||||
|
// ERROR: {{.*testdata[\\/]errors[\\/]interp\.go}}:10:19:
|
||||||
|
// ERROR: call void @__tinygo_interp_raise_test_error{{.*}}
|
||||||
|
// ERROR: {{.*testdata[\\/]errors[\\/]interp\.go}}:6:5:
|
||||||
|
// ERROR: call void @main.foo{{.*}}
|
||||||
|
// ERROR: {{.*testdata[\\/]errors}}:
|
||||||
|
// ERROR: call void @"main.init#1"{{.*}}
|
||||||
Reference in New Issue
Block a user