From 3f7bf9fa0ddb4c8da9996464e1472b46d53d6ad8 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Tue, 8 Nov 2022 12:21:15 +0000 Subject: Allow namespace config to be tested properly Previously, the NewTextContext created a context that always called NewNameResolver with a export filter that always returned true. This change fixes that by: 1. Changing NewNameResolver to take a Config parameter instead of a filter parameter and pushing the code to create the filter from the Config from newNameResolver() in cmd/soong_build/main.go into the NewNameResolver function. 2. Extracting a newTestContextForFixture that does not create a NameResolver or set it on the context. That avoids creating a NameResolver before the test has prepared the config. 3. Modify the fixture to create and set the NameResolver in the Context after the config has been prepared by the test. 4. Added test to verify that it all works. Bug: 234825639 Test: m nothing Change-Id: Ie4b13f18093dc01a0ab65a9ecfd143585d843b55 --- android/namespace_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'android/namespace_test.go') diff --git a/android/namespace_test.go b/android/namespace_test.go index 87d13206b..7a387a0bd 100644 --- a/android/namespace_test.go +++ b/android/namespace_test.go @@ -602,6 +602,36 @@ func TestRename(t *testing.T) { // RunTest will report any errors } +func TestNamespace_Exports(t *testing.T) { + result := GroupFixturePreparers( + prepareForTestWithNamespace, + FixtureModifyProductVariables(func(variables FixtureProductVariables) { + variables.NamespacesToExport = []string{"dir1"} + }), + dirBpToPreparer(map[string]string{ + "dir1": ` + soong_namespace { + } + test_module { + name: "a", + } + `, + "dir2": ` + soong_namespace { + } + test_module { + name: "b", + } + `, + }), + ).RunTest(t) + + aModule := result.Module("a", "") + AssertBoolEquals(t, "a exported", true, aModule.ExportedToMake()) + bModule := result.Module("b", "") + AssertBoolEquals(t, "b not exported", false, bModule.ExportedToMake()) +} + // some utils to support the tests var prepareForTestWithNamespace = GroupFixturePreparers( -- cgit v1.2.3-59-g8ed1b