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

Function TestErrorf

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

Source from the content-addressed store, hash-verified

323}
324
325func TestErrorf(t *testing.T) {
326 l := NewState()
327 BaseOpen(l)
328 program := "-- script that is bigger than the max ID size\nhelper()\n" + strings.Repeat("--", idSize)
329 expectedErrorMessage := chunkID(program) + ":2: error"
330 l.PushGoFunction(func(l *State) int {
331 Errorf(l, "error")
332 return 0
333 })
334 l.SetGlobal("helper")
335 errorHandled := false
336 l.PushGoFunction(func(l *State) int {
337 if l.Top() == 0 {
338 t.Error("error handler received no arguments")
339 } else if errorMessage, ok := l.ToString(-1); !ok {
340 t.Errorf("error handler received %s instead of string", TypeNameOf(l, -1))
341 } else if errorMessage != expectedErrorMessage {
342 t.Errorf("error handler received '%s' instead of '%s'", errorMessage, expectedErrorMessage)
343 }
344 errorHandled = true
345 return 1
346 })
347 LoadString(l, program)
348 l.ProtectedCall(0, 0, -2)
349 if !errorHandled {
350 t.Error("error not handled")
351 }
352}
353
354func TestPairsSplit(t *testing.T) {
355 testString(t, `

Callers

nothing calls this directly

Calls 12

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

Tested by

no test coverage detected