Ensure subtest failures are reported on subtest
A subtest (code inside the func passed to t.Run(...)) are passed their
own t *Testing pointer to use to report errors in order to ensure that
they are treated as errors of the subtest and not the containing test.
This change ensures that the subtests in the following tests use the
correct t *Testing.
* TestPrebuiltExportDexImplementationJars
* TestBootDexJarsFromSourcesAndPrebuilts
Bug: 178361284
Test: m nothing
Change-Id: I4e8b166051cb6098c89d8e68a450c81a714f7677
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 85d6259..9f8cd06 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -4362,7 +4362,7 @@
// Empty transformation.
}
- checkDexJarBuildPath := func(ctx *android.TestContext, name string) {
+ checkDexJarBuildPath := func(t *testing.T, ctx *android.TestContext, name string) {
// Make sure the import has been given the correct path to the dex jar.
p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.Dependency)
dexJarBuildPath := p.DexJarBuildPath()
@@ -4371,7 +4371,7 @@
}
}
- ensureNoSourceVariant := func(ctx *android.TestContext) {
+ ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext) {
// Make sure that an apex variant is not created for the source module.
if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests("libfoo"); !reflect.DeepEqual(expected, actual) {
t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual)
@@ -4402,7 +4402,7 @@
// Make sure that dexpreopt can access dex implementation files from the prebuilt.
ctx := testDexpreoptWithApexes(t, bp, "", transform)
- checkDexJarBuildPath(ctx, "libfoo")
+ checkDexJarBuildPath(t, ctx, "libfoo")
})
t.Run("prebuilt with source preferred", func(t *testing.T) {
@@ -4434,8 +4434,8 @@
// Make sure that dexpreopt can access dex implementation files from the prebuilt.
ctx := testDexpreoptWithApexes(t, bp, "", transform)
- checkDexJarBuildPath(ctx, "prebuilt_libfoo")
- ensureNoSourceVariant(ctx)
+ checkDexJarBuildPath(t, ctx, "prebuilt_libfoo")
+ ensureNoSourceVariant(t, ctx)
})
t.Run("prebuilt preferred with source", func(t *testing.T) {
@@ -4467,8 +4467,8 @@
// Make sure that dexpreopt can access dex implementation files from the prebuilt.
ctx := testDexpreoptWithApexes(t, bp, "", transform)
- checkDexJarBuildPath(ctx, "prebuilt_libfoo")
- ensureNoSourceVariant(ctx)
+ checkDexJarBuildPath(t, ctx, "prebuilt_libfoo")
+ ensureNoSourceVariant(t, ctx)
})
}
@@ -4477,7 +4477,7 @@
config.BootJars = android.CreateTestConfiguredJarList([]string{"myapex:libfoo"})
}
- checkBootDexJarPath := func(ctx *android.TestContext, bootDexJarPath string) {
+ checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, bootDexJarPath string) {
s := ctx.SingletonForTests("dex_bootjars")
foundLibfooJar := false
for _, output := range s.AllOutputs() {
@@ -4518,7 +4518,7 @@
`
ctx := testDexpreoptWithApexes(t, bp, "", transform)
- checkBootDexJarPath(ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
+ checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
})
t.Run("prebuilt with source library preferred", func(t *testing.T) {
@@ -4587,7 +4587,7 @@
`
ctx := testDexpreoptWithApexes(t, bp, "", transform)
- checkBootDexJarPath(ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
+ checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
})
t.Run("prebuilt with source apex preferred", func(t *testing.T) {
@@ -4631,7 +4631,7 @@
`
ctx := testDexpreoptWithApexes(t, bp, "", transform)
- checkBootDexJarPath(ctx, ".intermediates/libfoo/android_common_apex10000/aligned/libfoo.jar")
+ checkBootDexJarPath(t, ctx, ".intermediates/libfoo/android_common_apex10000/aligned/libfoo.jar")
})
t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) {
@@ -4677,7 +4677,7 @@
`
ctx := testDexpreoptWithApexes(t, bp, "", transform)
- checkBootDexJarPath(ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
+ checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
})
}