Migrate enclosingmethod legacy test.

This removes the last example test compiled with pg 5.2

Bug: b/167145686
Bug: b/281805219
Change-Id: If8c7111e46d1214a42256267038dd9ca9b3d59a1
diff --git a/build.gradle b/build.gradle
index 6ce6aa4..6a788a9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -484,16 +484,6 @@
     }
 }
 
-task downloadProguard {
-    cloudDependencies.each { entry ->
-        entry.value.each { entryFile ->
-            if (entryFile.contains("proguard")) {
-                dependsOn "${getDownloadDepsTaskName(entry.key, entryFile)}"
-            }
-        }
-    }
-}
-
 task downloadOpenJDKrt {
    cloudDependencies.each { entry ->
         entry.value.each { entryFile ->
@@ -1337,14 +1327,7 @@
 
 
 task buildExampleJars {
-    dependsOn downloadProguard
     def examplesDir = file("src/test/examples")
-    def proguardScript
-    if (OperatingSystem.current().isWindows()) {
-        proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.bat"
-    } else {
-        proguardScript = "third_party/proguard/proguard5.2.1/bin/proguard.sh"
-    }
     task extractExamplesRuntime(type: Sync) {
         dependsOn configurations.examplesRuntime
         from { configurations.examplesRuntime.collect { zipTree(it) } }
@@ -1397,76 +1380,29 @@
         dependsOn "jar_example_${name}_debuginfo_none"
         dependsOn "extractExamplesRuntime"
         def runtimeDependencies = copySpec { }
-        // The "throwing" test verifies debugging/stack info on the post-proguarded output.
-        def proguardConfigPath = "${dir}/proguard.cfg"
-        if (new File(proguardConfigPath).exists()) {
-            task "pre_proguard_example_${name}"(type: Jar, dependsOn: "compile_examples") {
-                archiveName = "${name}_pre_proguard.jar"
-                destinationDir = exampleOutputDir
-                from "build/test/examples/classes"
-                include name + "/**/*.class"
-                with runtimeDependencies
-                includeEmptyDirs false
-            }
-            def jarPath = files(tasks.getByPath("pre_proguard_example_${name}")).files.first();
-            def proguardJarPath = "${exampleOutputDir}/${jarName}"
-            def proguardMapPath = "${exampleOutputDir}/${name}/${name}.map"
-            task "jar_example_${name}"(type: Exec, dependsOn: "pre_proguard_example_${name}") {
-                inputs.files files(
-                        tasks.getByPath("pre_proguard_example_${name}"),
-                        proguardConfigPath)
-                // Enable these to get stdout and stderr redirected to files...
-                // standardOutput = new FileOutputStream('proguard.stdout')
-                // errorOutput = new FileOutputStream('proguard.stderr')
-                def proguardArguments = "-verbose -dontwarn java.** -injars ${jarPath}" +
-                        " -outjars ${proguardJarPath}" +
-                        " -include ${proguardConfigPath}" +
-                        " -printmapping ${proguardMapPath}"
-                if (OperatingSystem.current().isWindows()) {
-                    executable "${proguardScript}"
-                    args "${proguardArguments}"
-                } else {
-                    executable "bash"
-                    args "-c", "${proguardScript} '${proguardArguments}'"
-                }
-                outputs.file proguardJarPath
-            }
-            // TODO: Consider performing distinct proguard compilations.
-            task "jar_example_${name}_debuginfo_all"(type: Copy, dependsOn: "jar_example_${name}") {
-                from "${exampleOutputDir}/${name}.jar"
-                into "${exampleOutputDir}"
-                rename(".*", "${name}_debuginfo_all.jar")
-            }
-            task "jar_example_${name}_debuginfo_none"(type: Copy, dependsOn: "jar_example_${name}") {
-                from "${exampleOutputDir}/${name}.jar"
-                into "${exampleOutputDir}"
-                rename(".*", "${name}_debuginfo_none.jar")
-            }
-        } else {
-            task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
-                archiveName = "${name}.jar"
-                destinationDir = exampleOutputDir
-                from "build/test/examples/classes"
-                include name + "/**/*"
-                with runtimeDependencies
-                includeEmptyDirs true
-            }
-            task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
-                archiveName = "${name}_debuginfo_all.jar"
-                destinationDir = exampleOutputDir
-                from "build/test/examples/classes_debuginfo_all"
-                include name + "/**/*.class"
-                with runtimeDependencies
-                includeEmptyDirs false
-            }
-            task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
-                archiveName = "${name}_debuginfo_none.jar"
-                destinationDir = exampleOutputDir
-                from "build/test/examples/classes_debuginfo_none"
-                include name + "/**/*.class"
-                with runtimeDependencies
-                includeEmptyDirs false
-            }
+        task "jar_example_${name}"(type: Jar, dependsOn: "compile_examples") {
+            archiveName = "${name}.jar"
+            destinationDir = exampleOutputDir
+            from "build/test/examples/classes"
+            include name + "/**/*"
+            with runtimeDependencies
+            includeEmptyDirs true
+        }
+        task "jar_example_${name}_debuginfo_all"(type: Jar, dependsOn: "compile_examples_debuginfo_all") {
+            archiveName = "${name}_debuginfo_all.jar"
+            destinationDir = exampleOutputDir
+            from "build/test/examples/classes_debuginfo_all"
+            include name + "/**/*.class"
+            with runtimeDependencies
+            includeEmptyDirs false
+        }
+        task "jar_example_${name}_debuginfo_none"(type: Jar, dependsOn: "compile_examples_debuginfo_none") {
+            archiveName = "${name}_debuginfo_none.jar"
+            destinationDir = exampleOutputDir
+            from "build/test/examples/classes_debuginfo_none"
+            include name + "/**/*.class"
+            with runtimeDependencies
+            includeEmptyDirs false
         }
     }
 }
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index 48e4bee..a61b882 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -44,8 +44,6 @@
       "memberrebinding2.Memberrebinding",
       "memberrebinding3.Memberrebinding",
       "minification.Minification",
-      "enclosingmethod.Main",
-      "enclosingmethod_proguarded.Main",
       "uninitializedfinal.UninitializedFinalFieldLeak",
     };
 
