Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package androidx.build.lint |
| 18 | |
| 19 | import org.junit.Test |
| 20 | import org.junit.runner.RunWith |
| 21 | import org.junit.runners.JUnit4 |
| 22 | |
| 23 | @RunWith(JUnit4::class) |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 24 | class IgnoreClassLevelDetectorTest : |
| 25 | AbstractLintDetectorTest( |
| 26 | useDetector = IgnoreClassLevelDetector(), |
| 27 | useIssues = listOf(IgnoreClassLevelDetector.ISSUE), |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 28 | ) { |
| 29 | @Test |
| 30 | fun `Detection of class level ignore in Kotlin sources`() { |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 31 | val input = |
| 32 | arrayOf( |
| 33 | kotlin( |
| 34 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 35 | package java.androidx |
| 36 | |
| 37 | import org.junit.Ignore |
| 38 | import org.junit.Test |
| 39 | |
| 40 | @Ignore("Class") |
| 41 | class TestClass { |
| 42 | @Test |
| 43 | fun oneTest() {} |
| 44 | |
| 45 | @Test |
| 46 | @Ignore |
| 47 | fun twoTest() {} |
| 48 | } |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 49 | """ |
| 50 | ), |
| 51 | Stubs.IgnoreAnnotation, |
| 52 | Stubs.TestAnnotation |
| 53 | ) |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 54 | |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 55 | val expected = |
| 56 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 57 | src/java/androidx/TestClass.kt:7: Error: @Ignore should not be used at the class level. Move the annotation to each test individually. [IgnoreClassLevelDetector] |
| 58 | @Ignore("Class") |
| 59 | ~~~~~~~~~~~~~~~~ |
| 60 | 1 errors, 0 warnings |
| 61 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 62 | |
| 63 | check(*input).expect(expected) |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | fun `Detection of class level ignore in Java sources`() { |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 68 | val input = |
| 69 | arrayOf( |
| 70 | java( |
| 71 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 72 | package java.androidx; |
| 73 | |
| 74 | import org.junit.Ignore; |
| 75 | import org.junit.Test; |
| 76 | |
| 77 | @Ignore |
| 78 | public class TestClass { |
| 79 | @Test |
| 80 | public void oneTest() {} |
| 81 | |
| 82 | @Ignore |
| 83 | @Test |
| 84 | public void twoTest() {} |
| 85 | } |
| 86 | """ |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 87 | ), |
| 88 | Stubs.IgnoreAnnotation, |
| 89 | Stubs.TestAnnotation |
| 90 | ) |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 91 | |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 92 | val expected = |
| 93 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 94 | src/java/androidx/TestClass.java:7: Error: @Ignore should not be used at the class level. Move the annotation to each test individually. [IgnoreClassLevelDetector] |
| 95 | @Ignore |
| 96 | ~~~~~~~ |
| 97 | 1 errors, 0 warnings |
| 98 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 99 | |
| 100 | check(*input).expect(expected) |
| 101 | } |
| 102 | |
| 103 | @Test |
| 104 | fun `Test level ignore allowed in Kotlin sources`() { |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 105 | val input = |
| 106 | arrayOf( |
| 107 | kotlin( |
| 108 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 109 | package java.androidx |
| 110 | |
| 111 | import org.junit.Ignore |
| 112 | import org.junit.Test |
| 113 | |
| 114 | class IgnoreTestLevelKotlin { |
| 115 | @Test |
| 116 | @Ignore("Test") |
| 117 | fun oneTest() {} |
| 118 | |
| 119 | @Test |
| 120 | fun twoTest() {} |
| 121 | } |
| 122 | """ |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 123 | ), |
| 124 | Stubs.IgnoreAnnotation, |
| 125 | Stubs.TestAnnotation |
| 126 | ) |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 127 | |
| 128 | check(*input).expectClean() |
| 129 | } |
| 130 | |
| 131 | @Test |
| 132 | fun `Test level ignore allowed in Java sources`() { |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 133 | val input = |
| 134 | arrayOf( |
| 135 | java( |
| 136 | """ |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 137 | package java.androidx; |
| 138 | |
| 139 | import org.junit.Ignore; |
| 140 | import org.junit.Test; |
| 141 | |
| 142 | public class Test { |
| 143 | @Test |
| 144 | @Ignore |
| 145 | public void oneTest() {} |
| 146 | |
| 147 | @Test |
| 148 | public void twoTest() {} |
| 149 | } |
Omar Ismail | edf734f | 2024-05-28 12:34:57 +0100 | [diff] [blame] | 150 | """ |
| 151 | ), |
| 152 | Stubs.IgnoreAnnotation, |
| 153 | Stubs.TestAnnotation |
| 154 | ) |
Julia McClellan | 16c82d6 | 2022-05-24 13:05:59 -0400 | [diff] [blame] | 155 | |
| 156 | check(*input).expectClean() |
| 157 | } |
| 158 | } |