From 90607e9056f6ff4cec2447fdd7a8b252d67ffde7 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 11 Feb 2025 14:58:07 -0800 Subject: Don't panic in ModuleForTests and friends Panicking in ModuleForTests and similar test helper functions was a mistake. Go's test runner stops running tests as soon as any test panics, which means debugging multiple tests panicking requires rerunning all the tests after fixing each panic to find the next one. Pass the *testing.T into ModuleForTests and friends so that it can call t.Fatalf instead. Test: all soong tests pass Change-Id: I5d0f2424eaf04fb795079e6d1e4b9469d8c7033c --- java/kotlin_test.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'java/kotlin_test.go') diff --git a/java/kotlin_test.go b/java/kotlin_test.go index 3a203358a..c7b1ece98 100644 --- a/java/kotlin_test.go +++ b/java/kotlin_test.go @@ -240,7 +240,7 @@ func TestKotlin(t *testing.T) { PrepareForTestWithJavaDefaultModules, tt.preparer, ).RunTestWithBp(t, bp) - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") fooKotlinc := foo.Rule("kotlinc") android.AssertPathsRelativeToTopEquals(t, "foo kotlinc inputs", tt.fooKotlincInputs, fooKotlinc.Inputs) @@ -260,7 +260,7 @@ func TestKotlin(t *testing.T) { fooCombinedHeaderJar := foo.Output("turbine-combined/foo.jar") android.AssertPathsRelativeToTopEquals(t, "foo header combined inputs", tt.fooHeaderCombinedInputs, fooCombinedHeaderJar.Inputs) - bar := result.ModuleForTests("bar", "android_common") + bar := result.ModuleForTests(t, "bar", "android_common") barKotlinc := bar.Rule("kotlinc") android.AssertPathsRelativeToTopEquals(t, "bar kotlinc inputs", tt.barKotlincInputs, barKotlinc.Inputs) @@ -311,14 +311,14 @@ func TestKapt(t *testing.T) { buildOS := ctx.Config().BuildOS.String() - foo := ctx.ModuleForTests("foo", "android_common") + foo := ctx.ModuleForTests(t, "foo", "android_common") kaptStubs := foo.Rule("kapt") turbineApt := foo.Description("turbine apt") kotlinc := foo.Rule("kotlinc") javac := foo.Rule("javac") - bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String() - baz := ctx.ModuleForTests("baz", buildOS+"_common").Rule("javac").Output.String() + bar := ctx.ModuleForTests(t, "bar", buildOS+"_common").Rule("javac").Output.String() + baz := ctx.ModuleForTests(t, "baz", buildOS+"_common").Rule("javac").Output.String() // Test that the kotlin and java sources are passed to kapt and kotlinc if len(kaptStubs.Inputs) != 2 || kaptStubs.Inputs[0].String() != "a.java" || kaptStubs.Inputs[1].String() != "b.kt" { @@ -400,13 +400,13 @@ func TestKapt(t *testing.T) { buildOS := result.Config.BuildOS.String() - kapt := result.ModuleForTests("foo", "android_common").Rule("kapt") - javac := result.ModuleForTests("foo", "android_common").Description("javac") - errorprone := result.ModuleForTests("foo", "android_common").Description("errorprone") + kapt := result.ModuleForTests(t, "foo", "android_common").Rule("kapt") + javac := result.ModuleForTests(t, "foo", "android_common").Description("javac") + errorprone := result.ModuleForTests(t, "foo", "android_common").Description("errorprone") - bar := result.ModuleForTests("bar", buildOS+"_common").Description("javac").Output.String() - baz := result.ModuleForTests("baz", buildOS+"_common").Description("javac").Output.String() - myCheck := result.ModuleForTests("my_check", buildOS+"_common").Description("javac").Output.String() + bar := result.ModuleForTests(t, "bar", buildOS+"_common").Description("javac").Output.String() + baz := result.ModuleForTests(t, "baz", buildOS+"_common").Description("javac").Output.String() + myCheck := result.ModuleForTests(t, "my_check", buildOS+"_common").Description("javac").Output.String() // Test that the errorprone plugins are not passed to kapt expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar + @@ -531,9 +531,9 @@ func TestKotlinCompose(t *testing.T) { buildOS := result.Config.BuildOS.String() - composeCompiler := result.ModuleForTests("kotlin-compose-compiler-plugin", buildOS+"_common").Rule("combineJar").Output - withCompose := result.ModuleForTests("withcompose", "android_common") - noCompose := result.ModuleForTests("nocompose", "android_common") + composeCompiler := result.ModuleForTests(t, "kotlin-compose-compiler-plugin", buildOS+"_common").Rule("combineJar").Output + withCompose := result.ModuleForTests(t, "withcompose", "android_common") + noCompose := result.ModuleForTests(t, "nocompose", "android_common") android.AssertStringListContains(t, "missing compose compiler dependency", withCompose.Rule("kotlinc").Implicits.Strings(), composeCompiler.String()) @@ -579,9 +579,9 @@ func TestKotlinPlugin(t *testing.T) { buildOS := result.Config.BuildOS.String() - kotlinPlugin := result.ModuleForTests("kotlin_plugin", buildOS+"_common").Rule("combineJar").Output - withKotlinPlugin := result.ModuleForTests("with_kotlin_plugin", "android_common") - noKotlinPlugin := result.ModuleForTests("no_kotlin_plugin", "android_common") + kotlinPlugin := result.ModuleForTests(t, "kotlin_plugin", buildOS+"_common").Rule("combineJar").Output + withKotlinPlugin := result.ModuleForTests(t, "with_kotlin_plugin", "android_common") + noKotlinPlugin := result.ModuleForTests(t, "no_kotlin_plugin", "android_common") android.AssertStringListContains(t, "missing plugin compiler dependency", withKotlinPlugin.Rule("kotlinc").Implicits.Strings(), kotlinPlugin.String()) -- cgit v1.2.3-59-g8ed1b