Specialize exceptions in desugared lib test infrastructure

Now we can remove "Throwable" in each test method and instead use the more specialized exception.

Change-Id: Icab45ee98fd92287bd390cb929d0103a5a40d5a4
diff --git a/src/test/java/com/android/tools/r8/L8TestCompileResult.java b/src/test/java/com/android/tools/r8/L8TestCompileResult.java
index fd5af1c..30744c3 100644
--- a/src/test/java/com/android/tools/r8/L8TestCompileResult.java
+++ b/src/test/java/com/android/tools/r8/L8TestCompileResult.java
@@ -77,7 +77,7 @@
   }
 
   public <E extends Throwable> L8TestCompileResult inspectKeepRules(
-      ThrowingConsumer<List<String>, E> consumer) throws Throwable {
+      ThrowingConsumer<List<String>, E> consumer) throws E {
     consumer.accept(allKeepRules);
     return self();
   }
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestBuilder.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestBuilder.java
index b67d511..6ef6b8b 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestBuilder.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestBuilder.java
@@ -38,6 +38,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import java.util.function.Consumer;
 import java.util.function.Function;
 import org.junit.Assume;
@@ -344,14 +345,16 @@
     builder.addLibraryFiles(libraryDesugaringSpecification.getLibraryFiles());
   }
 
