Debian Codegraph @

qtsuite/suite_test.go

raw
1 // Licensed under the MIT license, see LICENSE file for details.
2
3 package qtsuite_test
4
5 import (
6 "testing"
7
8 "github.com/go-quicktest/qt"
9 "github.com/go-quicktest/qt/qtsuite"
10 )
11
12 func TestRunSuite(t *testing.T) {
13 var calls []call
14 qtsuite.Run(t, testSuite{calls: &calls})
15 qt.Assert(t, qt.DeepEquals(calls, []call{
16 {"Test1", 0},
17 {"Test4", 0},
18 }))
19 }
20
21 func TestRunSuiteEmbedded(t *testing.T) {
22 var calls []call
23 suite := struct {
24 testSuite
25 }{testSuite: testSuite{calls: &calls}}
26 qtsuite.Run(t, suite)
27 qt.Assert(t, qt.DeepEquals(calls, []call{
28 {"Test1", 0},
29 {"Test4", 0},
30 }))
31 }
32
33 func TestRunSuitePtr(t *testing.T) {
34 var calls []call
35 qtsuite.Run(t, &testSuite{calls: &calls})
36 qt.Assert(t, qt.DeepEquals(calls, []call{
37 {"Init", 0},
38 {"Test1", 1},
39 {"Init", 0},
40 {"Test4", 1},
41 }))
42 }
43
44 type testSuite struct {
45 init int
46 calls *[]call
47 }
48
49 func (s testSuite) addCall(name string) {
50 *s.calls = append(*s.calls, call{Name: name, Init: s.init})
51 }
52
53 func (s *testSuite) Init(*testing.T) {
54 s.addCall("Init")
55 s.init++
56 }
57
58 func (s testSuite) Test1(*testing.T) {
59 s.addCall("Test1")
60 }
61
62 func (s testSuite) Test4(*testing.T) {
63 s.addCall("Test4")
64 }
65
66 func (s testSuite) Testa(*testing.T) {
67 s.addCall("Testa")
68 }
69
70 type call struct {
71 Name string
72 Init int
73 }
74
75 // It's not clear how to test this.
76 //
77 //func TestInvalidInit(t *testing.T) {
78 // c := qt.New(t)
79 // tt := &testingT{}
80 // tc := qt.New(tt)
81 // qtsuite.Run(tc, invalidTestSuite{})
82 // qt.Assert(t, qt.Equals(tt.fatalString(), "wrong signature for Init, must be Init(*testing.T)"))
83 //}
84 //
85 //type invalidTestSuite struct{}
86 //
87 //func (invalidTestSuite) Init() {}
88 //}