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/hiddenapi_singleton_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'java/hiddenapi_singleton_test.go') diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index c14fdb7bb..147f326c7 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -57,7 +57,7 @@ func TestHiddenAPISingleton(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") want := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, want) @@ -101,7 +101,7 @@ func TestHiddenAPISingletonWithPrebuilt(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") want := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, want) @@ -128,7 +128,7 @@ func TestHiddenAPISingletonWithPrebuiltUseSource(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") fromSourceJarArg := "--boot-dex=out/soong/.intermediates/foo/android_common/aligned/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, fromSourceJarArg) @@ -158,7 +158,7 @@ func TestHiddenAPISingletonWithPrebuiltOverrideSource(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") prebuiltJarArg := "--boot-dex=out/soong/.intermediates/prebuilt_foo/android_common/dex/foo.jar" android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, prebuiltJarArg) @@ -219,7 +219,7 @@ func TestHiddenAPISingletonSdks(t *testing.T) { } `) - hiddenAPI := result.ModuleForTests("platform-bootclasspath", "android_common") + hiddenAPI := result.ModuleForTests(t, "platform-bootclasspath", "android_common") hiddenapiRule := hiddenAPI.Rule("platform-bootclasspath-monolithic-hiddenapi-stub-flags") wantPublicStubs := "--public-stub-classpath=" + generateSdkDexPath(tc.publicStub, tc.unbundledBuild) android.AssertStringDoesContain(t, "hiddenapi command", hiddenapiRule.RuleParams.Command, wantPublicStubs) @@ -279,9 +279,9 @@ func TestHiddenAPISingletonWithPrebuiltCsvFile(t *testing.T) { expectedCpOutput := "out/soong/hiddenapi/hiddenapi-flags.csv" expectedFlagsCsv := "out/soong/hiddenapi/hiddenapi-flags.csv" - foo := result.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests(t, "foo", "android_common") - hiddenAPI := result.SingletonForTests("hiddenapi") + hiddenAPI := result.SingletonForTests(t, "hiddenapi") cpRule := hiddenAPI.Rule("Cp") actualCpInput := cpRule.BuildParams.Input actualCpOutput := cpRule.BuildParams.Output @@ -318,7 +318,7 @@ func TestHiddenAPIEncoding_JavaSdkLibrary(t *testing.T) { `) checkDexEncoded := func(t *testing.T, name, unencodedDexJar, encodedDexJar string) { - moduleForTests := result.ModuleForTests(name+".impl", "android_common") + moduleForTests := result.ModuleForTests(t, name+".impl", "android_common") encodeDexRule := moduleForTests.Rule("hiddenAPIEncodeDex") actualUnencodedDexJar := encodeDexRule.Input -- cgit v1.2.3-59-g8ed1b