Make CheckHiddenAPIRuleInputs more reusable
Adds a message parameter and allows leading spaces in the expected file string to allow them to be nicely indented. Bug: 177892522 Test: m nothing Change-Id: I33df26610738c48879fa0b8250dc377dd04bb07d
This commit is contained in:
@@ -4643,7 +4643,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
t.Helper()
|
t.Helper()
|
||||||
platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common")
|
platformBootclasspath := ctx.ModuleForTests("platform-bootclasspath", "android_common")
|
||||||
indexRule := platformBootclasspath.Rule("monolithic_hidden_API_index")
|
indexRule := platformBootclasspath.Rule("monolithic_hidden_API_index")
|
||||||
java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule)
|
java.CheckHiddenAPIRuleInputs(t, "index", expectedInputs, indexRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment := java.ApexVariantReference{
|
fragment := java.ApexVariantReference{
|
||||||
@@ -4694,9 +4694,9 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
// Verify the correct module jars contribute to the hiddenapi index file.
|
// Verify the correct module jars contribute to the hiddenapi index file.
|
||||||
checkHiddenAPIIndexInputs(t, ctx, `
|
checkHiddenAPIIndexInputs(t, ctx, `
|
||||||
.intermediates/libbar.stubs/android_common/combined/libbar.stubs.jar
|
out/soong/.intermediates/libbar.stubs/android_common/combined/libbar.stubs.jar
|
||||||
.intermediates/libfoo/android_common_myapex/combined/libfoo.jar
|
out/soong/.intermediates/libfoo/android_common_myapex/combined/libfoo.jar
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("apex_set only", func(t *testing.T) {
|
t.Run("apex_set only", func(t *testing.T) {
|
||||||
@@ -4735,9 +4735,9 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
// Verify the correct module jars contribute to the hiddenapi index file.
|
// Verify the correct module jars contribute to the hiddenapi index file.
|
||||||
checkHiddenAPIIndexInputs(t, ctx, `
|
checkHiddenAPIIndexInputs(t, ctx, `
|
||||||
.intermediates/libbar.stubs/android_common/combined/libbar.stubs.jar
|
out/soong/.intermediates/libbar.stubs/android_common/combined/libbar.stubs.jar
|
||||||
.intermediates/libfoo/android_common_myapex/combined/libfoo.jar
|
out/soong/.intermediates/libfoo/android_common_myapex/combined/libfoo.jar
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("prebuilt with source library preferred", func(t *testing.T) {
|
t.Run("prebuilt with source library preferred", func(t *testing.T) {
|
||||||
@@ -4856,9 +4856,9 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
// Verify the correct module jars contribute to the hiddenapi index file.
|
// Verify the correct module jars contribute to the hiddenapi index file.
|
||||||
checkHiddenAPIIndexInputs(t, ctx, `
|
checkHiddenAPIIndexInputs(t, ctx, `
|
||||||
.intermediates/prebuilt_libbar.stubs/android_common/combined/libbar.stubs.jar
|
out/soong/.intermediates/prebuilt_libbar.stubs/android_common/combined/libbar.stubs.jar
|
||||||
.intermediates/prebuilt_libfoo/android_common_myapex/combined/libfoo.jar
|
out/soong/.intermediates/prebuilt_libfoo/android_common_myapex/combined/libfoo.jar
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("prebuilt with source apex preferred", func(t *testing.T) {
|
t.Run("prebuilt with source apex preferred", func(t *testing.T) {
|
||||||
@@ -4930,9 +4930,9 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
// Verify the correct module jars contribute to the hiddenapi index file.
|
// Verify the correct module jars contribute to the hiddenapi index file.
|
||||||
checkHiddenAPIIndexInputs(t, ctx, `
|
checkHiddenAPIIndexInputs(t, ctx, `
|
||||||
.intermediates/libbar/android_common_myapex/javac/libbar.jar
|
out/soong/.intermediates/libbar/android_common_myapex/javac/libbar.jar
|
||||||
.intermediates/libfoo/android_common_apex10000/javac/libfoo.jar
|
out/soong/.intermediates/libfoo/android_common_apex10000/javac/libfoo.jar
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) {
|
t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) {
|
||||||
@@ -5006,9 +5006,9 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
|
|||||||
|
|
||||||
// Verify the correct module jars contribute to the hiddenapi index file.
|
// Verify the correct module jars contribute to the hiddenapi index file.
|
||||||
checkHiddenAPIIndexInputs(t, ctx, `
|
checkHiddenAPIIndexInputs(t, ctx, `
|
||||||
.intermediates/prebuilt_libbar.stubs/android_common/combined/libbar.stubs.jar
|
out/soong/.intermediates/prebuilt_libbar.stubs/android_common/combined/libbar.stubs.jar
|
||||||
.intermediates/prebuilt_libfoo/android_common_myapex/combined/libfoo.jar
|
out/soong/.intermediates/prebuilt_libfoo/android_common_myapex/combined/libfoo.jar
|
||||||
`)
|
`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -319,10 +319,9 @@ func TestPlatformBootclasspath_HiddenAPIMonolithicFiles(t *testing.T) {
|
|||||||
// creates the index.csv file.
|
// creates the index.csv file.
|
||||||
platformBootclasspath := result.ModuleForTests("myplatform-bootclasspath", "android_common")
|
platformBootclasspath := result.ModuleForTests("myplatform-bootclasspath", "android_common")
|
||||||
indexRule := platformBootclasspath.Rule("monolithic_hidden_API_index")
|
indexRule := platformBootclasspath.Rule("monolithic_hidden_API_index")
|
||||||
CheckHiddenAPIRuleInputs(t, `
|
CheckHiddenAPIRuleInputs(t, "index", `
|
||||||
.intermediates/bar/android_common/javac/bar.jar
|
out/soong/.intermediates/bar/android_common/javac/bar.jar
|
||||||
.intermediates/foo-hiddenapi-annotations/android_common/javac/foo-hiddenapi-annotations.jar
|
out/soong/.intermediates/foo-hiddenapi-annotations/android_common/javac/foo-hiddenapi-annotations.jar
|
||||||
.intermediates/foo/android_common/javac/foo.jar
|
out/soong/.intermediates/foo/android_common/javac/foo.jar
|
||||||
`,
|
`, indexRule)
|
||||||
indexRule)
|
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ package java
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -393,12 +394,20 @@ func CheckPlatformBootclasspathFragments(t *testing.T, result *android.TestResul
|
|||||||
android.AssertDeepEquals(t, fmt.Sprintf("%s fragments", "platform-bootclasspath"), expected, pairs)
|
android.AssertDeepEquals(t, fmt.Sprintf("%s fragments", "platform-bootclasspath"), expected, pairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckHiddenAPIRuleInputs(t *testing.T, expected string, hiddenAPIRule android.TestingBuildParams) {
|
func CheckHiddenAPIRuleInputs(t *testing.T, message string, expected string, hiddenAPIRule android.TestingBuildParams) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
actual := strings.TrimSpace(strings.Join(android.NormalizePathsForTesting(hiddenAPIRule.Implicits), "\n"))
|
inputs := android.Paths{}
|
||||||
expected = strings.TrimSpace(expected)
|
if hiddenAPIRule.Input != nil {
|
||||||
|
inputs = append(inputs, hiddenAPIRule.Input)
|
||||||
|
}
|
||||||
|
inputs = append(inputs, hiddenAPIRule.Inputs...)
|
||||||
|
inputs = append(inputs, hiddenAPIRule.Implicits...)
|
||||||
|
inputs = android.SortedUniquePaths(inputs)
|
||||||
|
actual := strings.TrimSpace(strings.Join(inputs.RelativeToTop().Strings(), "\n"))
|
||||||
|
re := regexp.MustCompile(`\n\s+`)
|
||||||
|
expected = strings.TrimSpace(re.ReplaceAllString(expected, "\n"))
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
t.Errorf("Expected hiddenapi rule inputs:\n%s\nactual inputs:\n%s", expected, actual)
|
t.Errorf("Expected hiddenapi rule inputs - %s:\n%s\nactual inputs:\n%s", message, expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user