Add a supportedOs attribute to TestSpec to make it possible to split off tests that can only run under certain operating systems (e.g. Linux sandboxing tests can only run under Linux) into separate suites.
--
MOS_MIGRATED_REVID=102566414
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 6aa19f1..f267cf3 100644
--- a/src/test/java/com/google/devtools/build/lib/AllTests.java
+++ b/src/test/java/com/google/devtools/build/lib/AllTests.java
@@ -13,13 +13,22 @@
// limitations under the License.
package com.google.devtools.build.lib;
-import com.google.devtools.build.lib.testutil.ClasspathSuite;
+import com.google.devtools.build.lib.testutil.BlazeTestSuiteBuilder;
+import com.google.devtools.build.lib.testutil.CustomSuite;
import org.junit.runner.RunWith;
+import java.util.Set;
+
/**
- * Test suite for options parsing framework.
+ * General test suite with defaults suitable for most of our tests.
*/
-@RunWith(ClasspathSuite.class)
-public class AllTests {
+@RunWith(CustomSuite.class)
+public class AllTests extends BlazeTestSuiteBuilder {
+ public static Set<Class<?>> suite() {
+ return new AllTests()
+ .getBuilder()
+ .matchClasses(BlazeTestSuiteBuilder.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/BlazeTestSuiteBuilder.java
index d311c89..edb3b17 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/BlazeTestSuiteBuilder.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/BlazeTestSuiteBuilder.java
@@ -14,6 +14,8 @@
package com.google.devtools.build.lib.testutil;
import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
+import com.google.devtools.build.lib.util.OS;
import java.util.Arrays;
import java.util.HashSet;
@@ -62,6 +64,17 @@
}
};
+ /** A predicate that succeeds only if the test supports the current operating system. */
+ public static final Predicate<Class<?>> TEST_SUPPORTS_CURRENT_OS =
+ new Predicate<Class<?>>() {
+ @Override
+ public boolean apply(Class<?> testClass) {
+ ImmutableSet<OS> supportedOs = ImmutableSet.copyOf(Suite.getSupportedOs(testClass));
+ return supportedOs.isEmpty() || supportedOs.contains(OS.getCurrent());
+ }
+ };
+
+
private static Predicate<Class<?>> hasSize(final Suite size) {
return new Predicate<Class<?>>() {
@Override
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/Suite.java b/src/test/java/com/google/devtools/build/lib/testutil/Suite.java
index 8c936b6..af69bab 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/Suite.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/Suite.java
@@ -13,6 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.testutil;
+import com.google.devtools.build.lib.util.OS;
+
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -76,6 +78,13 @@
}
/**
+ * Given a class, determine the list of operating systems its tests can run under.
+ */
+ public static OS[] getSupportedOs(Class<?> clazz) {
+ return getAnnotationElementOrDefault(clazz, "supportedOs");
+ }
+
+ /**
* Returns the value of the given element in the {@link TestSpec} annotation of the given class,
* or the default value of that element if the class doesn't have a {@link TestSpec} annotation.
*/
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/TestSpec.java b/src/test/java/com/google/devtools/build/lib/testutil/TestSpec.java
index 7147904..9931d61 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/TestSpec.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/TestSpec.java
@@ -13,6 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.testutil;
+import com.google.devtools.build.lib.util.OS;
+
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
@@ -51,4 +53,10 @@
* machine.
*/
boolean localOnly() default false;
+
+ /**
+ * An array of operating systems that the test can run under. If not specified, the test can
+ * run under all operating systems.
+ */
+ OS[] supportedOs() default {};
}