R8RunExamplesCommon: Don't reassign ExpectedException

Instead of reassigning `thrown` to ExpectedException.none(), ensure that
test fails if no expection was thrown in compile() by returning early
(without throwing) in outputIsIdentical().

Also fix If8011354 a4038e4a3 ("Run test examples in CF-to-DEX mode",
2018-06-06) in which getFailingCompileCfToDex() and
getFailingRunCfToDex() were mixed up.

Change-Id: Ie75784e84fa856deddfaa7704119011fcc2c32e3
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesCommon.java b/src/test/java/com/android/tools/r8/R8RunExamplesCommon.java
index 4afd0c2..3d3b4e7 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesCommon.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesCommon.java
@@ -145,12 +145,7 @@
 
   @Before
   public void compile() throws Exception {
-    if (output == Output.CF && getFailingCompileCf().contains(mainClass)) {
-      thrown.expect(Throwable.class);
-    }
-    if (frontend == Frontend.CF
-        && output == Output.DEX
-        && getFailingCompileCfToDex().contains(mainClass)) {
+    if (shouldCompileFail()) {
       thrown.expect(Throwable.class);
     }
     OutputMode outputMode = output == Output.CF ? OutputMode.ClassFile : OutputMode.DexIndexed;
@@ -191,8 +186,25 @@
     }
   }
 
+  private boolean shouldCompileFail() {
+    if (output == Output.CF && getFailingCompileCf().contains(mainClass)) {
+      return true;
+    }
+    if (frontend == Frontend.CF
+        && output == Output.DEX
+        && getFailingCompileCfToDex().contains(mainClass)) {
+      return true;
+    }
+    return false;
+  }
+
   @Test
   public void outputIsIdentical() throws IOException, InterruptedException, ExecutionException {
+    if (shouldCompileFail()) {
+      // We expected an exception, but got none.
+      // Return to ensure that this test fails due to the missing exception.
+      return;
+    }
     Assume.assumeTrue(ToolHelper.artSupported() || ToolHelper.compareAgaintsGoldenFiles());
 
 
@@ -216,8 +228,6 @@
         output == Output.CF ? getFailingRunCf().get(mainClass) : getFailingRun().get(mainClass);
     if (condition != null && condition.test(getTool(), compiler, vm.getVersion(), mode)) {
       thrown.expect(Throwable.class);
-    } else {
-      thrown = ExpectedException.none();
     }
 
     if (frontend == Frontend.CF
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index 4ee928b..348dbf1 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -151,7 +151,7 @@
   }
 
   @Override
-  protected Set<String> getFailingCompileCfToDex() {
+  protected Set<String> getFailingRunCfToDex() {
     return new ImmutableSet.Builder<String>()
         // TODO(b/109788783): Implement byte/boolean distinction for array load/store.
         .add("arrayaccess.ArrayAccess")
@@ -161,7 +161,7 @@
   }
 
   @Override
-  protected Set<String> getFailingRunCfToDex() {
+  protected Set<String> getFailingCompileCfToDex() {
     return new ImmutableSet.Builder<String>()
         // TODO(b/109789541): Implement method synchronization for DEX backend.
         .add("sync.Sync")