From f00200b6fb18aa671c7840a8c9013fc270c31520 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Mon, 9 Oct 2023 18:00:17 +0000 Subject: 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 --- java/testing.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'java/testing.go') 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) { -- cgit v1.2.3-59-g8ed1b