Add CLI tests for various flag additions and fixes.

Bug: 157708956
Change-Id: I78de0ab4de7a6bd8280080260c07fb2aa42c536c
diff --git a/src/test/java/com/android/tools/r8/D8CommandTest.java b/src/test/java/com/android/tools/r8/D8CommandTest.java
index ce051a5..f395118 100644
--- a/src/test/java/com/android/tools/r8/D8CommandTest.java
+++ b/src/test/java/com/android/tools/r8/D8CommandTest.java
@@ -37,14 +37,20 @@
 import java.util.List;
 import java.util.Set;
 import java.util.zip.ZipFile;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
-public class D8CommandTest {
+@RunWith(Parameterized.class)
+public class D8CommandTest extends TestBase {
 
-  @Rule
-  public TemporaryFolder temp = ToolHelper.getTemporaryFolderForTest();
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withNoneRuntime().build();
+  }
+
+  public D8CommandTest(TestParameters parameters) {}
 
   @Test(expected = CompilationFailedException.class)
   public void emptyBuilder() throws Throwable {
@@ -267,6 +273,12 @@
     parse("--main-dex-list", mainDexList.toString());
   }
 
+  @Test
+  public void testFlagFilePerClass() throws Throwable {
+    D8Command command = parse("--file-per-class");
+    assertTrue(command.getProgramConsumer() instanceof DexFilePerClassFileConsumer);
+  }
+
   @Test(expected = CompilationFailedException.class)
   public void mainDexListWithFilePerClass() throws Throwable {
     Path mainDexList = temp.newFile("main-dex-list.txt").toPath();
@@ -274,6 +286,19 @@
     assertTrue(ToolHelper.getApp(command).hasMainDexListResources());
   }
 
+  @Test
+  public void testFlagFilePerClassFile() throws Throwable {
+    D8Command command = parse("--file-per-class-file");
+    assertTrue(command.getProgramConsumer() instanceof DexFilePerClassFileConsumer);
+  }
+
+  @Test(expected = CompilationFailedException.class)
+  public void mainDexListWithFilePerClassFile() throws Throwable {
+    Path mainDexList = temp.newFile("main-dex-list.txt").toPath();
+    D8Command command = parse("--main-dex-list", mainDexList.toString(), "--file-per-class-file");
+    assertTrue(ToolHelper.getApp(command).hasMainDexListResources());
+  }
+
   @Test(expected = CompilationFailedException.class)
   public void mainDexListWithIntermediate() throws Throwable {
     Path mainDexList = temp.newFile("main-dex-list.txt").toPath();
diff --git a/src/test/java/com/android/tools/r8/L8CommandTest.java b/src/test/java/com/android/tools/r8/L8CommandTest.java
index 705ecff..1631830 100644
--- a/src/test/java/com/android/tools/r8/L8CommandTest.java
+++ b/src/test/java/com/android/tools/r8/L8CommandTest.java
@@ -3,6 +3,8 @@
 // BSD-style license that can be found in the LICENSE file.
 package com.android.tools.r8;
 
+import static com.android.tools.r8.DiagnosticsMatcher.diagnosticMessage;
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -15,6 +17,7 @@
 import com.android.tools.r8.origin.EmbeddedOrigin;
 import com.android.tools.r8.origin.Origin;
 import com.android.tools.r8.utils.AndroidApiLevel;
+import com.android.tools.r8.utils.FileUtils;
 import com.android.tools.r8.utils.ThreadUtils;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
@@ -24,14 +27,20 @@
 import java.util.Collections;
 import java.util.List;
 import org.junit.Ignore;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
-public class L8CommandTest {
+@RunWith(Parameterized.class)
+public class L8CommandTest extends TestBase {
 
-  @Rule
-  public TemporaryFolder temp = ToolHelper.getTemporaryFolderForTest();
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withNoneRuntime().build();
+  }
+
+  public L8CommandTest(TestParameters parameters) {}
 
   @Test(expected = CompilationFailedException.class)
   public void emptyBuilder() throws Throwable {
@@ -95,6 +104,34 @@
     Marker marker = markers.iterator().next();
   }
 
+  @Test
+  public void testFlagPgConf() throws Exception {
+    TestDiagnosticMessagesImpl diagnostics = new TestDiagnosticMessagesImpl();
+    Path pgconf = temp.newFolder().toPath().resolve("pg.conf");
+    FileUtils.writeTextFile(pgconf, "");
+    parse(
+        diagnostics,
+        "--desugared-lib",
+        ToolHelper.DESUGAR_LIB_JSON_FOR_TESTING.toString(),
+        "--pg-conf",
+        pgconf.toString());
+  }
+
+  @Test
+  public void testFlagPgConfMissingParameter() {
+    TestDiagnosticMessagesImpl diagnostics = new TestDiagnosticMessagesImpl();
+    try {
+      parse(
+          diagnostics,
+          "--desugared-lib",
+          ToolHelper.DESUGAR_LIB_JSON_FOR_TESTING.toString(),
+          "--pg-conf");
+      fail("Expected parse error");
+    } catch (CompilationFailedException e) {
+      diagnostics.assertErrorsMatch(diagnosticMessage(containsString("Missing parameter")));
+    }
+  }
+
   private L8Command.Builder prepareBuilder(DiagnosticsHandler handler) {
     return L8Command.builder(handler)
         .addLibraryFiles(ToolHelper.getAndroidJar(AndroidApiLevel.P))
diff --git a/src/test/java/com/android/tools/r8/R8CommandTest.java b/src/test/java/com/android/tools/r8/R8CommandTest.java
index b5c518c..149c3c3 100644
--- a/src/test/java/com/android/tools/r8/R8CommandTest.java
+++ b/src/test/java/com/android/tools/r8/R8CommandTest.java
@@ -3,7 +3,9 @@
 // BSD-style license that can be found in the LICENSE file.
 package com.android.tools.r8;
 
+import static com.android.tools.r8.DiagnosticsMatcher.diagnosticMessage;
 import static com.android.tools.r8.ToolHelper.EXAMPLES_BUILD_DIR;
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
@@ -37,14 +39,20 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipOutputStream;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
-public class R8CommandTest {
+@RunWith(Parameterized.class)
+public class R8CommandTest extends TestBase {
 
-  @Rule
-  public TemporaryFolder temp = ToolHelper.getTemporaryFolderForTest();
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withNoneRuntime().build();
+  }
+
+  public R8CommandTest(TestParameters parameters) {}
 
   @Test(expected = CompilationFailedException.class)
   public void emptyBuilder() throws Throwable {
@@ -759,6 +767,34 @@
   }
 
   @Test
+  public void desugaredLibraryWithOutputConf() throws CompilationFailedException {
+    Path pgout = temp.getRoot().toPath().resolve("pgout.conf");
+    R8Command r8Command =
+        parse(
+            "--desugared-lib",
+            "src/library_desugar/desugar_jdk_libs.json",
+            "--desugared-lib-pg-conf-output",
+            pgout.toString());
+    assertFalse(
+        r8Command.getInternalOptions().desugaredLibraryConfiguration.getRewritePrefix().isEmpty());
+  }
+
+  @Test
+  public void desugaredLibraryWithOutputConfMissingArg() {
+    TestDiagnosticMessagesImpl diagnostics = new TestDiagnosticMessagesImpl();
+    try {
+      parse(
+          diagnostics,
+          "--desugared-lib",
+          "src/library_desugar/desugar_jdk_libs.json",
+          "--desugared-lib-pg-conf-output");
+      fail("Expected parse error");
+    } catch (CompilationFailedException e) {
+      diagnostics.assertErrorsMatch(diagnosticMessage(containsString("Missing parameter")));
+    }
+  }
+
+  @Test
   public void numThreadsOption() throws Exception {
     assertEquals(ThreadUtils.NOT_SPECIFIED, parse().getThreadCount());
     assertEquals(1, parse("--thread-count", "1").getThreadCount());
diff --git a/src/test/java/com/android/tools/r8/TestDiagnosticMessagesImpl.java b/src/test/java/com/android/tools/r8/TestDiagnosticMessagesImpl.java
index 19a700d..54ad442 100644
--- a/src/test/java/com/android/tools/r8/TestDiagnosticMessagesImpl.java
+++ b/src/test/java/com/android/tools/r8/TestDiagnosticMessagesImpl.java
@@ -201,7 +201,8 @@
         if (!matchedDiagnostics.contains(diagnostic)) {
           builder
               .append("\n  - ")
-              .append(diagnostics.getClass().getName())
+              .append(diagnostic.getClass().getName())
+              .append(": ")
               .append(diagnostic.getDiagnosticMessage());
         }
       }
@@ -220,7 +221,8 @@
       for (Diagnostic diagnostic : diagnostics) {
         builder
             .append("\n  - ")
-            .append(diagnostics.getClass().getName())
+            .append(diagnostic.getClass().getName())
+            .append(": ")
             .append(diagnostic.getDiagnosticMessage());
       }
       builder.append("\nAll matchers:");