use of com.carrotsearch.randomizedtesting.FilterExpressionParser.IContext in project randomizedtesting by randomizedtesting.
the class TestFilterExpressionParser method testFalseExpressions.
@Test
public void testFalseExpressions() {
// {groups}, {rules}
Deque<String[]> examples = new ArrayDeque<String[]>(Arrays.asList(new String[][] { {}, { "@foo", "default" }, { "@nightly" }, { "not @nightly", "@nightly and @foo" }, { "@nightly", "@slow" }, { "not(@nightly or @slow)" } }));
while (!examples.isEmpty()) {
final List<String> groups = Arrays.asList((String[]) examples.pop());
IContext context = new IContext() {
@Override
public boolean defaultValue() {
return hasGroup("default");
}
@Override
public boolean hasGroup(String value) {
return groups.contains(value);
}
};
for (String rule : examples.pop()) {
Assertions.assertThat(new FilterExpressionParser().parse(rule).evaluate(context)).as("ctx=" + groups + ", rule=" + rule).isEqualTo(false);
}
}
}
use of com.carrotsearch.randomizedtesting.FilterExpressionParser.IContext in project randomizedtesting by randomizedtesting.
the class TestFilterExpressionParser method testTrueExpressions.
@Test
public void testTrueExpressions() {
// {groups}, {rules}
Deque<String[]> examples = new ArrayDeque<String[]>(Arrays.asList(new String[][] { {}, { "not @foo", "not default" }, { "@nightly" }, { "@nightly", "@nightly or @foo", "@foo or @nightly", "not not @nightly" }, { "@nightly", "@slow" }, { "@nightly and @slow", "@nightly and not @foo", "not @nightly or @slow" }, { "default" }, { "", "default" } }));
while (!examples.isEmpty()) {
final List<String> groups = Arrays.asList((String[]) examples.pop());
IContext context = new IContext() {
@Override
public boolean defaultValue() {
return hasGroup("default");
}
@Override
public boolean hasGroup(String value) {
return groups.contains(value);
}
};
for (String rule : examples.pop()) {
Assertions.assertThat(new FilterExpressionParser().parse(rule).evaluate(context)).as("ctx=" + groups + ", rule=" + rule).isEqualTo(true);
}
}
}
use of com.carrotsearch.randomizedtesting.FilterExpressionParser.IContext in project randomizedtesting by randomizedtesting.
the class GroupEvaluator method getIgnoreReason.
/**
* @return Returns a non-null string with the reason why the annotated element (class, test or test-class pair)
* should be ignored in the execution. This is an expert-level method, typically tests
* shouldn't be concerned with this.
*/
public String getIgnoreReason(AnnotatedElement... elements) {
final Map<String, Annotation> annotations = new HashMap<String, Annotation>();
for (AnnotatedElement element : elements) {
for (Annotation ann : element.getAnnotations()) {
Class<? extends Annotation> annType = ann.annotationType();
if (annType.isAnnotationPresent(TestGroup.class)) {
if (!testGroups.containsKey(annType)) {
testGroups.put(annType, new TestGroupInfo(annType));
}
annotations.put(testGroups.get(annType).name, ann);
}
}
}
String defaultState = null;
for (Annotation ann : annotations.values()) {
TestGroupInfo g = testGroups.get(ann.annotationType());
if (!g.enabled) {
defaultState = "'" + g.name + "' test group is disabled (" + toString(ann) + ")";
break;
}
}
if (hasFilteringExpression()) {
final String defaultStateCopy = defaultState;
boolean enabled = filter.evaluate(new IContext() {
@Override
public boolean defaultValue() {
return defaultStateCopy == null;
}
@Override
public boolean hasGroup(String value) {
if (value.startsWith("@"))
value = value.substring(1);
for (Annotation ann : annotations.values()) {
if (value.equalsIgnoreCase(testGroups.get(ann.annotationType()).name)) {
return true;
}
}
return false;
}
});
return enabled ? null : "Test filter condition: " + filterExpression;
} else {
return defaultState;
}
}
Aggregations