summaryrefslogtreecommitdiff
path: root/java/testing.go
diff options
context:
space:
mode:
author Jihoon Kang <jihoonkang@google.com> 2023-10-09 18:00:17 +0000
committer Jihoon Kang <jihoonkang@google.com> 2023-10-11 16:18:45 +0000
commitf00200b6fb18aa671c7840a8c9013fc270c31520 (patch)
treecf6379c9997f20130b6f0a1b2948d734aa6edb4b /java/testing.go
parent8f83dcd18c6bead85384e359a69ba36b3883b252 (diff)
Add module dependency checking testing method
Currently in Soong testing suite, the only method for testing module dependency is CheckModuleDependencies(...), which comapares for the exact module dependencies. This change adds the method CheckModuleDependency(...) which enables checking the dependency between two modules, instead of comparing for all dependencies of an interested module. Test: m nothing Bug: 288624417 Change-Id: I804d35979ddc24b0134671e326c1d37615ec4190
Diffstat (limited to 'java/testing.go')
-rw-r--r--java/testing.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/java/testing.go b/java/testing.go
index 335c98398..446135116 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -574,7 +574,7 @@ func gatherRequiredDepsForTest() string {
return bp
}
-func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
+func getModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string) []string {
t.Helper()
module := ctx.ModuleForTests(name, variant).Module()
deps := []string{}
@@ -583,11 +583,29 @@ func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, varia
})
sort.Strings(deps)
+ return deps
+}
+
+// CheckModuleDependencies checks if the expected dependencies of the module are
+// identical to the actual dependencies.
+func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
+ deps := getModuleDependencies(t, ctx, name, variant)
+
if actual := deps; !reflect.DeepEqual(expected, actual) {
t.Errorf("expected %#q, found %#q", expected, actual)
}
}
+// CheckModuleHasDependency returns true if the module depends on the expected dependency.
+func CheckModuleHasDependency(t *testing.T, ctx *android.TestContext, name, variant string, expected string) bool {
+ for _, dep := range getModuleDependencies(t, ctx, name, variant) {
+ if dep == expected {
+ return true
+ }
+ }
+ return false
+}
+
// CheckPlatformBootclasspathModules returns the apex:module pair for the modules depended upon by
// the platform-bootclasspath module.
func CheckPlatformBootclasspathModules(t *testing.T, result *android.TestResult, name string, expected []string) {