(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestRecoverableT(t *testing.T) { |
| 12 | t.Run("FailNow marks test as failed", func(t *testing.T) { |
| 13 | inner := &mockTB{} |
| 14 | rt := NewRecoverableT(inner) |
| 15 | defer rt.Recover() |
| 16 | |
| 17 | rt.FailNow() |
| 18 | |
| 19 | assert.True(t, inner.failed, "expected underlying TB to be marked as failed") |
| 20 | }) |
| 21 | |
| 22 | t.Run("Fatal marks test as failed", func(t *testing.T) { |
| 23 | inner := &mockTB{} |
| 24 | rt := NewRecoverableT(inner) |
| 25 | defer rt.Recover() |
| 26 | |
| 27 | rt.Fatal("something went wrong") |
| 28 | |
| 29 | assert.True(t, inner.failed, "expected underlying TB to be marked as failed") |
| 30 | assert.Contains(t, inner.lastError, "something went wrong") |
| 31 | }) |
| 32 | |
| 33 | t.Run("Fatalf marks test as failed", func(t *testing.T) { |
| 34 | inner := &mockTB{} |
| 35 | rt := NewRecoverableT(inner) |
| 36 | defer rt.Recover() |
| 37 | |
| 38 | rt.Fatalf("value is %d", 42) |
| 39 | |
| 40 | assert.True(t, inner.failed, "expected underlying TB to be marked as failed") |
| 41 | assert.Contains(t, inner.lastError, "value is 42") |
| 42 | }) |
| 43 | |
| 44 | t.Run("Recover catches FailNow", func(t *testing.T) { |
| 45 | inner := &mockTB{} |
| 46 | rt := NewRecoverableT(inner) |
| 47 | |
| 48 | func() { |
| 49 | defer rt.Recover() |
| 50 | rt.FailNow() |
| 51 | t.Fatal("should not reach here") |
| 52 | }() |
| 53 | |
| 54 | assert.True(t, inner.failed) |
| 55 | }) |
| 56 | |
| 57 | t.Run("Recover re-raises non-sentinel panic", func(t *testing.T) { |
| 58 | inner := &mockTB{} |
| 59 | rt := NewRecoverableT(inner) |
| 60 | |
| 61 | assert.PanicsWithValue(t, "real panic", func() { |
| 62 | defer rt.Recover() |
| 63 | panic("real panic") |
| 64 | }) |
| 65 | }) |
| 66 | |
| 67 | t.Run("RecoverError returns ErrTestFailed", func(t *testing.T) { |
| 68 | inner := &mockTB{} |
nothing calls this directly
no test coverage detected