use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager 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.google.idea.blaze.base.model.MockBlazeProjectDataManager 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 com.google.idea.blaze.base.model.MockBlazeProjectDataManager 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);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeCppAutoImportHelperTest method resolve.
private void resolve(ProjectView projectView, TargetMap targetMap, OCFile... files) {
BlazeProjectData blazeProjectData = projectDataBuilder().setTargetMap(targetMap).build();
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(blazeProjectData));
BlazeCWorkspace.getInstance(getProject()).update(new BlazeContext(), workspaceRoot, ProjectViewSet.builder().add(projectView).build(), blazeProjectData);
for (OCFile file : files) {
resetFileSymbols(file);
}
FileSymbolTablesCache.getInstance(getProject()).ensurePendingFilesProcessed();
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeGoGotoDeclarationHandlerTest method testResolveGoDirectories.
@Test
public void testResolveGoDirectories() {
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(src("foo/bar/BUILD")).setLabel("//foo/bar:binary").setKind("go_binary").addSource(src("foo/bar/binary.go")).addDependency("//one/two:library").setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/binary.go"))).setImportPath("prefix/foo/bar/binary"))).addTarget(TargetIdeInfo.builder().setBuildFile(src("one/two/BUILD")).setLabel("//one/two:library").setKind("go_library").addSource(src("one/two/library.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("one/two/library.go"))).setImportPath("prefix/one/two/library"))).build();
BlazeProjectData projectData = new BlazeProjectData(0L, targetMap, null, null, new WorkspacePathResolverImpl(workspaceRoot), location -> workspaceRoot.fileForPath(new WorkspacePath(location.getRelativePath())), new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null);
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(projectData));
GoFile fooBarBinary = (GoFile) workspace.createPsiFile(new WorkspacePath("foo/bar/binary.go"), "package main", "import \"p<caret>refix/one<caret>/<caret>two/lib<caret>rary\"", "func foo(a library.One<caret>Two) {}", "func main() {}");
GoFile oneTwoLibrary = (GoFile) workspace.createPsiFile(new WorkspacePath("one/two/library.go"), "package library", "type OneTwo struct {}");
GoTypeSpec oneTwoStruct = PsiTreeUtil.findChildOfType(oneTwoLibrary, GoTypeSpec.class);
PsiDirectory oneTwoDirectory = oneTwoLibrary.getParent();
assertThat(oneTwoDirectory).isNotNull();
PsiDirectory oneDirectory = oneTwoDirectory.getParent();
assertThat(oneDirectory).isNotNull();
BuildFile oneTwoBUILD = (BuildFile) workspace.createPsiFile(new WorkspacePath("one/two/BUILD"), "go_library(", " name = 'library',", " srcs = ['library.go'],", ")");
FuncallExpression oneTwoLibraryRule = PsiUtils.findFirstChildOfClassRecursive(oneTwoBUILD, FuncallExpression.class);
BlazeGoRootsProvider.createGoPathSourceRoot(getProject(), projectData);
testFixture.configureFromExistingVirtualFile(fooBarBinary.getVirtualFile());
List<Caret> carets = testFixture.getEditor().getCaretModel().getAllCarets();
assertThat(carets).hasSize(5);
PsiElement gotoPrefix = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(0).getOffset());
assertThat(gotoPrefix).isEqualTo(oneTwoLibraryRule);
PsiElement gotoOne = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(1).getOffset());
assertThat(gotoOne).isEqualTo(oneDirectory);
PsiElement gotoTwo = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(2).getOffset());
assertThat(gotoTwo).isEqualTo(oneTwoDirectory);
PsiElement gotoLibrary = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(3).getOffset());
assertThat(gotoLibrary).isEqualTo(oneTwoLibraryRule);
PsiElement gotoOneTwoType = GotoDeclarationAction.findTargetElement(getProject(), testFixture.getEditor(), carets.get(4).getOffset());
assertThat(gotoOneTwoType).isEqualTo(oneTwoStruct);
}
Aggregations