@@ -31,6 +31,75 @@ class DeprecatedColorInXmlDetectorTest : LintDetectorTest() {
3131 .expectClean()
3232 }
3333
34+ @Test
35+ fun testSuppressedDeprecatedColorInWidget () {
36+ lint().files(
37+ DEPRECATED_COLOUR_FILE ,
38+ xml(
39+ " res/layout/layout.xml" ,
40+ """
41+ <View xmlns:android="http://schemas.android.com/apk/res/android"
42+ xmlns:tools="http://schemas.android.com/tools"
43+ android:layout_width="wrap_content"
44+ android:layout_height="wrap_content">
45+ <TextView android:layout_width="wrap_content"
46+ android:layout_height="wrap_content"
47+ android:textColor="@color/red_error"
48+ tools:ignore="DeprecatedColorInXml"/>
49+ </View>
50+ """
51+ ).indented()
52+ )
53+ .testModes(TestMode .PARTIAL )
54+ .run ()
55+ .expectClean()
56+ }
57+
58+ @Test
59+ fun testSuppressedDeprecatedColorInLayoutFile () {
60+ lint().files(
61+ DEPRECATED_COLOUR_FILE ,
62+ xml(
63+ " res/layout/layout.xml" ,
64+ """
65+ <View xmlns:android="http://schemas.android.com/apk/res/android"
66+ xmlns:tools="http://schemas.android.com/tools"
67+ android:layout_width="wrap_content"
68+ android:layout_height="wrap_content"
69+ tools:ignore="DeprecatedColorInXml">
70+ <TextView android:layout_width="wrap_content"
71+ android:layout_height="wrap_content"
72+ android:textColor="@color/red_error" />
73+ </View>
74+ """
75+ ).indented()
76+ )
77+ .testModes(TestMode .PARTIAL )
78+ .run ()
79+ .expectClean()
80+ }
81+
82+ @Test
83+ fun testMultipleSuppressedDeprecatedColorInLayoutFile () {
84+ lint().files(
85+ DEPRECATED_COLOUR_FILE ,
86+ xml(
87+ " res/layout/layout.xml" ,
88+ """
89+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
90+ xmlns:tools="http://schemas.android.com/tools"
91+ android:layout_width="wrap_content"
92+ android:layout_height="wrap_content"
93+ android:background="@color/red_error"
94+ tools:ignore="Orientation,DeprecatedColorInXml" />
95+ """
96+ ).indented()
97+ )
98+ .testModes(TestMode .PARTIAL )
99+ .run ()
100+ .expectClean()
101+ }
102+
34103 @Test
35104 fun testDeprecatedColorInLayoutFile () {
36105 lint().files(
@@ -112,6 +181,31 @@ class DeprecatedColorInXmlDetectorTest : LintDetectorTest() {
112181 )
113182 }
114183
184+ @Test
185+ fun testDeprecatedColorInAlias () {
186+ lint().files(
187+ DEPRECATED_COLOUR_FILE ,
188+ xml(
189+ " res/values/colors.xml" ,
190+ """
191+ <resources>
192+ <color name="red_alias">@color/red_error</color>
193+ </resources>
194+ """
195+ ).indented()
196+ )
197+ .testModes(TestMode .PARTIAL )
198+ .run ()
199+ .expect(
200+ """
201+ res/values/colors.xml:2: Error: Deprecated colours should not be used [DeprecatedColorInXml]
202+ <color name="red_alias">@color/red_error</color>
203+ ~~~~~~~~~~~~~~~~
204+ 1 errors, 0 warnings
205+ """
206+ )
207+ }
208+
115209 @Test
116210 fun testDeprecatedSelectorInLayoutFile () {
117211 lint().files(
@@ -284,9 +378,9 @@ class DeprecatedColorInXmlDetectorTest : LintDetectorTest() {
284378 " res/layout/layout.xml" ,
285379 """
286380 <View xmlns:android="http://schemas.android.com/apk/res/android"
287- android:layout_width="wrap_content"
288- android:layout_height="wrap_content"
289- android:background="@color/rewards_color_primary" />
381+ android:layout_width="wrap_content"
382+ android:layout_height="wrap_content"
383+ android:background="@color/rewards_color_primary" />
290384 """
291385 ).indented()
292386
0 commit comments