Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bb2b219 authored by Paul Duffin's avatar Paul Duffin
Browse files

Convert android/variable_test.go to test fixtures

Bug: 182885307
Test: m nothing
Change-Id: I51d3651244b110bf41cb0e4c331ac663bf816f84
parent 791302b4
Loading
Loading
Loading
Loading
+38 −49
Original line number Diff line number Diff line
@@ -181,10 +181,12 @@ func TestProductVariables(t *testing.T) {
			name: "baz",
		}
	`
	config := TestConfig(buildDir, nil, bp, nil)
	config.TestProductVariables.Eng = proptools.BoolPtr(true)

	ctx := NewTestContext(config)
	emptyTestFixtureFactory.RunTest(t,
		FixtureModifyProductVariables(func(variables FixtureProductVariables) {
			variables.Eng = proptools.BoolPtr(true)
		}),
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			// A module type that has a srcs property but not a cflags property.
			ctx.RegisterModuleType("module1", testProductVariableModuleFactoryFactory(&struct {
				Srcs []string
@@ -200,13 +202,9 @@ func TestProductVariables(t *testing.T) {
			ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
				ctx.BottomUp("variable", VariableMutator).Parallel()
			})

	ctx.Register()

	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	_, errs = ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)
		}),
		FixtureWithRootAndroidBp(bp),
	)
}

var testProductVariableDefaultsProperties = struct {
@@ -290,32 +288,23 @@ func TestProductVariablesDefaults(t *testing.T) {
		}
	`

	config := TestConfig(buildDir, nil, bp, nil)
	config.TestProductVariables.Eng = boolPtr(true)

	ctx := NewTestContext(config)

	result := emptyTestFixtureFactory.RunTest(t,
		FixtureModifyProductVariables(func(variables FixtureProductVariables) {
			variables.Eng = boolPtr(true)
		}),
		PrepareForTestWithDefaults,
		PrepareForTestWithVariables,
		FixtureRegisterWithContext(func(ctx RegistrationContext) {
			ctx.RegisterModuleType("test", productVariablesDefaultsTestModuleFactory)
			ctx.RegisterModuleType("defaults", productVariablesDefaultsTestDefaultsFactory)
		}),
		FixtureWithRootAndroidBp(bp),
	)

	ctx.PreArchMutators(RegisterDefaultsPreArchMutators)
	ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
		ctx.BottomUp("variable", VariableMutator).Parallel()
	})

	ctx.Register()

	_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
	FailIfErrored(t, errs)
	_, errs = ctx.PrepareBuildActions(config)
	FailIfErrored(t, errs)

	foo := ctx.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule)
	foo := result.ModuleForTests("foo", "").Module().(*productVariablesDefaultsTestModule)

	want := []string{"defaults", "module", "product_variable_defaults", "product_variable_module"}
	if g, w := foo.properties.Foo, want; !reflect.DeepEqual(g, w) {
		t.Errorf("expected foo %q, got %q", w, g)
	}
	AssertDeepEquals(t, "foo", want, foo.properties.Foo)
}

func BenchmarkSliceToTypeArray(b *testing.B) {