| 399 | } |
| 400 | |
| 401 | func TestLocIsCorrectOnRegisteredFuncCall(t *testing.T) { |
| 402 | l := NewState() |
| 403 | l.Register("barf", func(l *State) int { |
| 404 | Errorf(l, "Boom!") |
| 405 | return 0 |
| 406 | }) |
| 407 | if err := l.Load(strings.NewReader(` |
| 408 | local thing = barf() -- line 2; is the source of the error |
| 409 | print(thing) -- line 3; this won't execute, and must NOT be the loc of the error! |
| 410 | `), "test", ""); err != nil { |
| 411 | t.Errorf("Unexpected error! Got %v", err) |
| 412 | } |
| 413 | err := l.ProtectedCall(0, 0, 0) |
| 414 | if err == nil { |
| 415 | t.Errorf("Expected error! Got none... :(") |
| 416 | } else { |
| 417 | if err.Error() != "runtime error: [string \"test\"]:2: Boom!" { |
| 418 | t.Errorf("Wrong error reported: %v", err) |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | func TestLocIsCorrectOnFuncCall(t *testing.T) { |
| 424 | l := NewState() |