use of org.jetbrains.plugins.scala.lang.psi.api.ScalaFile in project intellij by bazelbuild.
the class BlazeScalaMainClassRunConfigurationProducer method getMainObject.
@Nullable
private static ScObject getMainObject(ConfigurationContext context) {
Location location = context.getLocation();
if (location == null) {
return null;
}
location = JavaExecutionUtil.stepIntoSingleClass(context.getLocation());
if (location == null) {
return null;
}
PsiElement element = location.getPsiElement();
if (!(element.getContainingFile() instanceof ScalaFile)) {
return null;
}
if (!element.isPhysical()) {
return null;
}
return getMainObjectFromElement(element);
}
use of org.jetbrains.plugins.scala.lang.psi.api.ScalaFile 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 org.jetbrains.plugins.scala.lang.psi.api.ScalaFile 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);
}
use of org.jetbrains.plugins.scala.lang.psi.api.ScalaFile 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);
}
Aggregations