Add test of parsing -keepXnames
Using keepXnames should be equivalnet of -keepX,allowshrinking.
Bug: 171289133
Change-Id: Ia641686033ef4a0eb50072d1123692333c5b4182
diff --git a/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java b/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
index 222c6a8..c15fb48 100644
--- a/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
@@ -3175,4 +3175,33 @@
}
});
}
+
+ @Test
+ public void parseKeepXNamesIsAllowShrinking() {
+ for (String rule : ImmutableList.of("-keep", "-keepclassmembers", "-keepclasseswithmembers")) {
+ for (String modifier :
+ ImmutableList.of("", "names", ",allowshrinking", "names,allowshrinking")) {
+ DexItemFactory dexItemFactory = new DexItemFactory();
+ ProguardConfigurationParser parser =
+ new ProguardConfigurationParser(dexItemFactory, reporter);
+ String ruleWithModifier =
+ (rule.endsWith("s") && (!modifier.startsWith(",") && !modifier.isEmpty())
+ ? rule.substring(0, rule.length() - 1)
+ : rule)
+ + modifier;
+ parser.parse(
+ createConfigurationForTesting(ImmutableList.of(ruleWithModifier + " class A")));
+ verifyParserEndsCleanly();
+
+ ProguardConfiguration configuration = parser.getConfig();
+ assertEquals(1, configuration.getRules().size());
+ assertEquals(
+ !modifier.isEmpty(),
+ ListUtils.first(configuration.getRules())
+ .asProguardKeepRule()
+ .getModifiers()
+ .allowsShrinking);
+ }
+ }
+ }
}
\ No newline at end of file