diff --git a/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java b/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
index 0d645ad..8274614 100644
--- a/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
+++ b/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
@@ -141,17 +141,6 @@
     testDebugging("minification", "Minification");
   }
 
-  @Test
-  public void testEnclosingmethod() throws Exception {
-    testDebugging("enclosingmethod", "Main");
-  }
-
-  @Test
-  public void testEnclosingmethod_proguarded() throws Exception {
-    // TODO(b/79671093): We don't match JVM's behavior on this example.
-    testDebuggingJvmOutputOnly("enclosingmethod_proguarded", "Main");
-  }
-
   private void testDebugging(String pkg, String clazz) throws Exception {
     init(pkg, clazz)
         .add("Input", input())
@@ -169,12 +158,6 @@
         .compare();
   }
 
-  private void testDebuggingJvmOutputOnly(String pkg, String clazz) throws Exception {
-    init(pkg, clazz)
-        .add("R8/CfSourceCode", r8cf())
-        .run();
-  }
-
   private DebugStreamComparator init(String pkg, String clazz) {
     // TODO(b/199700280): Reenable on 12.0.0 when we have the libjdwp.so file include and the flags
     // fixed.
diff --git a/src/test/examples/enclosingmethod/AbstractClass.java b/src/test/java/com/android/tools/r8/examples/enclosingmethod/AbstractClass.java
similarity index 83%
rename from src/test/examples/enclosingmethod/AbstractClass.java
rename to src/test/java/com/android/tools/r8/examples/enclosingmethod/AbstractClass.java
index 90dfe27..65eb0fc 100644
--- a/src/test/examples/enclosingmethod/AbstractClass.java
+++ b/src/test/java/com/android/tools/r8/examples/enclosingmethod/AbstractClass.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2017, 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 enclosingmethod;
+package com.android.tools.r8.examples.enclosingmethod;
 
 public abstract class AbstractClass {
   public abstract int anInt();
diff --git a/src/test/java/com/android/tools/r8/examples/enclosingmethod/EnclosingMethodTestRunner.java b/src/test/java/com/android/tools/r8/examples/enclosingmethod/EnclosingMethodTestRunner.java
new file mode 100644
index 0000000..091df7b
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/enclosingmethod/EnclosingMethodTestRunner.java
@@ -0,0 +1,97 @@
+// Copyright (c) 2023, 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.examples.enclosingmethod;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.ToolHelper.DexVm.Version;
+import com.android.tools.r8.examples.ExamplesTestBase;
+import com.android.tools.r8.utils.StringUtils;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.junit.Assume;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class EnclosingMethodTestRunner extends ExamplesTestBase {
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
+  }
+
+  public EnclosingMethodTestRunner(TestParameters parameters) {
+    super(parameters);
+  }
+
+  @Override
+  public Class<?> getMainClass() {
+    return Main.class;
+  }
+
+  @Override
+  public List<Class<?>> getTestClasses() throws Exception {
+    return ImmutableList.of(
+        getMainClass(),
+        AbstractClass.class,
+        OuterClass.class,
+        OuterClass.AClass.class,
+        Class.forName(OuterClass.class.getTypeName() + "$1"),
+        Class.forName(OuterClass.class.getTypeName() + "$2"),
+        Class.forName(OuterClass.class.getTypeName() + "$1AnotherClass"),
+        Class.forName(OuterClass.class.getTypeName() + "$1LocalClass"));
+  }
+
+  private boolean isDalvikWithIncorrectBehavior() {
+    // Dalvik does not correctly report the enclosing classes.
+    return parameters.isDexRuntimeVersionOlderThanOrEqual(Version.V4_4_4);
+  }
+
+  @Override
+  public String getExpected() {
+    return StringUtils.lines(
+        "42",
+        "class com.android.tools.r8.examples.enclosingmethod.OuterClass",
+        "null",
+        "true",
+        isDalvikWithIncorrectBehavior() ? "true" : "false",
+        "7",
+        "class com.android.tools.r8.examples.enclosingmethod.OuterClass",
+        "null",
+        "false",
+        "true",
+        "42",
+        "class com.android.tools.r8.examples.enclosingmethod.OuterClass",
+        "public void com.android.tools.r8.examples.enclosingmethod.OuterClass.aMethod()",
+        "true",
+        "false",
+        "48",
+        "class com.android.tools.r8.examples.enclosingmethod.OuterClass",
+        "public void com.android.tools.r8.examples.enclosingmethod.OuterClass.aMethod()",
+        "false",
+        "true",
+        "InnerClass com.android.tools.r8.examples.enclosingmethod.OuterClass$AClass");
+  }
+
+  @Test
+  public void testDesugaring() throws Exception {
+    Assume.assumeFalse(isDalvikWithIncorrectBehavior());
+    runTestDesugaring();
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    // The program reflects on inner-outer classes so disable all shrinking and optimization.
+    runTestR8(b -> b.addDontShrink().addDontOptimize().addDontObfuscate().addKeepAllAttributes());
+  }
+
+  @Ignore("TODO(b/281805219): R8 output steps to a different line number.")
+  @Test
+  public void testDebug() throws Exception {
+    runTestDebugComparator();
+  }
+}
diff --git a/src/test/examples/enclosingmethod/Main.java b/src/test/java/com/android/tools/r8/examples/enclosingmethod/Main.java
similarity index 90%
rename from src/test/examples/enclosingmethod/Main.java
rename to src/test/java/com/android/tools/r8/examples/enclosingmethod/Main.java
index c1c0b75..2eeb794 100644
--- a/src/test/examples/enclosingmethod/Main.java
+++ b/src/test/java/com/android/tools/r8/examples/enclosingmethod/Main.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2017, 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 enclosingmethod;
+package com.android.tools.r8.examples.enclosingmethod;
 
 public class Main {
   public static void main(String... args) {
diff --git a/src/test/examples/enclosingmethod/OuterClass.java b/src/test/java/com/android/tools/r8/examples/enclosingmethod/OuterClass.java
similarity index 96%
rename from src/test/examples/enclosingmethod/OuterClass.java
rename to src/test/java/com/android/tools/r8/examples/enclosingmethod/OuterClass.java
index 5268954..5f4562c 100644
--- a/src/test/examples/enclosingmethod/OuterClass.java
+++ b/src/test/java/com/android/tools/r8/examples/enclosingmethod/OuterClass.java
@@ -1,7 +1,7 @@
 // Copyright (c) 2017, 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 enclosingmethod;
+package com.android.tools.r8.examples.enclosingmethod;
 
 public class OuterClass {
   // Named member class.