Search in sources :

Example 16 with ConfigurationFromContext

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

the class BlazeGoTestConfigurationProducerTest method testProducedFromTestCase.

@Test
public void testProducedFromTestCase() throws Throwable {
    PsiFile goFile = createAndIndexFile(new WorkspacePath("foo/bar/foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("go_test").setLabel("//foo/bar:foo_test").addSource(sourceRoot("foo/bar/foo_test.go")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    List<GoFunctionDeclaration> functions = PsiUtils.findAllChildrenOfClassRecursive(goFile, GoFunctionDeclaration.class);
    assertThat(functions).hasSize(1);
    GoFunctionDeclaration function = functions.get(0);
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    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("//foo/bar:foo_test"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=^TestFoo$");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GoFunctionDeclaration(com.goide.psi.GoFunctionDeclaration) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) 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 17 with ConfigurationFromContext

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

the class GoBinaryContextProviderTest method contextProducedFromLibraryGoFileIsBinaryTarget.

@Test
public void contextProducedFromLibraryGoFileIsBinaryTarget() throws Throwable {
    PsiFile goFile = createAndIndexFile(new WorkspacePath("foo/bar/main.go"), "package main", "func main() {}");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("go_library").setLabel("//foo/bar:library").addSource(sourceRoot("foo/bar/main.go"))).addTarget(TargetIdeInfo.builder().setKind("go_binary").setLabel("//foo/bar:main").addDependency("//foo/bar:library")).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(goFile);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BinaryContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//foo/bar:main"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) 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 18 with ConfigurationFromContext

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

the class GoBinaryContextProviderTest method contextProducedFromBinaryGoFileIsBinaryTarget.

@Test
public void contextProducedFromBinaryGoFileIsBinaryTarget() throws Throwable {
    PsiFile goFile = createAndIndexFile(new WorkspacePath("foo/bar/main.go"), "package main", "func main() {}");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("go_binary").setLabel("//foo/bar:main").addSource(sourceRoot("foo/bar/main.go"))).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(goFile);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).isNotNull();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BinaryContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//foo/bar:main"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) 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 19 with ConfigurationFromContext

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

the class MultipleJavaClassesTestContextProviderTest method testNotProducedForDirectoryNotUnderTestRoots.

@Test
public void testNotProducedForDirectoryNotUnderTestRoots() throws Throwable {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/other:TestClass").addSource(sourceRoot("java/com/google/other/TestClass.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java"));
    createAndIndexFile(new WorkspacePath("java/com/google/other/TestClass.java"), "package com.google.other;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass {", "  @org.junit.Test", "  public void testMethod() {}", "}");
    ConfigurationContext context = createContextFromPsi(directory);
    ConfigurationFromContext fromContext = new TestContextRunConfigurationProducer().createConfigurationFromContext(context);
    assertThat(fromContext).isNotNull();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/...:all"));
    assertThat(getTestFilterContents(config)).isNull();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiDirectory(com.intellij.psi.PsiDirectory) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 20 with ConfigurationFromContext

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

the class MultipleJavaClassesTestContextProviderTest method testProducedFromTestFiles.

@Test
public void testProducedFromTestFiles() throws Throwable {
    // GIVEN two test classes
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:allTests").addSource(sourceRoot("java/com/google/test/TestClass1.java")).addSource(sourceRoot("java/com/google/test/TestClass2.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
    PsiFile testClass1 = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass1.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass1 {", "  @org.junit.Test", "  public void testMethod() {}", "}");
    PsiFile testClass2 = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass2.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass2 {", "  @org.junit.Test", "  public void testMethod() {}", "}");
    // WHEN generating a BlazeCommandRunConfiguration
    ConfigurationContext context = createContextFromMultipleElements(new PsiElement[] { testClass1, testClass2 });
    ConfigurationFromContext fromContext = new TestContextRunConfigurationProducer().createConfigurationFromContext(context);
    assertThat(fromContext).isNotNull();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    // THEN expect config to be correct
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:allTests"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=\"com.google.test.TestClass1#|com.google.test.TestClass2#\"");
    assertThat(config.getName()).isEqualTo("Blaze test TestClass1 and 1 others");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) 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)

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