MCPcopy Index your code
hub / github.com/Shopify/go-lua / TestError

Function TestError

vm_test.go:302–323  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

300}
301
302func TestError(t *testing.T) {
303 l := NewState()
304 BaseOpen(l)
305 errorHandled := false
306 program := "error('error')"
307 l.PushGoFunction(func(l *State) int {
308 if l.Top() == 0 {
309 t.Error("error handler received no arguments")
310 } else if errorMessage, ok := l.ToString(-1); !ok {
311 t.Errorf("error handler received %s instead of string", TypeNameOf(l, -1))
312 } else if errorMessage != chunkID(program)+":1: error" {
313 t.Errorf("error handler received '%s' instead of 'error'", errorMessage)
314 }
315 errorHandled = true
316 return 1
317 })
318 LoadString(l, program)
319 l.ProtectedCall(0, 0, -2)
320 if !errorHandled {
321 t.Error("error not handled")
322 }
323}
324
325func TestErrorf(t *testing.T) {
326 l := NewState()

Callers

nothing calls this directly

Calls 10

PushGoFunctionMethod · 0.95
TopMethod · 0.95
ToStringMethod · 0.95
ProtectedCallMethod · 0.95
NewStateFunction · 0.85
BaseOpenFunction · 0.85
TypeNameOfFunction · 0.85
chunkIDFunction · 0.85
LoadStringFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected