Add test for main dex tracing after removed annotation

Bug: 190623364
Change-Id: I0292eb89173da577fdefc89d457af3e6cc82fdc7
diff --git a/src/test/java/com/android/tools/r8/maindexlist/MainDexRemovedAnnotationIfTest.java b/src/test/java/com/android/tools/r8/maindexlist/MainDexRemovedAnnotationIfTest.java
new file mode 100644
index 0000000..5e0fa6b
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/maindexlist/MainDexRemovedAnnotationIfTest.java
@@ -0,0 +1,86 @@
+// 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.maindexlist;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+// This is a reproduction of b/190623364.
+@RunWith(Parameterized.class)
+public class MainDexRemovedAnnotationIfTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters()
+        .withDexRuntimes()
+        .withApiLevelsEndingAtExcluding(apiLevelWithNativeMultiDexSupport())
+        .build();
+  }
+
+  public MainDexRemovedAnnotationIfTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testMainDexTracing() throws Exception {
+    testForR8(parameters.getBackend())
+        .addProgramClasses(MainDex.class, Inside.class, Main.class)
+        .addKeepClassAndMembersRules(Main.class)
+        .setMinApi(parameters.getApiLevel())
+        .enableInliningAnnotations()
+        .addMainDexRules(
+            "-if @" + MainDex.class.getTypeName() + " class *", "-keep class <1> { *; }")
+        .collectMainDexClasses()
+        .compile()
+        .inspectMainDexClasses(
+            mainDexClasses -> {
+              // TODO(b/190623364): Should not be empty.
+              assertTrue(mainDexClasses.isEmpty());
+            })
+        .inspect(
+            codeInspector -> {
+              assertThat(codeInspector.clazz(MainDex.class), not(isPresent()));
+            })
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("Hello World!");
+  }
+
+  @Retention(RetentionPolicy.RUNTIME)
+  @Target({ElementType.TYPE})
+  public @interface MainDex {}
+
+  @MainDex
+  public static class Inside {
+
+    @NeverInline
+    public static void foo() {
+      System.out.println("Hello World!");
+    }
+  }
+
+  public static class Main {
+
+    public static void main(String[] args) {
+      Inside.foo();
+    }
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/maindexlist/MainDexRemovedAnnotationTest.java b/src/test/java/com/android/tools/r8/maindexlist/MainDexRemovedAnnotationTest.java
new file mode 100644
index 0000000..67b113c
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/maindexlist/MainDexRemovedAnnotationTest.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.maindexlist;
+
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+// This is a reproduction of b/190623364.
+@RunWith(Parameterized.class)
+public class MainDexRemovedAnnotationTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters()
+        .withDexRuntimes()
+        .withApiLevelsEndingAtExcluding(apiLevelWithNativeMultiDexSupport())
+        .build();
+  }
+
+  public MainDexRemovedAnnotationTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testMainDexTracing() throws Exception {
+    testForR8(parameters.getBackend())
+        .addProgramClasses(MainDex.class, Inside.class, Main.class)
+        .addKeepClassAndMembersRules(Main.class)
+        .setMinApi(parameters.getApiLevel())
+        .enableInliningAnnotations()
+        .addMainDexRules("-keep @" + MainDex.class.getTypeName() + " class * { *; }")
+        .collectMainDexClasses()
+        .compile()
+        .inspectMainDexClasses(
+            mainDexClasses -> {
+              // TODO(b/190623364): Should not be empty.
+              assertTrue(mainDexClasses.isEmpty());
+            })
+        .inspect(
+            codeInspector -> {
+              assertThat(codeInspector.clazz(MainDex.class), not(isPresent()));
+            })
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("Hello World!");
+  }
+
+  @Retention(RetentionPolicy.RUNTIME)
+  @Target({ElementType.TYPE})
+  public @interface MainDex {}
+
+  @MainDex
+  public static class Inside {
+
+    @NeverInline
+    public static void foo() {
+      System.out.println("Hello World!");
+    }
+  }
+
+  public static class Main {
+
+    public static void main(String[] args) {
+      Inside.foo();
+    }
+  }
+}