(t *testing.T)
| 277 | } |
| 278 | |
| 279 | func TestPCall(t *testing.T) { |
| 280 | L := NewState() |
| 281 | defer L.Close() |
| 282 | L.Register("f1", func(L *LState) int { |
| 283 | panic("panic!") |
| 284 | return 0 |
| 285 | }) |
| 286 | errorIfScriptNotFail(t, L, `f1()`, "panic!") |
| 287 | L.Push(L.GetGlobal("f1")) |
| 288 | err := L.PCall(0, 0, L.NewFunction(func(L *LState) int { |
| 289 | L.Push(LString("by handler")) |
| 290 | return 1 |
| 291 | })) |
| 292 | errorIfFalse(t, strings.Contains(err.Error(), "by handler"), "") |
| 293 | |
| 294 | L.Push(L.GetGlobal("f1")) |
| 295 | err = L.PCall(0, 0, L.NewFunction(func(L *LState) int { |
| 296 | L.RaiseError("error!") |
| 297 | return 1 |
| 298 | })) |
| 299 | errorIfFalse(t, strings.Contains(err.Error(), "error!"), "") |
| 300 | |
| 301 | L.Push(L.GetGlobal("f1")) |
| 302 | err = L.PCall(0, 0, L.NewFunction(func(L *LState) int { |
| 303 | panic("panicc!") |
| 304 | return 1 |
| 305 | })) |
| 306 | errorIfFalse(t, strings.Contains(err.Error(), "panicc!"), "") |
| 307 | |
| 308 | // Issue #452, expected to be revert back to previous call stack after any error. |
| 309 | currentFrame, currentTop, currentSp := L.currentFrame, L.GetTop(), L.stack.Sp() |
| 310 | L.Push(L.GetGlobal("f1")) |
| 311 | err = L.PCall(0, 0, nil) |
| 312 | errorIfFalse(t, err != nil, "") |
| 313 | errorIfFalse(t, L.currentFrame == currentFrame, "") |
| 314 | errorIfFalse(t, L.GetTop() == currentTop, "") |
| 315 | errorIfFalse(t, L.stack.Sp() == currentSp, "") |
| 316 | |
| 317 | currentFrame, currentTop, currentSp = L.currentFrame, L.GetTop(), L.stack.Sp() |
| 318 | L.Push(L.GetGlobal("f1")) |
| 319 | err = L.PCall(0, 0, L.NewFunction(func(L *LState) int { |
| 320 | L.RaiseError("error!") |
| 321 | return 1 |
| 322 | })) |
| 323 | errorIfFalse(t, err != nil, "") |
| 324 | errorIfFalse(t, L.currentFrame == currentFrame, "") |
| 325 | errorIfFalse(t, L.GetTop() == currentTop, "") |
| 326 | errorIfFalse(t, L.stack.Sp() == currentSp, "") |
| 327 | } |
| 328 | |
| 329 | func TestCoroutineApi1(t *testing.T) { |
| 330 | L := NewState() |
nothing calls this directly
no test coverage detected
searching dependent graphs…