[KeepAnno] Update test with unexpected keepclasseswithmembers behavior

Bug: b/322104143
Change-Id: Ibeffd5e0fb27a194a247cff532979e4edae283a6
diff --git a/src/test/java/com/android/tools/r8/keepanno/KeepFieldValueApiTest.java b/src/test/java/com/android/tools/r8/keepanno/KeepFieldValueApiTest.java
index 61c4e54..dfca281 100644
--- a/src/test/java/com/android/tools/r8/keepanno/KeepFieldValueApiTest.java
+++ b/src/test/java/com/android/tools/r8/keepanno/KeepFieldValueApiTest.java
@@ -3,16 +3,18 @@
 // BSD-style license that can be found in the LICENSE file.
 package com.android.tools.r8.keepanno;
 
+import static com.android.tools.r8.utils.codeinspector.Matchers.isAbsent;
 import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeTrue;
 
-import com.android.tools.r8.TestBase;
-import com.android.tools.r8.TestParameters;
-import com.android.tools.r8.TestParametersCollection;
 import com.android.tools.r8.keepanno.annotations.KeepForApi;
 import com.android.tools.r8.keepanno.annotations.KeepItemKind;
 import com.android.tools.r8.keepanno.annotations.KeepTarget;
 import com.android.tools.r8.utils.AndroidApiLevel;
+import com.android.tools.r8.utils.Box;
 import com.android.tools.r8.utils.StringUtils;
 import com.android.tools.r8.utils.codeinspector.ClassSubject;
 import com.android.tools.r8.utils.codeinspector.CodeInspector;
@@ -22,53 +24,55 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
 
 @RunWith(Parameterized.class)
-public class KeepFieldValueApiTest extends TestBase {
+public class KeepFieldValueApiTest extends KeepAnnoTestBase {
 
   static final String EXPECTED = StringUtils.lines("B::foo");
 
-  private final TestParameters parameters;
+  @Parameter public KeepAnnoParameters parameters;
 
   @Parameterized.Parameters(name = "{0}")
-  public static TestParametersCollection data() {
-    return getTestParameters()
-        .withDefaultRuntimes()
-        .withApiLevel(AndroidApiLevel.B)
-        .enableApiLevelsForCf()
-        .build();
-  }
-
-  public KeepFieldValueApiTest(TestParameters parameters) {
-    this.parameters = parameters;
+  public static List<KeepAnnoParameters> data() {
+    return createParameters(
+        getTestParameters()
+            .withDefaultRuntimes()
+            .withApiLevel(AndroidApiLevel.B)
+            .enableApiLevelsForCf()
+            .build());
   }
 
   @Test
   public void testReference() throws Exception {
-    testForRuntime(parameters)
+    assumeTrue(parameters.isReference());
+    testForKeepAnno(parameters)
         .addProgramClasses(getLibraryClasses())
         .addProgramClasses(getClientClasses())
-        .run(parameters.getRuntime(), TestClass.class)
+        .run(TestClass.class)
         .assertSuccessWithOutput(EXPECTED);
   }
 
   @Test
-  public void testWithRuleExtraction() throws Exception {
-    Path lib =
-        testForR8(parameters.getBackend())
-            .enableExperimentalKeepAnnotations()
-            .addProgramClasses(getLibraryClasses())
-            .setMinApi(parameters)
-            .compile()
-            .inspect(this::checkLibraryOutput)
-            .writeToZip();
+  public void testShrinker() throws Exception {
+    assumeFalse(parameters.isReference());
+    assertTrue(parameters.isShrinker());
+    Box<Path> lib = new Box<>();
+    testForKeepAnno(parameters)
+        .addProgramClasses(getLibraryClasses())
+        .setExcludedOuterClass(getClass())
+        .applyIfShrinker(b -> lib.set(b.compile().inspect(this::checkLibraryOutput).writeToZip()));
 
     testForD8(parameters.getBackend())
         .addProgramClasses(getClientClasses())
-        .addProgramFiles(lib)
-        .setMinApi(parameters)
+        .addProgramFiles(lib.get())
+        .setMinApi(parameters.parameters())
         .run(parameters.getRuntime(), TestClass.class)
-        .assertSuccessWithOutput(EXPECTED);
+        // TODO(b/322104143): The -keepclasseswithmembers rule does not keep B and its members.
+        .applyIf(
+            parameters.isPG(),
+            r -> r.assertFailureWithErrorThatThrows(ClassNotFoundException.class),
+            r -> r.assertSuccessWithOutput(EXPECTED));
   }
 
   public List<Class<?>> getLibraryClasses() {
@@ -84,6 +88,11 @@
     assertThat(aClass, isPresent());
     assertThat(aClass.uniqueFieldWithFinalName("CLASS"), isPresent());
     ClassSubject bClass = inspector.clazz(B.class);
+    if (parameters.isPG()) {
+      // TODO(b/322104143): The -keepclasseswithmembers rule does not keep B and its members.
+      assertThat(bClass, isAbsent());
+      return;
+    }
     assertThat(bClass, isPresent());
     assertThat(bClass.uniqueMethodWithOriginalName("foo"), isPresent());
     assertThat(bClass.uniqueMethodWithOriginalName("bar"), isPresent());