File: deferpanic_test.go

package info (click to toggle)
golang-github-frankban-quicktest 1.14.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: makefile: 2
file content (44 lines) | stat: -rw-r--r-- 863 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Licensed under the MIT license, see LICENSE file for details.

//go:build !go1.14
// +build !go1.14

package quicktest_test

import (
	"testing"

	qt "github.com/frankban/quicktest"
)

func TestCDeferCalledEvenAfterDeferPanic(t *testing.T) {
	// This test doesn't test anything useful under go 1.14 and
	// later when Cleanup is built in.
	c := qt.New(t)
	deferred1 := 0
	deferred2 := 0
	c.Defer(func() {
		deferred1++
	})
	c.Defer(func() {
		panic("scream and shout")
	})
	c.Defer(func() {
		deferred2++
	})
	c.Defer(func() {
		panic("run in circles")
	})
	func() {
		defer func() {
			c.Check(recover(), qt.Equals, "scream and shout")
		}()
		c.Done()
	}()
	c.Assert(deferred1, qt.Equals, 1)
	c.Assert(deferred2, qt.Equals, 1)
	// Check that calling Done again doesn't panic.
	c.Done()
	c.Assert(deferred1, qt.Equals, 1)
	c.Assert(deferred2, qt.Equals, 1)
}