Remove duplicate sdk.TestHelper

As part of the work on the new fixture mechanism some of the TestHelper
functionality was moved into the android/fixture.go package. This moves
the rest and removes the now duplicated TestHelper from the sdk
package.

Also removed some unnecessary & operators.

Bug: 181070625
Test: m nothing
Change-Id: Ia09a5d05e4fab3a4e28cf44b2d947a33541e3925
This commit is contained in:
Paul Duffin
2021-03-10 09:15:22 +00:00
parent 706cb6f344
commit a3cb2b396f
4 changed files with 50 additions and 75 deletions

View File

@@ -484,6 +484,18 @@ func (h *TestHelper) AssertStringEquals(message string, expected string, actual
}
}
// AssertErrorMessageEquals checks if the error is not nil and has the expected message. If it does
// not then this reports an error prefixed with the supplied message and including a reason for why
// it failed.
func (h *TestHelper) AssertErrorMessageEquals(message string, expected string, actual error) {
h.Helper()
if actual == nil {
h.Errorf("Expected error but was nil")
} else if actual.Error() != expected {
h.Errorf("%s: expected %s, actual %s", message, expected, actual.Error())
}
}
// AssertTrimmedStringEquals checks if the expected and actual values are the same after trimming
// leading and trailing spaces from them both. If they are not then it reports an error prefixed
// with the supplied message and including a reason for why it failed.
@@ -538,6 +550,23 @@ func (h *TestHelper) AssertDeepEquals(message string, expected interface{}, actu
}
}
// AssertPanic checks that the supplied function panics as expected.
func (h *TestHelper) AssertPanic(message string, funcThatShouldPanic func()) {
h.Helper()
panicked := false
func() {
defer func() {
if x := recover(); x != nil {
panicked = true
}
}()
funcThatShouldPanic()
}()
if !panicked {
h.Error(message)
}
}
// Struct to allow TestResult to embed a *TestContext and allow call forwarding to its methods.
type testContext struct {
*TestContext