Merge "Remove varargs from Fixture(t *testing.T)" am: 301099e451 am: cffb5bf2c4

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1660017

Change-Id: I6fd47a0e21b990b279b61225d94ff93ba58bfa08
This commit is contained in:
Paul Duffin 2021-03-31 18:27:49 +00:00 committed by Automerger Merge Worker
commit dc6f50ba96
2 changed files with 17 additions and 22 deletions

View File

@ -455,7 +455,7 @@ type FixturePreparer interface {
Extend(preparers ...FixturePreparer) FixturePreparer
// Create a Fixture.
Fixture(t *testing.T, preparers ...FixturePreparer) Fixture
Fixture(t *testing.T) Fixture
// ExtendWithErrorHandler creates a new FixturePreparer that will use the supplied error handler
// to check the errors (may be 0) reported by the test.
@ -706,13 +706,11 @@ type TestResult struct {
NinjaDeps []string
}
func createFixture(t *testing.T, buildDir string, base []*simpleFixturePreparer, extra []FixturePreparer) Fixture {
all := dedupAndFlattenPreparers(base, extra)
func createFixture(t *testing.T, buildDir string, preparers []*simpleFixturePreparer) Fixture {
config := TestConfig(buildDir, nil, "", nil)
ctx := NewTestContext(config)
fixture := &fixture{
preparers: all,
preparers: preparers,
t: t,
config: config,
ctx: ctx,
@ -721,7 +719,7 @@ func createFixture(t *testing.T, buildDir string, base []*simpleFixturePreparer,
errorHandler: FixtureExpectsNoErrors,
}
for _, preparer := range all {
for _, preparer := range preparers {
preparer.function(fixture)
}
@ -741,8 +739,8 @@ func (b *baseFixturePreparer) Extend(preparers ...FixturePreparer) FixturePrepar
return newFixturePreparer(all)
}
func (b *baseFixturePreparer) Fixture(t *testing.T, preparers ...FixturePreparer) Fixture {
return createFixture(t, t.TempDir(), b.self.list(), preparers)
func (b *baseFixturePreparer) Fixture(t *testing.T) Fixture {
return createFixture(t, t.TempDir(), b.self.list())
}
func (b *baseFixturePreparer) ExtendWithErrorHandler(errorHandler FixtureErrorHandler) FixturePreparer {
@ -812,16 +810,16 @@ func (f *fixtureFactory) Extend(preparers ...FixturePreparer) FixturePreparer {
return extendedFactory
}
func (f *fixtureFactory) Fixture(t *testing.T, preparers ...FixturePreparer) Fixture {
func (f *fixtureFactory) Fixture(t *testing.T) Fixture {
// If there is no buildDirSupplier then just use the default implementation.
if f.buildDirSupplier == nil {
return f.baseFixturePreparer.Fixture(t, preparers...)
return f.baseFixturePreparer.Fixture(t)
}
// Retrieve the buildDir from the supplier.
buildDir := *f.buildDirSupplier
return createFixture(t, buildDir, f.preparers, preparers)
return createFixture(t, buildDir, f.preparers)
}
type fixture struct {

View File

@ -43,43 +43,40 @@ func TestFixtureDedup(t *testing.T) {
extension := group.Extend(preparer4, preparer2)
extension.Fixture(t, preparer1, preparer2, preparer2Then1, preparer3)
GroupFixturePreparers(extension, preparer1, preparer2, preparer2Then1, preparer3).Fixture(t)
AssertDeepEquals(t, "preparers called in wrong order",
[]string{"preparer1", "preparer2", "preparer4", "preparer3"}, list)
}
func TestFixtureValidateMockFS(t *testing.T) {
buildDir := "<unused>"
factory := NewFixtureFactory(&buildDir)
t.Run("absolute path", func(t *testing.T) {
AssertPanicMessageContains(t, "source path validation failed", "Path is outside directory: /abs/path/Android.bp", func() {
factory.Fixture(t, FixtureAddFile("/abs/path/Android.bp", nil))
FixtureAddFile("/abs/path/Android.bp", nil).Fixture(t)
})
})
t.Run("not canonical", func(t *testing.T) {
AssertPanicMessageContains(t, "source path validation failed", `path "path/with/../in/it/Android.bp" is not a canonical path, use "path/in/it/Android.bp" instead`, func() {
factory.Fixture(t, FixtureAddFile("path/with/../in/it/Android.bp", nil))
FixtureAddFile("path/with/../in/it/Android.bp", nil).Fixture(t)
})
})
t.Run("FixtureAddFile", func(t *testing.T) {
AssertPanicMessageContains(t, "source path validation failed", `cannot add output path "out/Android.bp" to the mock file system`, func() {
factory.Fixture(t, FixtureAddFile("out/Android.bp", nil))
FixtureAddFile("out/Android.bp", nil).Fixture(t)
})
})
t.Run("FixtureMergeMockFs", func(t *testing.T) {
AssertPanicMessageContains(t, "source path validation failed", `cannot add output path "out/Android.bp" to the mock file system`, func() {
factory.Fixture(t, FixtureMergeMockFs(MockFS{
FixtureMergeMockFs(MockFS{
"out/Android.bp": nil,
}))
}).Fixture(t)
})
})
t.Run("FixtureModifyMockFS", func(t *testing.T) {
AssertPanicMessageContains(t, "source path validation failed", `cannot add output path "out/Android.bp" to the mock file system`, func() {
factory.Fixture(t, FixtureModifyMockFS(func(fs MockFS) {
FixtureModifyMockFS(func(fs MockFS) {
fs["out/Android.bp"] = nil
}))
}).Fixture(t)
})
})
}