Move TestOutputFormat and TestSummaryFormat into ExecutionOptions.

This breaks a dependency cycle between ExecutionOptions and TestStrategy.

PiperOrigin-RevId: 305231464
diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
index 1a1c1bc..4c2728d 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java
@@ -27,6 +27,7 @@
 import com.google.devtools.common.options.BoolOrEnumConverter;
 import com.google.devtools.common.options.Converters;
 import com.google.devtools.common.options.Converters.CommaSeparatedNonEmptyOptionListConverter;
+import com.google.devtools.common.options.EnumConverter;
 import com.google.devtools.common.options.Option;
 import com.google.devtools.common.options.OptionDocumentationCategory;
 import com.google.devtools.common.options.OptionEffectTag;
@@ -239,33 +240,31 @@
   public PathFragment testTmpDir;
 
   @Option(
-    name = "test_output",
-    defaultValue = "summary",
-    converter = TestStrategy.TestOutputFormat.Converter.class,
-    documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
-    effectTags = {OptionEffectTag.UNKNOWN},
-    help =
-        "Specifies desired output mode. Valid values are 'summary' to output only test status "
-            + "summary, 'errors' to also print test logs for failed tests, 'all' to print logs "
-            + "for all tests and 'streamed' to output logs for all tests in real time "
-            + "(this will force tests to be executed locally one at a time regardless of "
-            + "--test_strategy value)."
-  )
-  public TestStrategy.TestOutputFormat testOutput;
+      name = "test_output",
+      defaultValue = "summary",
+      converter = TestOutputFormat.Converter.class,
+      documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+      effectTags = {OptionEffectTag.UNKNOWN},
+      help =
+          "Specifies desired output mode. Valid values are 'summary' to output only test status "
+              + "summary, 'errors' to also print test logs for failed tests, 'all' to print logs "
+              + "for all tests and 'streamed' to output logs for all tests in real time "
+              + "(this will force tests to be executed locally one at a time regardless of "
+              + "--test_strategy value).")
+  public TestOutputFormat testOutput;
 
   @Option(
-    name = "test_summary",
-    defaultValue = "short",
-    converter = TestStrategy.TestSummaryFormat.Converter.class,
-    documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
-    effectTags = {OptionEffectTag.UNKNOWN},
-    help =
-        "Specifies the desired format ot the test summary. Valid values are 'short' to print "
-            + "information only about tests executed, 'terse', to print information only about "
-            + "unsuccessful tests that were run, 'detailed' to print detailed information about "
-            + "failed test cases, and 'none' to omit the summary."
-  )
-  public TestStrategy.TestSummaryFormat testSummary;
+      name = "test_summary",
+      defaultValue = "short",
+      converter = TestSummaryFormat.Converter.class,
+      documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+      effectTags = {OptionEffectTag.UNKNOWN},
+      help =
+          "Specifies the desired format ot the test summary. Valid values are 'short' to print "
+              + "information only about tests executed, 'terse', to print information only about "
+              + "unsuccessful tests that were run, 'detailed' to print detailed information about "
+              + "failed test cases, and 'none' to omit the summary.")
+  public TestSummaryFormat testSummary;
 
   @Option(
     name = "resource_autosense",
@@ -478,6 +477,38 @@
               + "test log. Otherwise, Bazel generates a test.xml as part of the test action.")
   public boolean splitXmlGeneration;
 
