Search in sources :

Example 46 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class AllInPackageBlazeConfigurationProducerTest method testProducedFromPsiDirectory.

@Test
public void testProducedFromPsiDirectory() {
    PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
    workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    ConfigurationContext context = createContextFromPsi(directory);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(AllInPackageBlazeConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test/...:all"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiDirectory(com.intellij.psi.PsiDirectory) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 47 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testConfigWithDifferentLabelIgnored.

@Test
public void testConfigWithDifferentLabelIgnored() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    ConfigurationContext context = createContextFromPsi(nameString);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
    // modify the label, and check that is enough for the producer to class it as different.
    config.setTarget(Label.create("//java/com/google/test:integration_tests"));
    assertThat(new BlazeBuildFileRunConfigurationProducer().isConfigurationFromContext(config, context)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeBuildFileRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 48 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeScalaSpecs2TestExprConfigurationProducerTest method testSpecs2TestProducedFromPsiClass.

@Test
public void testSpecs2TestProducedFromPsiClass() {
    PsiFile file = createTestPsiFile();
    assertThat(file).isInstanceOf(ScalaFile.class);
    ScalaFile scalaFile = (ScalaFile) file;
    PsiClass[] classes = scalaFile.getClasses();
    assertThat(classes).isNotEmpty();
    PsiClass testClass = classes[0];
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_junit_test").setLabel("//scala/com/google/test:TestClass").addSource(sourceRoot("scala/com/google/test/TestClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(testClass);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeJavaTestClassConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//scala/com/google/test:TestClass"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass#");
    assertThat(config.getName()).isEqualTo("Blaze test TestClass");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
// TODO: add tests for infix expression run configurations
// TODO: also test BlazeScalaTestEventsHandler
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ScalaFile(org.jetbrains.plugins.scala.lang.psi.api.ScalaFile) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 49 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeScalaTestClassConfigurationProducerTest method testJunitTestProducedFromPsiClass.

@Test
public void testJunitTestProducedFromPsiClass() {
    PsiFile file = createAndIndexFile(new WorkspacePath("scala/com/google/test/TestClass.scala"), "package com.google.test {", "  class TestClass {", "    @org.junit.Test", "    def testMethod() {}", "  }", "}", "package org.junit { trait Test }");
    assertThat(file).isInstanceOf(ScalaFile.class);
    ScalaFile scalaFile = (ScalaFile) file;
    PsiClass[] classes = scalaFile.getClasses();
    assertThat(classes).isNotEmpty();
    PsiClass testClass = classes[0];
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_junit_test").setLabel("//scala/com/google/test:TestClass").addSource(sourceRoot("scala/com/google/test/TestClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(testClass);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeJavaTestClassConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//scala/com/google/test:TestClass"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass#");
    assertThat(config.getName()).isEqualTo("Blaze test TestClass");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ScalaFile(org.jetbrains.plugins.scala.lang.psi.api.ScalaFile) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 50 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeScalaTestClassConfigurationProducerTest method testScalaTestProducedFromPsiClass.

@Test
public void testScalaTestProducedFromPsiClass() {
    PsiFile file = createAndIndexFile(WorkspacePath.createIfValid("scala/com/google/test/TestClass.scala"), "package com.google.test {", "  class TestClass extends org.scalatest.FlatSpec {", "    \"this test\" should \"pass\" in {}", "  }", "}", "package org.scalatest {", "  trait FlatSpec extends Suite", "  trait Suite", "}");
    assertThat(file).isInstanceOf(ScalaFile.class);
    ScalaFile scalaFile = (ScalaFile) file;
    PsiClass[] classes = scalaFile.getClasses();
    assertThat(classes).isNotEmpty();
    PsiClass testClass = classes[0];
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_test").setLabel("//scala/com/google/test:TestClass").addSource(sourceRoot("scala/com/google/test/TestClass.scala")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(testClass);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeScalaTestClassConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//scala/com/google/test:TestClass"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass");
    assertThat(config.getName()).isEqualTo("Blaze test TestClass");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ScalaFile(org.jetbrains.plugins.scala.lang.psi.api.ScalaFile) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)52 Test (org.junit.Test)36 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)33 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)29 PsiFile (com.intellij.psi.PsiFile)26 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)24 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)23 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)23 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)9 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)8 PsiClass (com.intellij.psi.PsiClass)8 PsiMethod (com.intellij.psi.PsiMethod)5 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)4 PsiDirectory (com.intellij.psi.PsiDirectory)4 Nullable (javax.annotation.Nullable)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 BlazeBuildFileRunConfigurationProducer (com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer)3 File (java.io.File)3 ScalaFile (org.jetbrains.plugins.scala.lang.psi.api.ScalaFile)3 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)2