aboutsummaryrefslogtreecommitdiffstats
path: root/android/namespace_test.go
diff options
context:
space:
mode:
authorJeff Gaston <jeffrygaston@google.com>2017-11-30 16:46:47 -0800
committerJeff Gaston <jeffrygaston@google.com>2017-12-04 17:44:32 -0800
commit5c3886de5a1eabb81e7d166a86c29ca324dabf49 (patch)
treed98c6eb7d8f55b49d19d3a5b4d5e81e135019a08 /android/namespace_test.go
parent44c0cd85435d7c90cbf6d5f930a64edac15b42ee (diff)
downloadbuild_soong-5c3886de5a1eabb81e7d166a86c29ca324dabf49.tar.gz
build_soong-5c3886de5a1eabb81e7d166a86c29ca324dabf49.tar.bz2
build_soong-5c3886de5a1eabb81e7d166a86c29ca324dabf49.zip
require namespaces to be declared only in files named Android.bp
Bug: 65683273 Test: m -j nothing # which runs unit tests Change-Id: I5edf0e0482809f5ac9fb9dfff342fb404e1c52da
Diffstat (limited to 'android/namespace_test.go')
-rw-r--r--android/namespace_test.go57
1 files changed, 44 insertions, 13 deletions
diff --git a/android/namespace_test.go b/android/namespace_test.go
index b10b5287..13da88b4 100644
--- a/android/namespace_test.go
+++ b/android/namespace_test.go
@@ -151,7 +151,7 @@ func TestDependingOnModuleInNonImportedNamespace(t *testing.T) {
expectedErrors := []error{
errors.New(
- `dir3/Blueprints:4:4: "b" depends on undefined module "a"
+ `dir3/Android.bp:4:4: "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"]`),
}
@@ -373,7 +373,7 @@ func TestImportingNonexistentNamespace(t *testing.T) {
// should complain about the missing namespace and not complain about the unresolvable dependency
expectedErrors := []error{
- errors.New(`dir1/Blueprints:2:4: module "soong_namespace": namespace a_nonexistent_namespace does not exist`),
+ 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)
@@ -402,7 +402,7 @@ func TestNamespacesDontInheritParentNamespaces(t *testing.T) {
)
expectedErrors := []error{
- errors.New(`dir1/subdir1/Blueprints:4:4: "b" depends on undefined module "a"
+ errors.New(`dir1/subdir1/Android.bp:4:4: "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"]`),
}
@@ -465,7 +465,7 @@ func TestNamespaceImportsNotTransitive(t *testing.T) {
)
expectedErrors := []error{
- errors.New(`dir3/Blueprints:5:4: "c" depends on undefined module "a"
+ errors.New(`dir3/Android.bp:5:4: "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"]`),
}
@@ -487,7 +487,7 @@ func TestTwoNamepacesInSameDir(t *testing.T) {
)
expectedErrors := []error{
- errors.New(`dir1/Blueprints:4:4: namespace dir1 already exists`),
+ 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)
@@ -508,7 +508,7 @@ func TestNamespaceNotAtTopOfFile(t *testing.T) {
)
expectedErrors := []error{
- errors.New(`dir1/Blueprints:5:4: a namespace must be the first module in the file`),
+ 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)
@@ -532,26 +532,48 @@ func TestTwoModulesWithSameNameInSameNamespace(t *testing.T) {
)
expectedErrors := []error{
- errors.New(`dir1/Blueprints:7:4: module "a" already defined
- dir1/Blueprints:4:4 <-- previous definition here`),
+ 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)
}
}
+func TestDeclaringNamespaceInNonAndroidBpFile(t *testing.T) {
+ _, errs := setupTestFromFiles(
+ map[string][]byte{
+ "Android.bp": []byte(`
+ build = ["include.bp"]
+ `),
+ "include.bp": []byte(`
+ 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)
+ }
+}
+
// some utils to support the tests
func mockFiles(bps map[string]string) (files map[string][]byte) {
files = make(map[string][]byte, len(bps))
- files["Blueprints"] = []byte("")
+ files["Android.bp"] = []byte("")
for dir, text := range bps {
- files[filepath.Join(dir, "Blueprints")] = []byte(text)
+ files[filepath.Join(dir, "Android.bp")] = []byte(text)
}
return files
}
-func setupTestExpectErrs(bps map[string]string) (ctx *TestContext, errs []error) {
+func setupTestFromFiles(bps map[string][]byte) (ctx *TestContext, errs []error) {
buildDir, err := ioutil.TempDir("", "soong_namespace_test")
if err != nil {
return nil, []error{err}
@@ -561,13 +583,13 @@ func setupTestExpectErrs(bps map[string]string) (ctx *TestContext, errs []error)
config := TestConfig(buildDir, nil)
ctx = NewTestContext()
- ctx.MockFileSystem(mockFiles(bps))
+ ctx.MockFileSystem(bps)
ctx.RegisterModuleType("test_module", ModuleFactoryAdaptor(newTestModule))
ctx.RegisterModuleType("soong_namespace", ModuleFactoryAdaptor(NamespaceFactory))
ctx.PreDepsMutators(RegisterNamespaceMutator)
ctx.Register()
- _, errs = ctx.ParseBlueprintsFiles("Blueprints")
+ _, errs = ctx.ParseBlueprintsFiles("Android.bp")
if len(errs) > 0 {
return ctx, errs
}
@@ -575,6 +597,15 @@ func setupTestExpectErrs(bps map[string]string) (ctx *TestContext, errs []error)
return ctx, errs
}
+func setupTestExpectErrs(bps map[string]string) (ctx *TestContext, errs []error) {
+ 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 setupTestFromFiles(files)
+}
+
func setupTest(t *testing.T, bps map[string]string) (ctx *TestContext) {
ctx, errs := setupTestExpectErrs(bps)
failIfErrored(t, errs)