Add test showing info message for invalid signature for non-kept method
Bug: 189815242
Change-Id: Ic0d0302a29926992efa5a97f9b27416e0078afcf
diff --git a/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignatureInvalidInfoKeepTest.java b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignatureInvalidInfoKeepTest.java
new file mode 100644
index 0000000..70a2bfd
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/graph/genericsignature/GenericSignatureInvalidInfoKeepTest.java
@@ -0,0 +1,82 @@
+// 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.graph.genericsignature;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.transformers.ClassFileTransformer.MethodPredicate;
+import com.android.tools.r8.utils.codeinspector.ClassSubject;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class GenericSignatureInvalidInfoKeepTest extends TestBase {
+
+ private final TestParameters parameters;
+
+ @Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public GenericSignatureInvalidInfoKeepTest(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addProgramClasses(Base.class, Main.class)
+ .addInnerClasses(A.class)
+ .addProgramClassFileData(
+ transformer(A.class)
+ .setGenericSignature(MethodPredicate.onName("foo"), (String) null)
+ .transform())
+ .setMinApi(parameters.getApiLevel())
+ .addKeepMainRule(Main.class)
+ .allowDiagnosticInfoMessages()
+ .compile()
+ .apply(TestBase::verifyAllInfoFromGenericSignatureTypeParameterValidation)
+ .run(parameters.getRuntime(), Main.class)
+ .assertSuccessWithOutputLines("A$1::bar")
+ .inspect(
+ inspector -> {
+ ClassSubject baseClass = inspector.clazz(Base.class);
+ assertThat(baseClass, not(isPresent()));
+ });
+ }
+
+ public abstract static class Base<K, V> {
+ public abstract K bar(V v);
+ }
+
+ public static class A {
+
+ public static <K, V> Base<K, V> foo() {
+ return new Base<K, V>() {
+ @Override
+ public K bar(V f) {
+ System.out.println("A$1::bar");
+ return null;
+ }
+ };
+ }
+ ;
+ }
+
+ public static class Main {
+
+ public static void main(String[] args) {
+ A.foo().bar(null);
+ }
+ }
+}