+  /** An enum for specifying different formats of test output. */
+  public enum TestOutputFormat {
+    SUMMARY, // Provide summary output only.
+    ERRORS, // Print output from failed tests to the stderr after the test failure.
+    ALL, // Print output from all tests to the stderr after the test completion.
+    STREAMED; // Stream output for each test.
+
+    /** Converts to {@link TestOutputFormat}. */
+    public static class Converter extends EnumConverter<TestOutputFormat> {
+      public Converter() {
+        super(TestOutputFormat.class, "test output");
+      }
+    }
+  }
+
+  /** An enum for specifying different formatting styles of test summaries. */
+  public enum TestSummaryFormat {
+    SHORT, // Print information only about tests.
+    TERSE, // Like "SHORT", but even shorter: Do not print PASSED and NO STATUS tests.
+    DETAILED, // Print information only about failed test cases.
+    NONE, // Do not print summary.
+    TESTCASE; // Print summary in test case resolution, do not print detailed information about
+    // failed test cases.
+
+    /** Converts to {@link TestSummaryFormat}. */
+    public static class Converter extends EnumConverter<TestSummaryFormat> {
+      public Converter() {
+        super(TestSummaryFormat.class, "test summary");
+      }
+    }
+  }
+
   /** Converter for the --flaky_test_attempts option. */
   public static class TestAttemptsConverter extends PerLabelOptions.PerLabelOptionsConverter {
     private static final int MIN_VALUE = 1;
diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
index 996df02..a82fd1d 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
@@ -296,7 +296,7 @@
     Path err = resolvedPaths.getTestStderr();
     FileOutErr testOutErr = new FileOutErr(out, err);
     Closeable streamed = null;
-    if (executionOptions.testOutput.equals(TestOutputFormat.STREAMED)) {
+    if (executionOptions.testOutput.equals(ExecutionOptions.TestOutputFormat.STREAMED)) {
       streamed =
           createStreamedTestOutput(
               Reporter.outErrForReporter(actionExecutionContext.getEventHandler()), out);
diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestLogHelper.java b/src/main/java/com/google/devtools/build/lib/exec/TestLogHelper.java
index 589c85c..0a47aef 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/TestLogHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/TestLogHelper.java
@@ -14,7 +14,7 @@
 package com.google.devtools.build.lib.exec;
 
 import com.google.common.io.ByteStreams;
-import com.google.devtools.build.lib.exec.TestStrategy.TestOutputFormat;
+import com.google.devtools.build.lib.exec.ExecutionOptions.TestOutputFormat;
 import com.google.devtools.build.lib.util.OS;
 import com.google.devtools.build.lib.vfs.Path;
 import java.io.BufferedOutputStream;
@@ -38,8 +38,8 @@
    * test has passed or not.
    */
   public static boolean shouldOutputTestLog(TestOutputFormat outputMode, boolean hasPassed) {
-    return (outputMode == TestOutputFormat.ALL)
-        || (!hasPassed && (outputMode == TestOutputFormat.ERRORS));
+    return (outputMode == ExecutionOptions.TestOutputFormat.ALL)
+        || (!hasPassed && (outputMode == ExecutionOptions.TestOutputFormat.ERRORS));
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
index 97ef786..2afdce3 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
@@ -46,7 +46,6 @@
 import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
 import com.google.devtools.build.lib.view.test.TestStatus.TestCase;
 import com.google.devtools.build.lib.view.test.TestStatus.TestResultData;
-import com.google.devtools.common.options.EnumConverter;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -102,38 +101,6 @@
     directory.createDirectoryAndParents();
   }
 
-  /** An enum for specifying different formats of test output. */
-  public enum TestOutputFormat {
-    SUMMARY, // Provide summary output only.
-    ERRORS, // Print output from failed tests to the stderr after the test failure.
-    ALL, // Print output from all tests to the stderr after the test completion.
-    STREAMED; // Stream output for each test.
-
-    /** Converts to {@link TestOutputFormat}. */
-    public static class Converter extends EnumConverter<TestOutputFormat> {
-      public Converter() {
-        super(TestOutputFormat.class, "test output");
-      }
-    }
-  }
-
-  /** An enum for specifying different formatting styles of test summaries. */
-  public enum TestSummaryFormat {
-    SHORT, // Print information only about tests.
-    TERSE, // Like "SHORT", but even shorter: Do not print PASSED and NO STATUS tests.
-    DETAILED, // Print information only about failed test cases.
-    NONE, // Do not print summary.
-    TESTCASE; // Print summary in test case resolution, do not print detailed information about
-    // failed test cases.
-
-    /** Converts to {@link TestSummaryFormat}. */
-    public static class Converter extends EnumConverter<TestSummaryFormat> {
-      public Converter() {
-        super(TestSummaryFormat.class, "test summary");
-      }
-    }
-  }
-
   public static final PathFragment TEST_TMP_ROOT = PathFragment.create("_tmp");
 
   // Used for generating unique temporary directory names. Contains the next numeric index for every
@@ -325,8 +292,8 @@
   protected TestCase parseTestResult(Path resultFile) {
     /* xml files. We avoid parsing it unnecessarily, since test results can potentially consume
     a large amount of memory. */
-    if ((executionOptions.testSummary != TestSummaryFormat.DETAILED)
-        && (executionOptions.testSummary != TestSummaryFormat.TESTCASE)) {
+    if ((executionOptions.testSummary != ExecutionOptions.TestSummaryFormat.DETAILED)
+        && (executionOptions.testSummary != ExecutionOptions.TestSummaryFormat.TESTCASE)) {
       return null;
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifier.java b/src/main/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifier.java
index 56d1953..e05d762 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifier.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifier.java
@@ -13,17 +13,17 @@
 // limitations under the License.
 package com.google.devtools.build.lib.runtime;
 
-import static com.google.devtools.build.lib.exec.TestStrategy.TestSummaryFormat.DETAILED;
-import static com.google.devtools.build.lib.exec.TestStrategy.TestSummaryFormat.TESTCASE;
+import static com.google.devtools.build.lib.exec.ExecutionOptions.TestSummaryFormat.DETAILED;
+import static com.google.devtools.build.lib.exec.ExecutionOptions.TestSummaryFormat.TESTCASE;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.devtools.build.lib.analysis.test.TestResult;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.exec.ExecutionOptions;
+import com.google.devtools.build.lib.exec.ExecutionOptions.TestOutputFormat;
+import com.google.devtools.build.lib.exec.ExecutionOptions.TestSummaryFormat;
 import com.google.devtools.build.lib.exec.TestLogHelper;
-import com.google.devtools.build.lib.exec.TestStrategy.TestOutputFormat;
-import com.google.devtools.build.lib.exec.TestStrategy.TestSummaryFormat;
 import com.google.devtools.build.lib.runtime.TestSummaryPrinter.TestLogPathFormatter;
 import com.google.devtools.build.lib.util.StringUtil;
 import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter;
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/TestSummaryPrinter.java b/src/main/java/com/google/devtools/build/lib/runtime/TestSummaryPrinter.java
index 33d0819..f06e436 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/TestSummaryPrinter.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/TestSummaryPrinter.java
@@ -15,8 +15,8 @@
 
 import com.google.common.base.Joiner;
 import com.google.common.base.Strings;
+import com.google.devtools.build.lib.exec.ExecutionOptions.TestOutputFormat;
 import com.google.devtools.build.lib.exec.TestLogHelper;
-import com.google.devtools.build.lib.exec.TestStrategy.TestOutputFormat;
 import com.google.devtools.build.lib.util.LoggingUtil;
 import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter;
 import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter.Mode;
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java
index 1f8a2b7..c9bd18f 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java
@@ -27,8 +27,7 @@
 import com.google.devtools.build.lib.buildtool.buildevent.TestingCompleteEvent;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.exec.ExecutionOptions;
-import com.google.devtools.build.lib.exec.TestStrategy;
-import com.google.devtools.build.lib.exec.TestStrategy.TestOutputFormat;
+import com.google.devtools.build.lib.exec.ExecutionOptions.TestOutputFormat;
 import com.google.devtools.build.lib.runtime.AggregatingTestListener;
 import com.google.devtools.build.lib.runtime.BlazeCommand;
 import com.google.devtools.build.lib.runtime.BlazeCommandResult;
@@ -73,7 +72,7 @@
   public void editOptions(OptionsParser optionsParser) {
     TestOutputFormat testOutput = optionsParser.getOptions(ExecutionOptions.class).testOutput;
     try {
-      if (testOutput == TestStrategy.TestOutputFormat.STREAMED) {
+      if (testOutput == ExecutionOptions.TestOutputFormat.STREAMED) {
         optionsParser.parse(
             PriorityCategory.SOFTWARE_REQUIREMENT,
             "streamed output requires locally run tests, without sharding",
@@ -87,7 +86,7 @@
   @Override
   public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult options) {
     TestOutputFormat testOutput = options.getOptions(ExecutionOptions.class).testOutput;
-    if (testOutput == TestStrategy.TestOutputFormat.STREAMED) {
+    if (testOutput == ExecutionOptions.TestOutputFormat.STREAMED) {
       env.getReporter().handle(Event.warn(
           "Streamed test output requested. All tests will be run locally, without sharding, "
           + "one at a time"));
diff --git a/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java b/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java
index 8014026..8eb4b6f 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/StandaloneTestStrategyTest.java
@@ -51,7 +51,6 @@
 import com.google.devtools.build.lib.events.EventKind;
 import com.google.devtools.build.lib.events.ExtendedEventHandler;
 import com.google.devtools.build.lib.events.StoredEventHandler;
-import com.google.devtools.build.lib.exec.TestStrategy.TestOutputFormat;
 import com.google.devtools.build.lib.util.OS;
 import com.google.devtools.build.lib.util.io.FileOutErr;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
@@ -468,7 +467,7 @@
   @Test
   public void testThatTestLogAndOutputAreReturned() throws Exception {
     ExecutionOptions executionOptions = Options.getDefaults(ExecutionOptions.class);
-    executionOptions.testOutput = TestOutputFormat.ERRORS;
+    executionOptions.testOutput = ExecutionOptions.TestOutputFormat.ERRORS;
     Path tmpDirRoot = TestStrategy.getTmpRoot(rootDirectory, outputBase, executionOptions);
     BinTools binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
     TestedStandaloneTestStrategy standaloneTestStrategy =
@@ -558,7 +557,7 @@
   @Test
   public void testThatTestLogAndOutputAreReturnedWithSplitXmlGeneration() throws Exception {
     ExecutionOptions executionOptions = Options.getDefaults(ExecutionOptions.class);
-    executionOptions.testOutput = TestOutputFormat.ERRORS;
+    executionOptions.testOutput = ExecutionOptions.TestOutputFormat.ERRORS;
     executionOptions.splitXmlGeneration = true;
     Path tmpDirRoot = TestStrategy.getTmpRoot(rootDirectory, outputBase, executionOptions);
     BinTools binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
@@ -654,7 +653,7 @@
   @Test
   public void testEmptyOutputCreatesEmptyLogFile() throws Exception {
     ExecutionOptions executionOptions = Options.getDefaults(ExecutionOptions.class);
-    executionOptions.testOutput = TestOutputFormat.ALL;
+    executionOptions.testOutput = ExecutionOptions.TestOutputFormat.ALL;
     Path tmpDirRoot = TestStrategy.getTmpRoot(rootDirectory, outputBase, executionOptions);
     BinTools binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
     TestedStandaloneTestStrategy standaloneTestStrategy =
@@ -710,7 +709,7 @@
   @Test
   public void testAppendStdErrDoesNotBusyLoop() throws Exception {
     ExecutionOptions executionOptions = Options.getDefaults(ExecutionOptions.class);
-    executionOptions.testOutput = TestOutputFormat.ALL;
+    executionOptions.testOutput = ExecutionOptions.TestOutputFormat.ALL;
     Path tmpDirRoot = TestStrategy.getTmpRoot(rootDirectory, outputBase, executionOptions);
     BinTools binTools = BinTools.forUnitTesting(directories, analysisMock.getEmbeddedTools());
     TestedStandaloneTestStrategy standaloneTestStrategy =
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifierTest.java b/src/test/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifierTest.java
index 4fdaa45..0def58e 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifierTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/TerminalTestResultNotifierTest.java
@@ -29,7 +29,7 @@
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
 import com.google.devtools.build.lib.exec.ExecutionOptions;
-import com.google.devtools.build.lib.exec.TestStrategy.TestSummaryFormat;
+import com.google.devtools.build.lib.exec.ExecutionOptions.TestSummaryFormat;
 import com.google.devtools.build.lib.runtime.TerminalTestResultNotifier.TestSummaryOptions;
 import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter;
 import com.google.devtools.build.lib.vfs.Path;
@@ -63,7 +63,7 @@
 
   @Test
   public void testCaseOption_allPass() throws Exception {
-    testSummaryFormat = TestSummaryFormat.TESTCASE;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE;
     numFailedTestCases = 0;
     numTotalTestCases = 10;
     targetStatus = BlazeTestStatus.PASSED;
@@ -80,7 +80,7 @@
 
   @Test
   public void testCaseOption_allPassButTargetFails() throws Exception {
-    testSummaryFormat = TestSummaryFormat.TESTCASE;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE;
     numFailedTestCases = 0;
     numUnknownTestCases = 10;
     numTotalTestCases = 10;
@@ -98,7 +98,7 @@
 
   @Test
   public void testCaseOption_someFail() throws Exception {
-    testSummaryFormat = TestSummaryFormat.TESTCASE;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE;
     numFailedTestCases = 2;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;
@@ -115,7 +115,7 @@
 
   @Test
   public void shortOption_someFailToBuild() throws Exception {
-    testSummaryFormat = TestSummaryFormat.SHORT;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.SHORT;
     numFailedTestCases = 0;
     int numFailedToBuildTestCases = TerminalTestResultNotifier.NUM_FAILED_TO_BUILD + 1;
     numUnknownTestCases = 0;
@@ -144,7 +144,7 @@
 
   @Test
   public void testCaseOption_allFail() throws Exception {
-    testSummaryFormat = TestSummaryFormat.TESTCASE;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE;
     numFailedTestCases = 10;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;
@@ -162,7 +162,7 @@
 
   @Test
   public void detailedOption_allPass() throws Exception {
-    testSummaryFormat = TestSummaryFormat.DETAILED;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED;
     numFailedTestCases = 0;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;
@@ -180,7 +180,7 @@
 
   @Test
   public void detailedOption_allPassButTargetFails() throws Exception {
-    testSummaryFormat = TestSummaryFormat.DETAILED;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED;
     numFailedTestCases = 0;
     numUnknownTestCases = 10;
     numTotalTestCases = 10;
@@ -198,7 +198,7 @@
 
   @Test
   public void detailedOption_someFail() throws Exception {
-    testSummaryFormat = TestSummaryFormat.DETAILED;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED;
     numFailedTestCases = 2;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;
@@ -215,7 +215,7 @@
 
   @Test
   public void detailedOption_allFail() throws Exception {
-    testSummaryFormat = TestSummaryFormat.DETAILED;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED;
     numFailedTestCases = 10;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;
@@ -233,7 +233,7 @@
 
   @Test
   public void shortOption_noSummaryPrinted() throws Exception {
-    testSummaryFormat = TestSummaryFormat.SHORT;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.SHORT;
     numFailedTestCases = 2;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;
@@ -246,7 +246,7 @@
 
   @Test
   public void terseOption_noSummaryPrinted() throws Exception {
-    testSummaryFormat = TestSummaryFormat.TERSE;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.TERSE;
     numFailedTestCases = 2;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;
@@ -259,7 +259,7 @@
 
   @Test
   public void noneOption_noSummaryPrinted() throws Exception {
-    testSummaryFormat = TestSummaryFormat.NONE;
+    testSummaryFormat = ExecutionOptions.TestSummaryFormat.NONE;
     numFailedTestCases = 2;
     numUnknownTestCases = 0;
     numTotalTestCases = 10;