MCPcopy
hub / github.com/google/go-cmp / TestPanic

Function TestPanic

cmp/cmpopts/util_test.go:1172–1421  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1170}
1171
1172func TestPanic(t *testing.T) {
1173 args := func(x ...interface{}) []interface{} { return x }
1174 tests := []struct {
1175 label string // Test name
1176 fnc interface{} // Option function to call
1177 args []interface{} // Arguments to pass in
1178 wantPanic string // Expected panic message
1179 reason string // The reason for the expected outcome
1180 }{{
1181 label: "EquateApprox",
1182 fnc: EquateApprox,
1183 args: args(0.0, 0.0),
1184 reason: "zero margin and fraction is equivalent to exact equality",
1185 }, {
1186 label: "EquateApprox",
1187 fnc: EquateApprox,
1188 args: args(-0.1, 0.0),
1189 wantPanic: "margin or fraction must be a non-negative number",
1190 reason: "negative inputs are invalid",
1191 }, {
1192 label: "EquateApprox",
1193 fnc: EquateApprox,
1194 args: args(0.0, -0.1),
1195 wantPanic: "margin or fraction must be a non-negative number",
1196 reason: "negative inputs are invalid",
1197 }, {
1198 label: "EquateApprox",
1199 fnc: EquateApprox,
1200 args: args(math.NaN(), 0.0),
1201 wantPanic: "margin or fraction must be a non-negative number",
1202 reason: "NaN inputs are invalid",
1203 }, {
1204 label: "EquateApprox",
1205 fnc: EquateApprox,
1206 args: args(1.0, 0.0),
1207 reason: "fraction of 1.0 or greater is valid",
1208 }, {
1209 label: "EquateApprox",
1210 fnc: EquateApprox,
1211 args: args(0.0, math.Inf(+1)),
1212 reason: "margin of infinity is valid",
1213 }, {
1214 label: "EquateApproxTime",
1215 fnc: EquateApproxTime,
1216 args: args(time.Duration(-1)),
1217 wantPanic: "margin must be a non-negative number",
1218 reason: "negative duration is invalid",
1219 }, {
1220 label: "SortSlices",
1221 fnc: SortSlices,
1222 args: args((func(_, _ int) bool)(nil)),
1223 wantPanic: "invalid less or compare function",
1224 reason: "nil value is not valid",
1225 }, {
1226 label: "SortMaps",
1227 fnc: SortMaps,
1228 args: args((func(_, _ int) bool)(nil)),
1229 wantPanic: "invalid less or compare function",

Callers

nothing calls this directly

Calls 2

TypeMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected