From 69861aa57fe538f076be029d14df46733a0340b0 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Tue, 31 Jan 2023 15:49:07 -0800 Subject: Give lint the correct api levels database for the current module Before this change, lint was always working off of the public api database. Now, it will have the system, module-lib, or system-server databases if the current module is compiling against those SDKs. This means that a lot more methods are going to start being checked for NewApi issues. Bug: 193460475 Test: Errorprone presubmit Change-Id: I3eb2c617cd61554cd2a3f9d15fd40b3ec91f961d --- java/lint_test.go | 81 +++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 47 deletions(-) (limited to 'java/lint_test.go') diff --git a/java/lint_test.go b/java/lint_test.go index 1ab416c9e..ec901aa70 100644 --- a/java/lint_test.go +++ b/java/lint_test.go @@ -113,8 +113,9 @@ func TestJavaLintUsesCorrectBpConfig(t *testing.T) { t.Error("did not use the correct file for baseline") } - if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check NewApi") { - t.Error("should check NewApi errors") + if !strings.Contains(*sboxProto.Commands[0].Command, "--warning_check NewApi") { + // TODO(b/268261262): Change this to check for --error_check + t.Error("should check NewApi warnings") } if !strings.Contains(*sboxProto.Commands[0].Command, "--error_check SomeCheck") { @@ -222,8 +223,35 @@ func TestJavaLintBypassUpdatableChecks(t *testing.T) { //} func TestJavaLintDatabaseSelectionFull(t *testing.T) { - testCases := []string{ - "current", "core_platform", "system_current", "S", "30", "10000", + testCases := []struct { + sdk_version string + expected_file string + }{ + { + "current", + "api_versions_public.xml", + }, { + "core_platform", + "api_versions_public.xml", + }, { + "system_current", + "api_versions_system.xml", + }, { + "module_current", + "api_versions_module_lib.xml", + }, { + "system_server_current", + "api_versions_system_server.xml", + }, { + "S", + "api_versions_public.xml", + }, { + "30", + "api_versions_public.xml", + }, { + "10000", + "api_versions_public.xml", + }, } bp := ` java_library { @@ -239,7 +267,7 @@ func TestJavaLintDatabaseSelectionFull(t *testing.T) { } ` for _, testCase := range testCases { - thisBp := strings.Replace(bp, "XXX", testCase, 1) + thisBp := strings.Replace(bp, "XXX", testCase.sdk_version, 1) result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules, FixtureWithPrebuiltApis(map[string][]string{ "30": {"foo"}, @@ -249,49 +277,8 @@ func TestJavaLintDatabaseSelectionFull(t *testing.T) { foo := result.ModuleForTests("foo", "android_common") sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto")) - if strings.Contains(*sboxProto.Commands[0].Command, - "/api_versions_public_filtered.xml") { - t.Error("used public-filtered lint api database for case", testCase) - } - if !strings.Contains(*sboxProto.Commands[0].Command, - "/api_versions.xml") { + if !strings.Contains(*sboxProto.Commands[0].Command, "/"+testCase.expected_file) { t.Error("did not use full api database for case", testCase) } } - -} - -func TestJavaLintDatabaseSelectionPublicFiltered(t *testing.T) { - testCases := []string{ - "module_current", "system_server_current", - } - bp := ` - java_library { - name: "foo", - srcs: [ - "a.java", - ], - min_sdk_version: "29", - sdk_version: "XXX", - lint: { - strict_updatability_linting: true, - }, - } -` - for _, testCase := range testCases { - thisBp := strings.Replace(bp, "XXX", testCase, 1) - result := android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules). - RunTestWithBp(t, thisBp) - - foo := result.ModuleForTests("foo", "android_common") - sboxProto := android.RuleBuilderSboxProtoForTests(t, foo.Output("lint.sbox.textproto")) - if !strings.Contains(*sboxProto.Commands[0].Command, - "/api_versions_public_filtered.xml") { - t.Error("did not use public-filtered lint api database for case", testCase) - } - if strings.Contains(*sboxProto.Commands[0].Command, - "/api_versions.xml") { - t.Error("used full api database for case", testCase) - } - } } -- cgit v1.2.3-59-g8ed1b