Add reproduction for not applying mapping to interface with parent
Bug: 181887416
Change-Id: I3cd63ccb3b885f450d9c37d4b1acd07abc85519e
diff --git a/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingClassPathInterfaceInheritTest.java b/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingClassPathInterfaceInheritTest.java
new file mode 100644
index 0000000..3ec9e8f
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingClassPathInterfaceInheritTest.java
@@ -0,0 +1,85 @@
+// Copyright (c) 2021, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.naming.applymapping;
+
+import com.android.tools.r8.R8TestCompileResult;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestShrinkerBuilder;
+import com.android.tools.r8.utils.BooleanUtils;
+import java.nio.file.Path;
+import java.util.List;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+// This is a reproduction of b/181887416.
+public class ApplyMappingClassPathInterfaceInheritTest extends TestBase {
+
+ private final TestParameters parameters;
+ private final boolean minifyLibrary;
+
+ @Parameters(name = "{0}, minifyLibrary: {1}")
+ public static List<Object[]> data() {
+ return buildParameters(
+ getTestParameters().withAllRuntimesAndApiLevels().build(), BooleanUtils.values());
+ }
+
+ public ApplyMappingClassPathInterfaceInheritTest(
+ TestParameters parameters, boolean minifyLibrary) {
+ this.parameters = parameters;
+ this.minifyLibrary = minifyLibrary;
+ }
+
+ @Test
+ public void testApplyMapping() throws Exception {
+ R8TestCompileResult libraryResult =
+ testForR8(parameters.getBackend())
+ .addLibraryClasses(LibI.class)
+ .addDefaultRuntimeLibrary(parameters)
+ .addProgramClasses(ClassPathI.class)
+ .applyIf(
+ minifyLibrary,
+ TestShrinkerBuilder::addKeepAllClassesRuleWithAllowObfuscation,
+ TestShrinkerBuilder::addKeepAllClassesRule)
+ .setMinApi(parameters.getApiLevel())
+ .compile();
+ Path libraryJar = libraryResult.writeToZip();
+ testForR8(parameters.getBackend())
+ .addLibraryClasses(LibI.class)
+ .addDefaultRuntimeLibrary(parameters)
+ .addClasspathClasses(ClassPathI.class)
+ .addProgramClasses(Main.class)
+ .addKeepAllClassesRule()
+ .addApplyMapping(libraryResult.getProguardMap())
+ .setMinApi(parameters.getApiLevel())
+ .compile()
+ .addRunClasspathClasses(LibI.class)
+ .addRunClasspathFiles(libraryJar)
+ .run(parameters.getRuntime(), Main.class)
+ // TODO(b/181887416): Should not throw an error when minifyLibrary == true.
+ .applyIf(
+ minifyLibrary,
+ r -> r.assertFailureWithErrorThatThrows(ClassNotFoundException.class),
+ r -> r.assertSuccessWithOutputLines(ClassPathI.class.getTypeName()));
+ }
+
+ public interface LibI {}
+
+ public interface ClassPathI extends LibI {}
+
+ public static class Main {
+
+ public static void main(String[] args) throws ClassNotFoundException {
+ System.out.println(
+ Class.forName(
+ "com.android.tools.r8.naming.applymapping"
+ + ".ApplyMappingClassPathInterfaceInheritTest$ClassPathI")
+ .getName());
+ }
+ }
+}