(t *testing.T)
| 445 | } |
| 446 | |
| 447 | func TestContextWithCroutine(t *testing.T) { |
| 448 | L := NewState() |
| 449 | defer L.Close() |
| 450 | ctx, cancel := context.WithCancel(context.Background()) |
| 451 | L.SetContext(ctx) |
| 452 | defer cancel() |
| 453 | L.DoString(` |
| 454 | function coro() |
| 455 | local i = 0 |
| 456 | while true do |
| 457 | coroutine.yield(i) |
| 458 | i = i+1 |
| 459 | end |
| 460 | return i |
| 461 | end |
| 462 | `) |
| 463 | co, cocancel := L.NewThread() |
| 464 | defer cocancel() |
| 465 | fn := L.GetGlobal("coro").(*LFunction) |
| 466 | _, err, values := L.Resume(co, fn) |
| 467 | errorIfNotNil(t, err) |
| 468 | errorIfNotEqual(t, LNumber(0), values[0]) |
| 469 | // cancel the parent context |
| 470 | cancel() |
| 471 | _, err, values = L.Resume(co, fn) |
| 472 | errorIfNil(t, err) |
| 473 | errorIfFalse(t, strings.Contains(err.Error(), "context canceled"), "coroutine execution must be canceled when the parent context is canceled") |
| 474 | |
| 475 | } |
| 476 | |
| 477 | func TestPCallAfterFail(t *testing.T) { |
| 478 | L := NewState() |
nothing calls this directly
no test coverage detected
searching dependent graphs…