summaryrefslogtreecommitdiff
path: root/android/namespace_test.go
diff options
context:
space:
mode:
author Paul Duffin <paulduffin@google.com> 2021-07-06 22:36:33 +0100
committer Paul Duffin <paulduffin@google.com> 2022-05-11 17:30:58 +0000
commit0fc6d32c8270ef0940db36aefe3e1a2d35daa3c7 (patch)
tree1f0ad24384d7d74f807fbb9efac18f85c2e2418b /android/namespace_test.go
parent61c6eef064d2fc72be422c91a70b59fda119adfc (diff)
Switch the namespace tests to fully use test fixtures
Indented the bp contents to make it easier to differentiate between them and the directory in which they belong. Bug: 181070625 Test: m nothing Change-Id: Iae7495fb7c88769dc688006a41f4d21f57cf03b8
Diffstat (limited to 'android/namespace_test.go')
-rw-r--r--android/namespace_test.go898
1 files changed, 430 insertions, 468 deletions
diff --git a/android/namespace_test.go b/android/namespace_test.go
index ea399da06..87d13206b 100644
--- a/android/namespace_test.go
+++ b/android/namespace_test.go
@@ -15,7 +15,6 @@
package android
import (
- "errors"
"path/filepath"
"reflect"
"testing"
@@ -24,577 +23,555 @@ import (
)
func TestDependingOnModuleInSameNamespace(t *testing.T) {
- ctx := setupTest(t,
- map[string]string{
+ result := GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
- test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- a := getModule(ctx, "a")
- b := getModule(ctx, "b")
- if !dependsOn(ctx, b, a) {
+ a := getModule(result, "a")
+ b := getModule(result, "b")
+ if !dependsOn(result, b, a) {
t.Errorf("module b does not depend on module a in the same namespace")
}
}
func TestDependingOnModuleInRootNamespace(t *testing.T) {
- ctx := setupTest(t,
- map[string]string{
+ result := GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
".": `
- test_module {
- name: "b",
- deps: ["a"],
- }
- test_module {
- name: "a",
- }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
+ test_module {
+ name: "a",
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- a := getModule(ctx, "a")
- b := getModule(ctx, "b")
- if !dependsOn(ctx, b, a) {
+ a := getModule(result, "a")
+ b := getModule(result, "b")
+ if !dependsOn(result, b, a) {
t.Errorf("module b in root namespace does not depend on module a in the root namespace")
}
}
func TestImplicitlyImportRootNamespace(t *testing.T) {
- _ = setupTest(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
".": `
- test_module {
- name: "a",
- }
+ test_module {
+ name: "a",
+ }
`,
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- // setupTest will report any errors
+ // RunTest will report any errors
}
func TestDependingOnBlueprintModuleInRootNamespace(t *testing.T) {
- _ = setupTest(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
".": `
- blueprint_test_module {
- name: "a",
- }
+ blueprint_test_module {
+ name: "a",
+ }
`,
"dir1": `
- soong_namespace {
- }
- blueprint_test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ }
+ blueprint_test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- // setupTest will report any errors
+ // RunTest will report any errors
}
func TestDependingOnModuleInImportedNamespace(t *testing.T) {
- ctx := setupTest(t,
- map[string]string{
+ result := GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
`,
"dir2": `
- soong_namespace {
- imports: ["dir1"],
- }
- test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ imports: ["dir1"],
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- a := getModule(ctx, "a")
- b := getModule(ctx, "b")
- if !dependsOn(ctx, b, a) {
+ a := getModule(result, "a")
+ b := getModule(result, "b")
+ if !dependsOn(result, b, a) {
t.Errorf("module b does not depend on module a in the same namespace")
}
}
func TestDependingOnModuleInNonImportedNamespace(t *testing.T) {
- _, errs := setupTestExpectErrs(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
`,
"dir2": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
`,
"dir3": `
- soong_namespace {
- }
- test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
-
- expectedErrors := []error{
- errors.New(
- `dir3/Android.bp:4:4: "b" depends on undefined module "a"
+ }),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir3/Android.bp:4:5: "b" depends on undefined module "a"
Module "b" is defined in namespace "dir3" which can read these 2 namespaces: ["dir3" "."]
-Module "a" can be found in these namespaces: ["dir1" "dir2"]`),
- }
-
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+Module "a" can be found in these namespaces: ["dir1" "dir2"]\E`)).
+ RunTest(t)
}
func TestDependingOnModuleByFullyQualifiedReference(t *testing.T) {
- ctx := setupTest(t,
- map[string]string{
+ result := GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
`,
"dir2": `
- soong_namespace {
- }
- test_module {
- name: "b",
- deps: ["//dir1:a"],
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "b",
+ deps: ["//dir1:a"],
+ }
`,
- },
- )
- a := getModule(ctx, "a")
- b := getModule(ctx, "b")
- if !dependsOn(ctx, b, a) {
+ }),
+ ).RunTest(t)
+
+ a := getModule(result, "a")
+ b := getModule(result, "b")
+ if !dependsOn(result, b, a) {
t.Errorf("module b does not depend on module a")
}
}
func TestSameNameInTwoNamespaces(t *testing.T) {
- ctx := setupTest(t,
- map[string]string{
+ result := GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- id: "1",
- }
- test_module {
- name: "b",
- deps: ["a"],
- id: "2",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ id: "1",
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ id: "2",
+ }
`,
"dir2": `
- soong_namespace {
- }
- test_module {
- name: "a",
- id:"3",
- }
- test_module {
- name: "b",
- deps: ["a"],
- id:"4",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ id:"3",
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ id:"4",
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- one := findModuleById(ctx, "1")
- two := findModuleById(ctx, "2")
- three := findModuleById(ctx, "3")
- four := findModuleById(ctx, "4")
- if !dependsOn(ctx, two, one) {
+ one := findModuleById(result, "1")
+ two := findModuleById(result, "2")
+ three := findModuleById(result, "3")
+ four := findModuleById(result, "4")
+ if !dependsOn(result, two, one) {
t.Fatalf("Module 2 does not depend on module 1 in its namespace")
}
- if dependsOn(ctx, two, three) {
+ if dependsOn(result, two, three) {
t.Fatalf("Module 2 depends on module 3 in another namespace")
}
- if !dependsOn(ctx, four, three) {
+ if !dependsOn(result, four, three) {
t.Fatalf("Module 4 does not depend on module 3 in its namespace")
}
- if dependsOn(ctx, four, one) {
+ if dependsOn(result, four, one) {
t.Fatalf("Module 4 depends on module 1 in another namespace")
}
}
func TestSearchOrder(t *testing.T) {
- ctx := setupTest(t,
- map[string]string{
+ result := GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- id: "1",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ id: "1",
+ }
`,
"dir2": `
- soong_namespace {
- }
- test_module {
- name: "a",
- id:"2",
- }
- test_module {
- name: "b",
- id:"3",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ id:"2",
+ }
+ test_module {
+ name: "b",
+ id:"3",
+ }
`,
"dir3": `
- soong_namespace {
- }
- test_module {
- name: "a",
- id:"4",
- }
- test_module {
- name: "b",
- id:"5",
- }
- test_module {
- name: "c",
- id:"6",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ id:"4",
+ }
+ test_module {
+ name: "b",
+ id:"5",
+ }
+ test_module {
+ name: "c",
+ id:"6",
+ }
`,
".": `
- test_module {
- name: "a",
- id: "7",
- }
- test_module {
- name: "b",
- id: "8",
- }
- test_module {
- name: "c",
- id: "9",
- }
- test_module {
- name: "d",
- id: "10",
- }
+ test_module {
+ name: "a",
+ id: "7",
+ }
+ test_module {
+ name: "b",
+ id: "8",
+ }
+ test_module {
+ name: "c",
+ id: "9",
+ }
+ test_module {
+ name: "d",
+ id: "10",
+ }
`,
"dir4": `
- soong_namespace {
- imports: ["dir1", "dir2", "dir3"]
- }
- test_module {
- name: "test_me",
- id:"0",
- deps: ["a", "b", "c", "d"],
- }
+ soong_namespace {
+ imports: ["dir1", "dir2", "dir3"]
+ }
+ test_module {
+ name: "test_me",
+ id:"0",
+ deps: ["a", "b", "c", "d"],
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- testMe := findModuleById(ctx, "0")
- if !dependsOn(ctx, testMe, findModuleById(ctx, "1")) {
+ testMe := findModuleById(result, "0")
+ if !dependsOn(result, testMe, findModuleById(result, "1")) {
t.Errorf("test_me doesn't depend on id 1")
}
- if !dependsOn(ctx, testMe, findModuleById(ctx, "3")) {
+ if !dependsOn(result, testMe, findModuleById(result, "3")) {
t.Errorf("test_me doesn't depend on id 3")
}
- if !dependsOn(ctx, testMe, findModuleById(ctx, "6")) {
+ if !dependsOn(result, testMe, findModuleById(result, "6")) {
t.Errorf("test_me doesn't depend on id 6")
}
- if !dependsOn(ctx, testMe, findModuleById(ctx, "10")) {
+ if !dependsOn(result, testMe, findModuleById(result, "10")) {
t.Errorf("test_me doesn't depend on id 10")
}
- if numDeps(ctx, testMe) != 4 {
- t.Errorf("num dependencies of test_me = %v, not 4\n", numDeps(ctx, testMe))
+ if numDeps(result, testMe) != 4 {
+ t.Errorf("num dependencies of test_me = %v, not 4\n", numDeps(result, testMe))
}
}
func TestTwoNamespacesCanImportEachOther(t *testing.T) {
- _ = setupTest(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- imports: ["dir2"]
- }
- test_module {
- name: "a",
- }
- test_module {
- name: "c",
- deps: ["b"],
- }
+ soong_namespace {
+ imports: ["dir2"]
+ }
+ test_module {
+ name: "a",
+ }
+ test_module {
+ name: "c",
+ deps: ["b"],
+ }
`,
"dir2": `
- soong_namespace {
- imports: ["dir1"],
- }
- test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ imports: ["dir1"],
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- // setupTest will report any errors
+ // RunTest will report any errors
}
func TestImportingNonexistentNamespace(t *testing.T) {
- _, errs := setupTestExpectErrs(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- imports: ["a_nonexistent_namespace"]
- }
- test_module {
- name: "a",
- deps: ["a_nonexistent_module"]
- }
+ soong_namespace {
+ imports: ["a_nonexistent_namespace"]
+ }
+ test_module {
+ name: "a",
+ deps: ["a_nonexistent_module"]
+ }
`,
- },
- )
-
- // should complain about the missing namespace and not complain about the unresolvable dependency
- expectedErrors := []error{
- errors.New(`dir1/Android.bp:2:4: module "soong_namespace": namespace a_nonexistent_namespace does not exist`),
- }
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+ }),
+ ).
+ // should complain about the missing namespace and not complain about the unresolvable dependency
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:2:5: module "soong_namespace": namespace a_nonexistent_namespace does not exist\E`)).
+ RunTest(t)
}
func TestNamespacesDontInheritParentNamespaces(t *testing.T) {
- _, errs := setupTestExpectErrs(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
`,
"dir1/subdir1": `
- soong_namespace {
- }
- test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
-
- expectedErrors := []error{
- errors.New(`dir1/subdir1/Android.bp:4:4: "b" depends on undefined module "a"
+ }),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/subdir1/Android.bp:4:5: "b" depends on undefined module "a"
Module "b" is defined in namespace "dir1/subdir1" which can read these 2 namespaces: ["dir1/subdir1" "."]
-Module "a" can be found in these namespaces: ["dir1"]`),
- }
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+Module "a" can be found in these namespaces: ["dir1"]\E`)).
+ RunTest(t)
}
func TestModulesDoReceiveParentNamespace(t *testing.T) {
- _ = setupTest(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
`,
"dir1/subdir": `
- test_module {
- name: "b",
- deps: ["a"],
- }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
- },
- )
+ }),
+ ).RunTest(t)
- // setupTest will report any errors
+ // RunTest will report any errors
}
func TestNamespaceImportsNotTransitive(t *testing.T) {
- _, errs := setupTestExpectErrs(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ }
`,
"dir2": `
- soong_namespace {
- imports: ["dir1"],
- }
- test_module {
- name: "b",
- deps: ["a"],
- }
+ soong_namespace {
+ imports: ["dir1"],
+ }
+ test_module {
+ name: "b",
+ deps: ["a"],
+ }
`,
"dir3": `
- soong_namespace {
- imports: ["dir2"],
- }
- test_module {
- name: "c",
- deps: ["a"],
- }
+ soong_namespace {
+ imports: ["dir2"],
+ }
+ test_module {
+ name: "c",
+ deps: ["a"],
+ }
`,
- },
- )
-
- expectedErrors := []error{
- errors.New(`dir3/Android.bp:5:4: "c" depends on undefined module "a"
+ }),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir3/Android.bp:5:5: "c" depends on undefined module "a"
Module "c" is defined in namespace "dir3" which can read these 3 namespaces: ["dir3" "dir2" "."]
-Module "a" can be found in these namespaces: ["dir1"]`),
- }
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+Module "a" can be found in these namespaces: ["dir1"]\E`)).
+ RunTest(t)
}
func TestTwoNamepacesInSameDir(t *testing.T) {
- _, errs := setupTestExpectErrs(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- soong_namespace {
- }
+ soong_namespace {
+ }
+ soong_namespace {
+ }
`,
- },
- )
-
- expectedErrors := []error{
- errors.New(`dir1/Android.bp:4:4: namespace dir1 already exists`),
- }
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+ }),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:4:5: namespace dir1 already exists\E`)).
+ RunTest(t)
}
func TestNamespaceNotAtTopOfFile(t *testing.T) {
- _, errs := setupTestExpectErrs(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- test_module {
- name: "a"
- }
- soong_namespace {
- }
+ test_module {
+ name: "a"
+ }
+ soong_namespace {
+ }
`,
- },
- )
-
- expectedErrors := []error{
- errors.New(`dir1/Android.bp:5:4: a namespace must be the first module in the file`),
- }
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+ }),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:5:5: a namespace must be the first module in the file\E`)).
+ RunTest(t)
}
func TestTwoModulesWithSameNameInSameNamespace(t *testing.T) {
- _, errs := setupTestExpectErrs(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a"
- }
- test_module {
- name: "a"
- }
+ soong_namespace {
+ }
+ test_module {
+ name: "a"
+ }
+ test_module {
+ name: "a"
+ }
`,
- },
- )
-
- expectedErrors := []error{
- errors.New(`dir1/Android.bp:7:4: module "a" already defined
- dir1/Android.bp:4:4 <-- previous definition here`),
- }
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+ }),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(`\Qdir1/Android.bp:7:5: module "a" already defined
+ dir1/Android.bp:4:5 <-- previous definition here\E`)).
+ RunTest(t)
}
func TestDeclaringNamespaceInNonAndroidBpFile(t *testing.T) {
- _, errs := setupTestFromFiles(t,
- map[string][]byte{
- "Android.bp": []byte(`
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ FixtureWithRootAndroidBp(`
build = ["include.bp"]
- `),
- "include.bp": []byte(`
+ `),
+ FixtureAddTextFile("include.bp", `
soong_namespace {
}
- `),
- },
- )
-
- expectedErrors := []error{
- errors.New(`include.bp:2:5: A namespace may only be declared in a file named Android.bp`),
- }
-
- if len(errs) != 1 || errs[0].Error() != expectedErrors[0].Error() {
- t.Errorf("Incorrect errors. Expected:\n%v\n, got:\n%v\n", expectedErrors, errs)
- }
+ `),
+ ).
+ ExtendWithErrorHandler(FixtureExpectsOneErrorPattern(
+ `\Qinclude.bp:2:5: A namespace may only be declared in a file named Android.bp\E`,
+ )).
+ RunTest(t)
}
// so that the generated .ninja file will have consistent names
func TestConsistentNamespaceNames(t *testing.T) {
- ctx := setupTest(t,
- map[string]string{
+ result := GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": "soong_namespace{}",
"dir2": "soong_namespace{}",
"dir3": "soong_namespace{}",
- })
+ }),
+ ).RunTest(t)
- ns1, _ := ctx.NameResolver.namespaceAt("dir1")
- ns2, _ := ctx.NameResolver.namespaceAt("dir2")
- ns3, _ := ctx.NameResolver.namespaceAt("dir3")
+ ns1, _ := result.NameResolver.namespaceAt("dir1")
+ ns2, _ := result.NameResolver.namespaceAt("dir2")
+ ns3, _ := result.NameResolver.namespaceAt("dir3")
actualIds := []string{ns1.id, ns2.id, ns3.id}
expectedIds := []string{"1", "2", "3"}
if !reflect.DeepEqual(actualIds, expectedIds) {
@@ -604,103 +581,88 @@ func TestConsistentNamespaceNames(t *testing.T) {
// so that the generated .ninja file will have consistent names
func TestRename(t *testing.T) {
- _ = setupTest(t,
- map[string]string{
+ GroupFixturePreparers(
+ prepareForTestWithNamespace,
+ dirBpToPreparer(map[string]string{
"dir1": `
- soong_namespace {
- }
- test_module {
- name: "a",
- deps: ["c"],
- }
- test_module {
- name: "b",
- rename: "c",
- }
- `})
- // setupTest will report any errors
-}
-
-// some utils to support the tests
+ soong_namespace {
+ }
+ test_module {
+ name: "a",
+ deps: ["c"],
+ }
+ test_module {
+ name: "b",
+ rename: "c",
+ }
+ `,
+ }),
+ ).RunTest(t)
-func mockFiles(bps map[string]string) (files map[string][]byte) {
- files = make(map[string][]byte, len(bps))
- files["Android.bp"] = []byte("")
- for dir, text := range bps {
- files[filepath.Join(dir, "Android.bp")] = []byte(text)
- }
- return files
+ // RunTest will report any errors
}
-func setupTestFromFiles(t *testing.T, bps MockFS) (ctx *TestContext, errs []error) {
- result := GroupFixturePreparers(
- FixtureModifyContext(func(ctx *TestContext) {
- ctx.RegisterModuleType("test_module", newTestModule)
- ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule)
- ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
- ctx.BottomUp("rename", renameMutator)
- })
- }),
- PrepareForTestWithNamespace,
- bps.AddToFixture(),
- ).
- // Ignore errors for now so tests can check them later.
- ExtendWithErrorHandler(FixtureIgnoreErrors).
- RunTest(t)
+// some utils to support the tests
- return result.TestContext, result.Errs
-}
+var prepareForTestWithNamespace = GroupFixturePreparers(
+ FixtureRegisterWithContext(registerNamespaceBuildComponents),
+ FixtureRegisterWithContext(func(ctx RegistrationContext) {
+ ctx.PreArchMutators(RegisterNamespaceMutator)
+ }),
+ FixtureModifyContext(func(ctx *TestContext) {
+ ctx.RegisterModuleType("test_module", newTestModule)
+ ctx.Context.RegisterModuleType("blueprint_test_module", newBlueprintTestModule)
+ ctx.PreDepsMutators(func(ctx RegisterMutatorsContext) {
+ ctx.BottomUp("rename", renameMutator)
+ })
+ }),
+)
-func setupTestExpectErrs(t *testing.T, bps map[string]string) (ctx *TestContext, errs []error) {
- files := make(map[string][]byte, len(bps))
+// dirBpToPreparer takes a map from directory to the contents of the Android.bp file and produces a
+// FixturePreparer.
+func dirBpToPreparer(bps map[string]string) FixturePreparer {
+ files := make(MockFS, len(bps))
files["Android.bp"] = []byte("")
for dir, text := range bps {
files[filepath.Join(dir, "Android.bp")] = []byte(text)
}
- return setupTestFromFiles(t, files)
-}
-
-func setupTest(t *testing.T, bps map[string]string) (ctx *TestContext) {
- t.Helper()
- ctx, errs := setupTestExpectErrs(t, bps)
- FailIfErrored(t, errs)
- return ctx
+ return files.AddToFixture()
}
-func dependsOn(ctx *TestContext, module TestingModule, possibleDependency TestingModule) bool {
+func dependsOn(result *TestResult, module TestingModule, possibleDependency TestingModule) bool {
depends := false
visit := func(dependency blueprint.Module) {
if dependency == possibleDependency.module {
depends = true
}
}
- ctx.VisitDirectDeps(module.module, visit)
+ result.VisitDirectDeps(module.module, visit)
return depends
}
-func numDeps(ctx *TestContext, module TestingModule) int {
+func numDeps(result *TestResult, module TestingModule) int {
count := 0
visit := func(dependency blueprint.Module) {
count++
}
- ctx.VisitDirectDeps(module.module, visit)
+ result.VisitDirectDeps(module.module, visit)
return count
}
-func getModule(ctx *TestContext, moduleName string) TestingModule {
- return ctx.ModuleForTests(moduleName, "")
+func getModule(result *TestResult, moduleName string) TestingModule {
+ return result.ModuleForTests(moduleName, "")
}
-func findModuleById(ctx *TestContext, id string) (module TestingModule) {
+func findModuleById(result *TestResult, id string) (module TestingModule) {
visit := func(candidate blueprint.Module) {
testModule, ok := candidate.(*testModule)
if ok {
if testModule.properties.Id == id {
- module = newTestingModule(ctx.config, testModule)
+ module = newTestingModule(result.config, testModule)
}
}
}
- ctx.VisitAllModules(visit)
+ result.VisitAllModules(visit)
return module
}
@@ -747,7 +709,7 @@ type blueprintTestModule struct {
}
}
-func (b *blueprintTestModule) DynamicDependencies(ctx blueprint.DynamicDependerModuleContext) []string {
+func (b *blueprintTestModule) DynamicDependencies(_ blueprint.DynamicDependerModuleContext) []string {
return b.properties.Deps
}