use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.
the class BlazeScalaSpecs2TestExprConfigurationProducer method testLocation.
@Nullable
private static TestLocation testLocation(ConfigurationContext context) {
// Handled by SM runner.
if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
return null;
}
ScInfixExpr testCase = Specs2Utils.getContainingTestExprOrScope(context.getPsiLocation());
if (testCase == null) {
return null;
}
ScTypeDefinition testClass = PsiTreeUtil.getParentOfType(testCase, ScTypeDefinition.class);
if (testClass == null) {
return null;
}
TestSize testSize = TestSizeAnnotationMap.getTestSize(testClass);
TargetInfo target = RunUtil.targetForTestClass(testClass, testSize);
if (target == null) {
return null;
}
return new TestLocation(target, testClass, testCase);
}
use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducer method getSingleJUnitTestClass.
/**
* Returns the {@link TestLocation} corresponding to the single selected JUnit test class, or
* {@code null} if something else is selected.
*/
@Nullable
private TestLocation getSingleJUnitTestClass(ConfigurationContext context) {
Location<?> location = context.getLocation();
if (location == null) {
return null;
}
location = JavaExecutionUtil.stepIntoSingleClass(location);
if (location == null) {
return null;
}
// check for contexts handled by a different producer
if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
return null;
}
if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
return null;
}
if (JavaTestCaseIdentifier.isAnyTestCase(context)) {
return null;
}
PsiClass testClass = JUnitUtil.getTestClass(location);
if (testClass == null || testClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return null;
}
TestSize testSize = TestSizeAnnotationMap.getTestSize(testClass);
TargetInfo target = RunUtil.targetForTestClass(testClass, testSize);
return target != null ? new TestLocation(testClass, target) : null;
}
use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducer method testTargetForClass.
@Nullable
private static TargetInfo testTargetForClass(PsiClass psiClass) {
PsiClass testClass = JUnitUtil.getTestClass(psiClass);
if (testClass == null || testClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return null;
}
TestSize testSize = TestSizeAnnotationMap.getTestSize(psiClass);
return RunUtil.targetForTestClass(psiClass, testSize);
}
use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.
the class TestSizeAnnotationMap method getTestSize.
@Nullable
private static TestSize getTestSize(PsiAnnotation[] annotations) {
for (PsiAnnotation annotation : annotations) {
String qualifiedName = annotation.getQualifiedName();
TestSize testSize = ANNOTATION_TO_TEST_SIZE.get(qualifiedName);
if (testSize != null) {
return testSize;
}
}
return null;
}
use of com.google.idea.blaze.base.dependencies.TestSize in project intellij by bazelbuild.
the class BlazeJavaAbstractTestCaseConfigurationProducer method setupContext.
private static void setupContext(BlazeCommandRunConfiguration configuration, PsiClass subClass, @Nullable PsiMethod method) {
TestSize testSize = method != null ? TestSizeAnnotationMap.getTestSize(method) : TestSizeAnnotationMap.getTestSize(subClass);
TargetInfo target = RunUtil.targetForTestClass(subClass, testSize);
if (target == null) {
return;
}
configuration.setTargetInfo(target);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return;
}
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
// remove old test filter flag if present
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
String testFilter = BlazeJUnitTestFilterFlags.testFilterForClassAndMethods(subClass, method == null ? ImmutableList.of() : ImmutableList.of(method));
if (testFilter == null) {
return;
}
flags.add(BlazeFlags.TEST_FILTER + "=" + testFilter);
handlerState.getBlazeFlagsState().setRawFlags(flags);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(configName(subClass, method));
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
}
Aggregations