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
diff --git a/sdk/testing.go b/sdk/testing.go
index 7a2540a..c401c86 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -19,7 +19,6 @@
"io/ioutil"
"os"
"path/filepath"
- "reflect"
"strings"
"testing"
@@ -141,7 +140,7 @@
_, errs = ctx.PrepareBuildActions(config)
android.FailIfErrored(t, errs)
return &testSdkResult{
- TestHelper: TestHelper{t: t},
+ TestHelper: android.TestHelper{T: t},
ctx: ctx,
config: config,
}
@@ -185,63 +184,10 @@
return ret
}
-// Provides general test support.
-type TestHelper struct {
- t *testing.T
-}
-
-func (h *TestHelper) AssertStringEquals(message string, expected string, actual string) {
- h.t.Helper()
- if actual != expected {
- h.t.Errorf("%s: expected %s, actual %s", message, expected, actual)
- }
-}
-
-func (h *TestHelper) AssertErrorMessageEquals(message string, expected string, actual error) {
- h.t.Helper()
- if actual == nil {
- h.t.Errorf("Expected error but was nil")
- } else if actual.Error() != expected {
- h.t.Errorf("%s: expected %s, actual %s", message, expected, actual.Error())
- }
-}
-
-func (h *TestHelper) AssertTrimmedStringEquals(message string, expected string, actual string) {
- h.t.Helper()
- expected = strings.TrimSpace(expected)
- actual = strings.TrimSpace(actual)
- if actual != expected {
- h.t.Errorf("%s: expected:\n%s\nactual:\n%s\n", message, expected, actual)
- }
-}
-
-func (h *TestHelper) AssertDeepEquals(message string, expected interface{}, actual interface{}) {
- h.t.Helper()
- if !reflect.DeepEqual(actual, expected) {
- h.t.Errorf("%s: expected %#v, actual %#v", message, expected, actual)
- }
-}
-
-func (h *TestHelper) AssertPanic(message string, funcThatShouldPanic func()) {
- h.t.Helper()
- panicked := false
- func() {
- defer func() {
- if x := recover(); x != nil {
- panicked = true
- }
- }()
- funcThatShouldPanic()
- }()
- if !panicked {
- h.t.Error(message)
- }
-}
-
// Encapsulates result of processing an SDK definition. Provides support for
// checking the state of the build structures.
type testSdkResult struct {
- TestHelper
+ android.TestHelper
ctx *android.TestContext
config android.Config
}
@@ -295,7 +241,7 @@
info.intermediateZip = info.outputZip
mergeInput := android.NormalizePathForTesting(bp.Input)
if info.intermediateZip != mergeInput {
- r.t.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead",
+ r.Errorf("Expected intermediate zip %s to be an input to merge zips but found %s instead",
info.intermediateZip, mergeInput)
}
@@ -328,7 +274,7 @@
// Allows each test to customize what is checked without duplicating lots of code
// or proliferating check methods of different flavors.
func (r *testSdkResult) CheckSnapshot(name string, dir string, checkers ...snapshotBuildInfoChecker) {
- r.t.Helper()
+ r.Helper()
// The sdk CommonOS variant is always responsible for generating the snapshot.
variant := android.CommonOS.Name
@@ -358,7 +304,7 @@
}
// Process the generated bp file to make sure it is valid.
- testSdkWithFs(r.t, snapshotBuildInfo.androidBpContents, fs)
+ testSdkWithFs(r.T, snapshotBuildInfo.androidBpContents, fs)
}
type snapshotBuildInfoChecker func(info *snapshotBuildInfo)
@@ -368,7 +314,7 @@
// Both the expected and actual string are both trimmed before comparing.
func checkAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.t.Helper()
+ info.r.Helper()
info.r.AssertTrimmedStringEquals("Android.bp contents do not match", expected, info.androidBpContents)
}
}
@@ -380,7 +326,7 @@
// Both the expected and actual string are both trimmed before comparing.
func checkUnversionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.t.Helper()
+ info.r.Helper()
info.r.AssertTrimmedStringEquals("unversioned Android.bp contents do not match", expected, info.androidUnversionedBpContents)
}
}
@@ -395,7 +341,7 @@
// Both the expected and actual string are both trimmed before comparing.
func checkVersionedAndroidBpContents(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.t.Helper()
+ info.r.Helper()
info.r.AssertTrimmedStringEquals("versioned Android.bp contents do not match", expected, info.androidVersionedBpContents)
}
}
@@ -407,14 +353,14 @@
// before comparing.
func checkAllCopyRules(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.t.Helper()
+ info.r.Helper()
info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.copyRules)
}
}
func checkAllOtherCopyRules(expected string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.t.Helper()
+ info.r.Helper()
info.r.AssertTrimmedStringEquals("Incorrect copy rules", expected, info.otherCopyRules)
}
}
@@ -422,9 +368,9 @@
// Check that the specified paths match the list of zips to merge with the intermediate zip.
func checkMergeZips(expected ...string) snapshotBuildInfoChecker {
return func(info *snapshotBuildInfo) {
- info.r.t.Helper()
+ info.r.Helper()
if info.intermediateZip == "" {
- info.r.t.Errorf("No intermediate zip file was created")
+ info.r.Errorf("No intermediate zip file was created")
}
info.r.AssertDeepEquals("mismatching merge zip files", expected, info.mergeZips)