use of com.intellij.execution.actions.ConfigurationFromContext 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
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class BlazeGoBinaryConfigurationProducerTest method testProducedFromGoFile.
@Test
public void testProducedFromGoFile() {
PsiFile goFile = createAndIndexFile(new WorkspacePath("foo/bar/main.go"), "package main", "func main() {}");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("go_binary").setLabel("//foo/bar:main").addSource(sourceRoot("foo/bar/main.go")).build()).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(BlazeGoBinaryConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//foo/bar:main"));
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class AllInDirectoryRecursiveTestContextProviderTest method testProducedFromDirectoryWithBuildFile.
@Test
public void testProducedFromDirectoryWithBuildFile() {
setProjectView("directories:", " java/com/google/test", "targets:", " //java/com/google/test:lib");
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).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("//java/com/google/test/...:all"));
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class AllInDirectoryRecursiveTestContextProviderTest method testProducedFromDirectoryWithoutBuildFile.
@Test
public void testProducedFromDirectoryWithoutBuildFile() {
setProjectView("directories:", " java/com/google/test");
PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
ConfigurationContext context = createContextFromPsi(directory);
TestContextRunConfigurationProducer producer = new TestContextRunConfigurationProducer();
ConfigurationFromContext fromContext = producer.createConfigurationFromContext(context);
assertThat(fromContext).isNotNull();
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test/...:all"));
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class KotlinTestContextProviderTest method getRunConfigurations.
private ImmutableList<RunConfiguration> getRunConfigurations(PsiElement psiElement) {
// Create the necessary context data we need to request run configurations.
ConfigurationContext context = createContextFromPsi(psiElement);
// Request the run configurations from IntelliJ's API. This eventually calls into the extension
// points we use to provide our custom run configurations.
List<ConfigurationFromContext> configurationsFromContext = Optional.ofNullable(context.getConfigurationsFromContext()).orElse(ImmutableList.of());
// additional data) as we're only interested in the run configurations in the tests.
return configurationsFromContext.stream().map(ConfigurationFromContext::getConfiguration).collect(toImmutableList());
}
Aggregations