Jaewoong Jung | 79e6f6b | 2021-04-21 14:01:55 -0700 | [diff] [blame^] | 1 | // Copyright 2021 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | func TestJavaLintBypassUpdatableChecks(t *testing.T) { |
| 24 | testCases := []struct { |
| 25 | name string |
| 26 | bp string |
| 27 | error string |
| 28 | }{ |
| 29 | { |
| 30 | name: "warning_checks", |
| 31 | bp: ` |
| 32 | java_library { |
| 33 | name: "foo", |
| 34 | srcs: [ |
| 35 | "a.java", |
| 36 | ], |
| 37 | min_sdk_version: "29", |
| 38 | sdk_version: "current", |
| 39 | lint: { |
| 40 | warning_checks: ["NewApi"], |
| 41 | }, |
| 42 | } |
| 43 | `, |
| 44 | error: "lint.warning_checks: Can't treat \\[NewApi\\] checks as warnings if min_sdk_version is different from sdk_version.", |
| 45 | }, |
| 46 | { |
| 47 | name: "disable_checks", |
| 48 | bp: ` |
| 49 | java_library { |
| 50 | name: "foo", |
| 51 | srcs: [ |
| 52 | "a.java", |
| 53 | ], |
| 54 | min_sdk_version: "29", |
| 55 | sdk_version: "current", |
| 56 | lint: { |
| 57 | disabled_checks: ["NewApi"], |
| 58 | }, |
| 59 | } |
| 60 | `, |
| 61 | error: "lint.disabled_checks: Can't disable \\[NewApi\\] checks if min_sdk_version is different from sdk_version.", |
| 62 | }, |
| 63 | } |
| 64 | |
| 65 | for _, testCase := range testCases { |
| 66 | t.Run(testCase.name, func(t *testing.T) { |
| 67 | errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.error) |
| 68 | android.GroupFixturePreparers(PrepareForTestWithJavaDefaultModules). |
| 69 | ExtendWithErrorHandler(errorHandler). |
| 70 | RunTestWithBp(t, testCase.bp) |
| 71 | }) |
| 72 | } |
| 73 | } |