Skip to content

Commit

Permalink
Add a supportedOs attribute to TestSpec to make it possible to split …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
philwo authored and damienmg committed Sep 8, 2015
1 parent fcf34fd commit a86c9a2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/test/java/com/google/devtools/build/lib/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +64,17 @@ public boolean apply(Class<?> testClass) {
}
};

/** 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -75,6 +77,13 @@ public static boolean isLocalOnly(Class<?> clazz) {
return getAnnotationElementOrDefault(clazz, "localOnly");
}

/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {};
}

0 comments on commit a86c9a2

Please sign in to comment.