Make bazel test suites fail without a real test, by no longer adding an empty test in the TestSuiteBuilder. 

The current scenario can be bug-prone since changes to the TestSuiteBuilder code may bypass all tests, and in the absence of test failures, our tests will signal success.

RELNOTES: Make it mandatory for Java test suites in bazel codebase, to contain at least one test.

--
PiperOrigin-RevId: 146919833
MOS_MIGRATED_REVID=146919833
diff --git a/src/test/java/com/google/devtools/build/lib/AllTests.java b/src/test/java/com/google/devtools/build/lib/AllTests.java
index 78d6cc8..d3c745d 100644
--- a/src/test/java/com/google/devtools/build/lib/AllTests.java
+++ b/src/test/java/com/google/devtools/build/lib/AllTests.java
@@ -13,7 +13,7 @@
 // limitations under the License.
 package com.google.devtools.build.lib;
 
-import com.google.devtools.build.lib.testutil.BlazeTestSuiteBuilder;
+import com.google.devtools.build.lib.testutil.BazelTestSuiteBuilder;
 import com.google.devtools.build.lib.testutil.CustomSuite;
 
 import org.junit.runner.RunWith;
@@ -24,11 +24,11 @@
  * General test suite with defaults suitable for most of our tests.
  */
 @RunWith(CustomSuite.class)
-public class AllTests extends BlazeTestSuiteBuilder {
+public class AllTests extends BazelTestSuiteBuilder {
   public static Set<Class<?>> suite() {
     return new AllTests()
         .getBuilder()
-        .matchClasses(BlazeTestSuiteBuilder.TEST_SUPPORTS_CURRENT_OS)
+        .matchClasses(BazelTestSuiteBuilder.TEST_SUPPORTS_CURRENT_OS)
         .create();
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/BlazeTestSuiteBuilder.java b/src/test/java/com/google/devtools/build/lib/testutil/BazelTestSuiteBuilder.java
similarity index 98%
rename from src/test/java/com/google/devtools/build/lib/testutil/BlazeTestSuiteBuilder.java
rename to src/test/java/com/google/devtools/build/lib/testutil/BazelTestSuiteBuilder.java
index 3c645f0..df638ff 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/BlazeTestSuiteBuilder.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/BazelTestSuiteBuilder.java
@@ -25,10 +25,10 @@
  * A base class for constructing test suites by searching the classpath for
  * tests, possibly restricted to a predicate.
  */
-public class BlazeTestSuiteBuilder {
+public class BazelTestSuiteBuilder {
 
   /**
-   * @return a TestSuiteBuilder configured for Blaze.
+   * @return a TestSuiteBuilder configured for Bazel.
    */
   protected TestSuiteBuilder getBuilder() {
     return new TestSuiteBuilder()
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestSuiteBuilder.java b/src/test/java/com/google/devtools/build/lib/testutil/TestSuiteBuilder.java
index f6588cb..59a5d85 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestSuiteBuilder.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestSuiteBuilder.java
@@ -35,6 +35,20 @@
 
   private Set<Class<?>> testClasses = Sets.newTreeSet(new TestClassNameComparator());
   private Predicate<Class<?>> matchClassPredicate = Predicates.alwaysTrue();
+  private final boolean tolerateEmptyTestSuites;
+
+  public TestSuiteBuilder() {
+    tolerateEmptyTestSuites = false;
+  }
+
+  /**
+   * @param tolerateEmptyTestSuites set this to true to add an empty test which passes to the suite.
+   *     Its better for Test Suites to fail when they create an empty set of classes to test, so new
+   *     suites should avoid setting this to true.
+   */
+  public TestSuiteBuilder(boolean tolerateEmptyTestSuites) {
+    this.tolerateEmptyTestSuites = tolerateEmptyTestSuites;
+  }
 
   /**
    * Adds the tests found (directly) in class {@code c} to the set of tests
@@ -84,7 +98,7 @@
     for (Class<?> testClass : Iterables.filter(testClasses, matchClassPredicate)) {
       result.add(testClass);
     }
-    if (result.isEmpty()) {
+    if (tolerateEmptyTestSuites && result.isEmpty()) {
       // We have some cases where the resulting test suite is empty, which some of our test
       // infrastructure treats as an error.
       result.add(TautologyTest.class);