-  public DesugaredLibraryTestCompileResult<T> compile() throws Exception {
+  public DesugaredLibraryTestCompileResult<T> compile()
+      throws CompilationFailedException, IOException, ExecutionException {
     prepareCompilation();
     TestCompileResult<?, ? extends SingleTestRunResult<?>> compile = builder.compile();
     return internalCompile(compile);
   }
 
   public DesugaredLibraryTestCompileResult<T> compileWithExpectedDiagnostics(
-      DiagnosticsConsumer consumer) throws Exception {
+      DiagnosticsConsumer consumer)
+      throws CompilationFailedException, IOException, ExecutionException {
     prepareCompilation();
     TestCompileResult<?, ? extends SingleTestRunResult<?>> compile =
         builder.compileWithExpectedDiagnostics(consumer);
@@ -359,7 +362,8 @@
   }
 
   private DesugaredLibraryTestCompileResult<T> internalCompile(
-      TestCompileResult<?, ? extends SingleTestRunResult<?>> compile) throws Exception {
+      TestCompileResult<?, ? extends SingleTestRunResult<?>> compile)
+      throws CompilationFailedException, IOException, ExecutionException {
     L8TestCompileResult l8Compile = compileDesugaredLibrary(compile, keepRuleConsumer);
     D8TestCompileResult customLibCompile = compileCustomLib();
     return new DesugaredLibraryTestCompileResult<>(
@@ -382,7 +386,7 @@
   private L8TestCompileResult compileDesugaredLibrary(
       TestCompileResult<?, ? extends SingleTestRunResult<?>> compile,
       KeepRuleConsumer keepRuleConsumer)
-      throws Exception {
+      throws CompilationFailedException, IOException, ExecutionException {
     if (!compilationSpecification.isL8Shrink()) {
       return compileDesugaredLibrary(null);
     }
@@ -401,7 +405,8 @@
     return compileDesugaredLibrary(keepRules);
   }
 
-  private L8TestCompileResult compileDesugaredLibrary(String keepRule) throws Exception {
+  private L8TestCompileResult compileDesugaredLibrary(String keepRule)
+      throws CompilationFailedException, IOException, ExecutionException {
     assert !compilationSpecification.isL8Shrink() || keepRule != null;
     return test.testForL8(parameters.getApiLevel(), parameters.getBackend())
         .apply(
@@ -427,7 +432,8 @@
   }
 
   public String collectKeepRulesWithTraceReferences(
-      Path desugaredProgramClassFile, Path desugaredLibraryClassFile) throws Exception {
+      Path desugaredProgramClassFile, Path desugaredLibraryClassFile)
+      throws CompilationFailedException, IOException {
     Path generatedKeepRules = test.temp.newFile().toPath();
     ArrayList<String> args = new ArrayList<>();
     args.add("--keep-rules");
@@ -449,12 +455,12 @@
   }
 
   public SingleTestRunResult<?> run(TestRuntime runtime, Class<?> mainClass, String... args)
-      throws Exception {
+      throws ExecutionException, IOException, CompilationFailedException {
     return compile().run(runtime, mainClass.getTypeName(), args);
   }
 
   public SingleTestRunResult<?> run(TestRuntime runtime, String mainClass, String... args)
-      throws Exception {
+      throws ExecutionException, IOException, CompilationFailedException {
     return compile().run(runtime, mainClass, args);
   }
 
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestCompileResult.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestCompileResult.java
index bd11465..3172876 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestCompileResult.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/DesugaredLibraryTestCompileResult.java
@@ -18,6 +18,7 @@
 import java.io.IOException;
 import java.nio.file.Path;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import java.util.function.Consumer;
 
 public class DesugaredLibraryTestCompileResult<T extends DesugaredLibraryTestBase> {
@@ -41,7 +42,7 @@
       CompilationSpecification compilationSpecification,
       D8TestCompileResult customLibCompile,
       L8TestCompileResult l8Compile)
-      throws Exception {
+      throws CompilationFailedException, IOException {
     this.test = test;
     this.compileResult = compileResult;
     this.parameters = parameters;
@@ -53,26 +54,26 @@
   }
 
   public <E extends Throwable> DesugaredLibraryTestCompileResult<T> inspectCustomLib(
-      ThrowingConsumer<CodeInspector, E> consumer) throws Throwable {
+      ThrowingConsumer<CodeInspector, E> consumer) throws IOException, E {
     assert customLibCompile != null;
     customLibCompile.inspect(consumer);
     return this;
   }
 
   public <E extends Throwable> DesugaredLibraryTestCompileResult<T> inspectL8(
-      ThrowingConsumer<CodeInspector, E> consumer) throws Throwable {
+      ThrowingConsumer<CodeInspector, E> consumer) throws IOException, E {
     l8Compile.inspect(consumer);
     return this;
   }
 
   public <E extends Throwable> DesugaredLibraryTestCompileResult<T> inspect(
-      ThrowingConsumer<CodeInspector, E> consumer) throws Throwable {
+      ThrowingConsumer<CodeInspector, E> consumer) throws IOException, E {
     compileResult.inspect(consumer);
     return this;
   }
 
   public <E extends Throwable> DesugaredLibraryTestCompileResult<T> inspectKeepRules(
-      ThrowingConsumer<List<String>, E> consumer) throws Throwable {
+      ThrowingConsumer<List<String>, E> consumer) throws E {
     if (compilationSpecification.isL8Shrink()) {
       l8Compile.inspectKeepRules(consumer);
     }
@@ -80,21 +81,21 @@
   }
 
   public <E extends Throwable> DesugaredLibraryTestCompileResult<T> apply(
-      ThrowingConsumer<DesugaredLibraryTestCompileResult<T>, E> consumer) throws Throwable {
+      ThrowingConsumer<DesugaredLibraryTestCompileResult<T>, E> consumer) throws E {
     consumer.accept(this);
     return this;
   }
 
-  public CodeInspector customLibInspector() throws Throwable {
+  public CodeInspector customLibInspector() throws IOException {
     assert customLibCompile != null;
     return customLibCompile.inspector();
   }
 
-  public CodeInspector l8Inspector() throws Throwable {
+  public CodeInspector l8Inspector() throws IOException {
     return l8Compile.inspector();
   }
 
-  public CodeInspector inspector() throws Throwable {
+  public CodeInspector inspector() throws IOException {
     return compileResult.inspector();
   }
 
@@ -105,17 +106,17 @@
   }
 
   public SingleTestRunResult<?> run(TestRuntime runtime, Class<?> mainClass, String... args)
-      throws Exception {
+      throws ExecutionException, IOException {
     return run(runtime, mainClass.getTypeName(), args);
   }
 
   public SingleTestRunResult<?> run(TestRuntime runtime, String mainClassName, String... args)
-      throws Exception {
+      throws ExecutionException, IOException {
     return runnableCompiledResult.run(runtime, mainClassName, args);
   }
 
   private TestCompileResult<?, ? extends SingleTestRunResult<?>> computeRunnableCompiledResult()
-      throws Exception {
+      throws CompilationFailedException, IOException {
     TestCompileResult<?, ? extends SingleTestRunResult<?>> runnable = convertToDexIfNeeded();
     if (customLibCompile != null) {
       runnable.addRunClasspathFiles(customLibCompile.writeToZip());