Search in sources :

Example 71 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromTestCaseWithParametersList.

@Test
public void testProducedFromTestCaseWithParametersList() throws Throwable {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(parameterized.TestCase):", "  @parameterized.parameters([1,100])", "  def testSomething(self, value):", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
    assertThat(function).isNotNull();
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=\"UnitTest.testSomething0 UnitTest.testSomething1\"");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
    assertThat(config.getName()).isEqualTo("Blaze test UnitTest.testSomething (unittest.py)");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PyFunction(com.jetbrains.python.psi.PyFunction) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) 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 72 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromTestCaseWithEmptyParametersList.

@Test
public void testProducedFromTestCaseWithEmptyParametersList() throws Throwable {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(parameterized.TestCase):", "  @parameterized.parameters()", "  def testSomething(self, value):", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
    assertThat(function).isNotNull();
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isNull();
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
    assertThat(config.getName()).isEqualTo("Blaze test UnitTest.testSomething (unittest.py)");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PyFunction(com.jetbrains.python.psi.PyFunction) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) 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 73 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class AllInBuildFileTestContextProviderTest method testProducedFromBuildFile.

@Test
public void testProducedFromBuildFile() {
    setProjectView("directories:", "  java/com/google/test", "targets:", "  //java/com/google/test:lib");
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    ConfigurationContext context = createContextFromPsi(buildFile);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(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) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 74 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testProducedWhenInsideFuncallExpression.

@Test
public void testProducedWhenInsideFuncallExpression() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    assertThat(nameString).isNotNull();
    ConfigurationContext context = createContextFromPsi(nameString);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 75 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testProducedFromFuncallExpression.

@Test
public void testProducedFromFuncallExpression() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    FuncallExpression target = PsiUtils.findFirstChildOfClassRecursive(buildFile, FuncallExpression.class);
    assertThat(target).isNotNull();
    ConfigurationContext context = createContextFromPsi(target);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)76 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)69 Test (org.junit.Test)61 PsiFile (com.intellij.psi.PsiFile)56 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)54 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)50 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)38 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)38 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)13 PsiClass (com.intellij.psi.PsiClass)13 PsiDirectory (com.intellij.psi.PsiDirectory)10 PyFunction (com.jetbrains.python.psi.PyFunction)8 PsiElement (com.intellij.psi.PsiElement)6 TestContextRunConfigurationProducer (com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer)4 DataContext (com.intellij.openapi.actionSystem.DataContext)4 Project (com.intellij.openapi.project.Project)4 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)3 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)3 BallerinaApplicationConfiguration (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)3 BallerinaApplicationRunConfigurationProducer (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer)3