Stop error handler relying on testing.T being embedded in TestResult
This change is in preparation for removing testing.T from TestResult. Bug: 181070625 Test: m nothing Change-Id: Iac627cc3c9f922ec4a41ce657442e4139fe7defb
This commit is contained in:
@@ -467,16 +467,16 @@ type FixtureErrorHandler interface {
|
|||||||
// The supplied result can be used to access the state of the code under test just as the main
|
// The supplied result can be used to access the state of the code under test just as the main
|
||||||
// body of the test would but if any errors other than ones expected are reported the state may
|
// body of the test would but if any errors other than ones expected are reported the state may
|
||||||
// be indeterminate.
|
// be indeterminate.
|
||||||
CheckErrors(result *TestResult)
|
CheckErrors(t *testing.T, result *TestResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
type simpleErrorHandler struct {
|
type simpleErrorHandler struct {
|
||||||
function func(result *TestResult)
|
function func(t *testing.T, result *TestResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h simpleErrorHandler) CheckErrors(result *TestResult) {
|
func (h simpleErrorHandler) CheckErrors(t *testing.T, result *TestResult) {
|
||||||
result.Helper()
|
t.Helper()
|
||||||
h.function(result)
|
h.function(t, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The default fixture error handler.
|
// The default fixture error handler.
|
||||||
@@ -486,9 +486,9 @@ func (h simpleErrorHandler) CheckErrors(result *TestResult) {
|
|||||||
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
|
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
|
||||||
// which the test is being run which means that the RunTest() method will not return.
|
// which the test is being run which means that the RunTest() method will not return.
|
||||||
var FixtureExpectsNoErrors = FixtureCustomErrorHandler(
|
var FixtureExpectsNoErrors = FixtureCustomErrorHandler(
|
||||||
func(result *TestResult) {
|
func(t *testing.T, result *TestResult) {
|
||||||
result.Helper()
|
t.Helper()
|
||||||
FailIfErrored(result.T, result.Errs)
|
FailIfErrored(t, result.Errs)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -505,10 +505,10 @@ var FixtureExpectsNoErrors = FixtureCustomErrorHandler(
|
|||||||
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
|
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
|
||||||
// which the test is being run which means that the RunTest() method will not return.
|
// which the test is being run which means that the RunTest() method will not return.
|
||||||
func FixtureExpectsAtLeastOneErrorMatchingPattern(pattern string) FixtureErrorHandler {
|
func FixtureExpectsAtLeastOneErrorMatchingPattern(pattern string) FixtureErrorHandler {
|
||||||
return FixtureCustomErrorHandler(func(result *TestResult) {
|
return FixtureCustomErrorHandler(func(t *testing.T, result *TestResult) {
|
||||||
result.Helper()
|
t.Helper()
|
||||||
if !FailIfNoMatchingErrors(result.T, pattern, result.Errs) {
|
if !FailIfNoMatchingErrors(t, pattern, result.Errs) {
|
||||||
result.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -527,14 +527,14 @@ func FixtureExpectsAtLeastOneErrorMatchingPattern(pattern string) FixtureErrorHa
|
|||||||
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
|
// If the test fails this handler will call `result.FailNow()` which will exit the goroutine within
|
||||||
// which the test is being run which means that the RunTest() method will not return.
|
// which the test is being run which means that the RunTest() method will not return.
|
||||||
func FixtureExpectsAllErrorsToMatchAPattern(patterns []string) FixtureErrorHandler {
|
func FixtureExpectsAllErrorsToMatchAPattern(patterns []string) FixtureErrorHandler {
|
||||||
return FixtureCustomErrorHandler(func(result *TestResult) {
|
return FixtureCustomErrorHandler(func(t *testing.T, result *TestResult) {
|
||||||
result.Helper()
|
t.Helper()
|
||||||
CheckErrorsAgainstExpectations(result.T, result.Errs, patterns)
|
CheckErrorsAgainstExpectations(t, result.Errs, patterns)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// FixtureCustomErrorHandler creates a custom error handler
|
// FixtureCustomErrorHandler creates a custom error handler
|
||||||
func FixtureCustomErrorHandler(function func(result *TestResult)) FixtureErrorHandler {
|
func FixtureCustomErrorHandler(function func(t *testing.T, result *TestResult)) FixtureErrorHandler {
|
||||||
return simpleErrorHandler{
|
return simpleErrorHandler{
|
||||||
function: function,
|
function: function,
|
||||||
}
|
}
|
||||||
@@ -705,7 +705,7 @@ func (f *fixture) RunTest() *TestResult {
|
|||||||
Errs: errs,
|
Errs: errs,
|
||||||
}
|
}
|
||||||
|
|
||||||
f.errorHandler.CheckErrors(result)
|
f.errorHandler.CheckErrors(f.t, result)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user