diff options
author | 2021-06-18 12:25:54 -0700 | |
---|---|---|
committer | 2021-06-18 12:34:51 -0700 | |
commit | 2b1536e4dbc9e9178a8f6cf3fa049170811a75a1 (patch) | |
tree | a27ec25c406281a92d05882aabe6e1101b181020 /java/java_test.go | |
parent | e6aefedeba5daaac4dd5b27b783e16df98055e18 (diff) |
Allow disabling errorprone even when RUN_ERROR_PRONE is true
Some modules use -XepDisableAllChecks to disable errorprone.
However, this still causes them to be compiled twice when
RUN_ERROR_PRONE is true. Allow the new enabled property to
be set to false to disable errorprone entirely, so that those
modules are only compiled once.
Bug: 190944875
Test: New unit tests
Change-Id: Ie68695db762fffcaf11bbbcb0509c4fcab73f5c5
Diffstat (limited to 'java/java_test.go')
-rw-r--r-- | java/java_test.go | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/java/java_test.go b/java/java_test.go index 78d9ab4c7..0f9965d03 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1409,7 +1409,7 @@ func TestErrorproneEnabled(t *testing.T) { // Test that the errorprone plugins are passed to javac expectedSubstring := "-Xplugin:ErrorProne" if !strings.Contains(javac.Args["javacFlags"], expectedSubstring) { - t.Errorf("expected javacFlags to conain %q, got %q", expectedSubstring, javac.Args["javacFlags"]) + t.Errorf("expected javacFlags to contain %q, got %q", expectedSubstring, javac.Args["javacFlags"]) } // Modules with errorprone { enabled: true } will include errorprone checks @@ -1420,3 +1420,67 @@ func TestErrorproneEnabled(t *testing.T) { t.Errorf("expected errorprone build rule to not exist, but it did") } } + +func TestErrorproneDisabled(t *testing.T) { + bp := ` + java_library { + name: "foo", + srcs: ["a.java"], + errorprone: { + enabled: false, + }, + } + ` + ctx := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.FixtureMergeEnv(map[string]string{ + "RUN_ERROR_PRONE": "true", + }), + ).RunTestWithBp(t, bp) + + javac := ctx.ModuleForTests("foo", "android_common").Description("javac") + + // Test that the errorprone plugins are not passed to javac, like they would + // be if enabled was true. + expectedSubstring := "-Xplugin:ErrorProne" + if strings.Contains(javac.Args["javacFlags"], expectedSubstring) { + t.Errorf("expected javacFlags to not contain %q, got %q", expectedSubstring, javac.Args["javacFlags"]) + } + + // Check that no errorprone build rule is created, like there would be + // if enabled was unset and RUN_ERROR_PRONE was true. + errorprone := ctx.ModuleForTests("foo", "android_common").MaybeDescription("errorprone") + if errorprone.RuleParams.Description != "" { + t.Errorf("expected errorprone build rule to not exist, but it did") + } +} + +func TestErrorproneEnabledOnlyByEnvironmentVariable(t *testing.T) { + bp := ` + java_library { + name: "foo", + srcs: ["a.java"], + } + ` + ctx := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.FixtureMergeEnv(map[string]string{ + "RUN_ERROR_PRONE": "true", + }), + ).RunTestWithBp(t, bp) + + javac := ctx.ModuleForTests("foo", "android_common").Description("javac") + errorprone := ctx.ModuleForTests("foo", "android_common").Description("errorprone") + + // Check that the errorprone plugins are not passed to javac, because they + // will instead be passed to the separate errorprone compilation + expectedSubstring := "-Xplugin:ErrorProne" + if strings.Contains(javac.Args["javacFlags"], expectedSubstring) { + t.Errorf("expected javacFlags to not contain %q, got %q", expectedSubstring, javac.Args["javacFlags"]) + } + + // Check that the errorprone plugin is enabled + if !strings.Contains(errorprone.Args["javacFlags"], expectedSubstring) { + t.Errorf("expected errorprone to contain %q, got %q", expectedSubstring, javac.Args["javacFlags"]) + } +} |