diff options
| author | Paul Duffin <paulduffin@google.com> | 2021-03-09 13:18:10 +0000 |
|---|---|---|
| committer | Paul Duffin <paulduffin@google.com> | 2021-03-20 10:25:45 +0000 |
| commit | 2be9dcd3aa96663e2f61b4eb336fbf8ffee177d8 (patch) | |
| tree | 7d0d8edc3e7581a6d5fc4585f60886e2cbd7c8de /apex/apex_test.go | |
| parent | 34d433ad7ed5e22b9cb600c2eb2a61c7cdacfcab (diff) | |
Allow test handlers to be either FixturePreparer or testCustomizer
This allows the testCustomizers to be switched to FixturePreparers
incrementally rather than in one go.
Bug: 181070625
Test: m nothing
Change-Id: Idd9d2e28abf9b17fc46b5566ab8d3affa330287e
Diffstat (limited to 'apex/apex_test.go')
| -rw-r--r-- | apex/apex_test.go | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/apex/apex_test.go b/apex/apex_test.go index e32b9f375..1006a62c1 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -50,14 +50,14 @@ func names(s string) (ns []string) { return } -func testApexError(t *testing.T, pattern, bp string, handlers ...testCustomizer) { +func testApexError(t *testing.T, pattern, bp string, handlers ...interface{}) { t.Helper() testApexFixtureFactory(bp, handlers). ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(pattern)). RunTest(t) } -func testApex(t *testing.T, bp string, handlers ...testCustomizer) *android.TestContext { +func testApex(t *testing.T, bp string, handlers ...interface{}) *android.TestContext { t.Helper() result := testApexFixtureFactory(bp, handlers).RunTest(t) return result.TestContext @@ -208,14 +208,26 @@ var apexFixtureFactory = android.NewFixtureFactory( }), ) -func testApexFixtureFactory(bp string, handlers []testCustomizer) android.FixtureFactory { - factory := apexFixtureFactory.Extend( - android.FixtureCustomPreparer(func(fixture android.Fixture) { - for _, handler := range handlers { - handler(fixture.MockFS(), fixture.Config()) +func testApexFixtureFactory(bp string, handlers []interface{}) android.FixtureFactory { + var preparers []android.FixturePreparer + for _, handler := range handlers { + var preparer android.FixturePreparer + if p, ok := handler.(android.FixturePreparer); ok { + preparer = p + } else { + var customizer testCustomizer + if c, ok := handler.(testCustomizer); ok { + customizer = c + } else { + customizer = handler.(func(fs map[string][]byte, config android.Config)) } - }), - ) + preparer = android.FixtureCustomPreparer(func(fixture android.Fixture) { + customizer(fixture.MockFS(), fixture.Config()) + }) + } + preparers = append(preparers, preparer) + } + factory := apexFixtureFactory.Extend(preparers...) if bp != "" { factory = factory.Extend(android.FixtureWithRootAndroidBp(bp)) } |
