Search in sources :

Example 1 with TestSize

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);
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ScInfixExpr(org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr) ScTypeDefinition(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 2 with TestSize

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;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiClass(com.intellij.psi.PsiClass) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 3 with TestSize

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);
}
Also used : PsiClass(com.intellij.psi.PsiClass) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 4 with 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;
}
Also used : PsiAnnotation(com.intellij.psi.PsiAnnotation) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 5 with TestSize

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);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArrayList(java.util.ArrayList) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder) TestSize(com.google.idea.blaze.base.dependencies.TestSize)

Aggregations

TestSize (com.google.idea.blaze.base.dependencies.TestSize)9 Nullable (javax.annotation.Nullable)7 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)4 PsiAnnotation (com.intellij.psi.PsiAnnotation)3 PsiClass (com.intellij.psi.PsiClass)3 TestIdeInfo (com.google.idea.blaze.base.ideinfo.TestIdeInfo)1 BlazeConfigurationNameBuilder (com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)1 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiModifierList (com.intellij.psi.PsiModifierList)1 ArrayList (java.util.ArrayList)1 ScInfixExpr (org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr)1 ScTypeDefinition (org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition)1