File: suite_test.go

package info (click to toggle)
golang-github-go-quicktest-qt 1.101.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 236 kB
  • sloc: makefile: 2
file content (88 lines) | stat: -rw-r--r-- 1,624 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Licensed under the MIT license, see LICENSE file for details.

package qtsuite_test

import (
	"testing"

	"github.com/go-quicktest/qt"
	"github.com/go-quicktest/qt/qtsuite"
)

func TestRunSuite(t *testing.T) {
	var calls []call
	qtsuite.Run(t, testSuite{calls: &calls})
	qt.Assert(t, qt.DeepEquals(calls, []call{
		{"Test1", 0},
		{"Test4", 0},
	}))
}

func TestRunSuiteEmbedded(t *testing.T) {
	var calls []call
	suite := struct {
		testSuite
	}{testSuite: testSuite{calls: &calls}}
	qtsuite.Run(t, suite)
	qt.Assert(t, qt.DeepEquals(calls, []call{
		{"Test1", 0},
		{"Test4", 0},
	}))
}

func TestRunSuitePtr(t *testing.T) {
	var calls []call
	qtsuite.Run(t, &testSuite{calls: &calls})
	qt.Assert(t, qt.DeepEquals(calls, []call{
		{"Init", 0},
		{"Test1", 1},
		{"Init", 0},
		{"Test4", 1},
	}))
}

type testSuite struct {
	init  int
	calls *[]call
}

func (s testSuite) addCall(name string) {
	*s.calls = append(*s.calls, call{Name: name, Init: s.init})
}

func (s *testSuite) Init(*testing.T) {
	s.addCall("Init")
	s.init++
}

func (s testSuite) Test1(*testing.T) {
	s.addCall("Test1")
}

func (s testSuite) Test4(*testing.T) {
	s.addCall("Test4")
}

func (s testSuite) Testa(*testing.T) {
	s.addCall("Testa")
}

type call struct {
	Name string
	Init int
}

// It's not clear how to test this.
//
//func TestInvalidInit(t *testing.T) {
//	c := qt.New(t)
//	tt := &testingT{}
//	tc := qt.New(tt)
//	qtsuite.Run(tc, invalidTestSuite{})
//	qt.Assert(t, qt.Equals(tt.fatalString(), "wrong signature for Init, must be Init(*testing.T)"))
//}
//
//type invalidTestSuite struct{}
//
//func (invalidTestSuite) Init() {}
//}