From 89886cbdb05cf4a4445a4fc7706ccff91fb310fd Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 5 Feb 2021 16:44:03 +0000 Subject: [PATCH] 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 --- apex/apex_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apex/apex_test.go b/apex/apex_test.go index 85d62590e..9f8cd0654 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -4362,7 +4362,7 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) { // 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 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) { } } - 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 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) { // 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 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) { // 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 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) { // 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 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { 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 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { ` 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 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { ` 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 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { ` 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 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) { ` 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") }) }