Move cse and catch example tests to new test set up.

Bug: b/167145686
Change-Id: Iad2e492dd00075e595b9fb9124bb3925e35f6dc6
diff --git a/src/test/examples/catchhandleroverlap/CatchHandlerOverlap.java b/src/test/examples/catchhandleroverlap/CatchHandlerOverlap.java
deleted file mode 100644
index 7a4950c..0000000
--- a/src/test/examples/catchhandleroverlap/CatchHandlerOverlap.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright (c) 2018, 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 catchhandleroverlap;
-
-public class CatchHandlerOverlap {
-  private static void f() throws Exception {
-    throw new Exception("f");
-  }
-
-  private static void g() throws Exception {
-    throw new Exception("g");
-  }
-
-  private static void h(int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9,
-      int i10, int i11, int i12, int i13, int i14, int i15, int i16, int i17) {
-    System.out.println(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 +
-        i12 + i13 + i14 + i15 + i16 + i17);
-    try {
-      f();
-    } catch (Exception e0) {
-      try {
-        g();
-      } catch (Exception e1) {
-        System.out.println(e0.getMessage() + " " + e1.getMessage());
-      }
-    }
-  }
-
-  public static void main(String[] args) {
-    h(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
-  }
-}
diff --git a/src/test/java/com/android/tools/r8/CfFrontendExamplesTest.java b/src/test/java/com/android/tools/r8/CfFrontendExamplesTest.java
index 7e10a4c..3d1e963 100644
--- a/src/test/java/com/android/tools/r8/CfFrontendExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/CfFrontendExamplesTest.java
@@ -46,11 +46,6 @@
   }
 
   @Test
-  public void testCommonSubexpressionElimination() throws Exception {
-    runTest("cse.CommonSubexpressionElimination");
-  }
-
-  @Test
   public void testConstants() throws Exception {
     runTest("constants.Constants");
   }
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index ecb577a..c2a1ba2 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -26,8 +26,6 @@
   public static Collection<String[]> data() {
     String[] tests = {
         "arithmetic.Arithmetic",
-        "catchhandleroverlap.CatchHandlerOverlap",
-        "cse.CommonSubexpressionElimination",
         "constants.Constants",
         "controlflow.ControlFlow",
         "conversions.Conversions",
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 76f9758..98067bb 100644
--- a/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
+++ b/src/test/java/com/android/tools/r8/debug/ExamplesDebugTest.java
@@ -65,11 +65,6 @@
   }
 
   @Test
-  public void testCommonSubexpressionElimination() throws Exception {
-    testDebugging("cse", "CommonSubexpressionElimination");
-  }
-
-  @Test
   public void testConstants() throws Exception {
     testDebugging("constants", "Constants");
   }
diff --git a/src/test/java/com/android/tools/r8/examples/catchhandleroverlap/CatchHandlerOverlap.java b/src/test/java/com/android/tools/r8/examples/catchhandleroverlap/CatchHandlerOverlap.java
new file mode 100644
index 0000000..c66cd26
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/catchhandleroverlap/CatchHandlerOverlap.java
@@ -0,0 +1,50 @@
+// 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.catchhandleroverlap;
+
+public class CatchHandlerOverlap {
+
+  private static void f() throws Exception {
+    throw new Exception("f");
+  }
+
+  private static void g() throws Exception {
+    throw new Exception("g");
+  }
+
+  private static void h(
+      int i1,
+      int i2,
+      int i3,
+      int i4,
+      int i5,
+      int i6,
+      int i7,
+      int i8,
+      int i9,
+      int i10,
+      int i11,
+      int i12,
+      int i13,
+      int i14,
+      int i15,
+      int i16,
+      int i17) {
+    System.out.println(
+        i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15 + i16 + i17);
+    try {
+      f();
+    } catch (Exception e0) {
+      try {
+        g();
+      } catch (Exception e1) {
+        System.out.println(e0.getMessage() + " " + e1.getMessage());
+      }
+    }
+  }
+
+  public static void main(String[] args) {
+    h(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/examples/catchhandleroverlap/CatchHandlerOverlapTestRunner.java b/src/test/java/com/android/tools/r8/examples/catchhandleroverlap/CatchHandlerOverlapTestRunner.java
new file mode 100644
index 0000000..f8d0e85
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/catchhandleroverlap/CatchHandlerOverlapTestRunner.java
@@ -0,0 +1,50 @@
+// 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.catchhandleroverlap;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.examples.ExamplesTestBase;
+import com.android.tools.r8.utils.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class CatchHandlerOverlapTestRunner extends ExamplesTestBase {
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
+  }
+
+  public CatchHandlerOverlapTestRunner(TestParameters parameters) {
+    super(parameters);
+  }
+
+  @Override
+  public Class<?> getMainClass() {
+    return CatchHandlerOverlap.class;
+  }
+
+  @Override
+  public String getExpected() {
+    return StringUtils.lines("153", "f g");
+  }
+
+  @Test
+  public void testDesugaring() throws Exception {
+    runTestDesugaring();
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    runTestR8();
+  }
+
+  @Test
+  public void testDebug() throws Exception {
+    runTestDebugComparator();
+  }
+}
diff --git a/src/test/examples/cse/CommonSubexpressionElimination.java b/src/test/java/com/android/tools/r8/examples/cse/CommonSubexpressionElimination.java
similarity index 95%
rename from src/test/examples/cse/CommonSubexpressionElimination.java
rename to src/test/java/com/android/tools/r8/examples/cse/CommonSubexpressionElimination.java
index 3c64a1d..4ae0ba7 100644
--- a/src/test/examples/cse/CommonSubexpressionElimination.java
+++ b/src/test/java/com/android/tools/r8/examples/cse/CommonSubexpressionElimination.java
@@ -1,11 +1,11 @@
-// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// 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.
 
 // This code is not run directly. It needs to be compiled to dex code.
 // 'arithmetic.dex' is what is run.
 
-package cse;
+package com.android.tools.r8.examples.cse;
 
 public class CommonSubexpressionElimination {
 
@@ -74,7 +74,6 @@
     }
   }
 
-
   public static void main(String[] args) {
     System.out.println(divNoCatch(1, 0, 1));
     System.out.println(divNoCatch2(1, 0, 2));
diff --git a/src/test/java/com/android/tools/r8/examples/cse/CommonSubexpressionEliminationTestRunner.java b/src/test/java/com/android/tools/r8/examples/cse/CommonSubexpressionEliminationTestRunner.java
new file mode 100644
index 0000000..1f50713
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/examples/cse/CommonSubexpressionEliminationTestRunner.java
@@ -0,0 +1,50 @@
+// 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.cse;
+
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.examples.ExamplesTestBase;
+import com.android.tools.r8.utils.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class CommonSubexpressionEliminationTestRunner extends ExamplesTestBase {
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().enableApiLevelsForCf().build();
+  }
+
+  public CommonSubexpressionEliminationTestRunner(TestParameters parameters) {
+    super(parameters);
+  }
+
+  @Override
+  public Class<?> getMainClass() {
+    return CommonSubexpressionElimination.class;
+  }
+
+  @Override
+  public String getExpected() {
+    return StringUtils.lines("1", "1", "2 2", "2", "3", "3", "4 4", "4", "A", "B");
+  }
+
+  @Test
+  public void testDesugaring() throws Exception {
+    runTestDesugaring();
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    runTestR8();
+  }
+
+  @Test
+  public void testDebug() throws Exception {
+    runTestDebugComparator();
+  }
+}