Search in sources :

Example 76 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeGoTestEventsHandlerTest method testFunctionLocationResolves.

@Test
public void testFunctionLocationResolves() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//foo/bar:foo_test").setKind("go_test").setBuildFile(src("foo/bar/BUILD")).addSource(src("foo/bar/foo_test.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/foo_test.go"))).setImportPath("google3/foo/bar/foo"))).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(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)));
    GoFile goFile = (GoFile) workspace.createPsiFile(new WorkspacePath("foo/bar/foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
    workspace.createFile(new WorkspacePath("foo/bar/BUILD"), "go_test(", "    name = 'foo_test',", "    srcs = ['foo_test.go'],", ")");
    GoFunctionDeclaration function = PsiUtils.findFirstChildOfClassRecursive(goFile, GoFunctionDeclaration.class);
    assertThat(function).isNotNull();
    String url = handler.testLocationUrl(null, "foo/bar/foo_test", "TestFoo", null);
    Location<?> location = getLocation(url);
    assertThat(location).isNotNull();
    assertThat(location.getPsiElement()).isEqualTo(function);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GoFile(com.goide.psi.GoFile) GoFunctionDeclaration(com.goide.psi.GoFunctionDeclaration) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 77 with TargetMap

use of com.google.idea.blaze.base.ideinfo.TargetMap in project intellij by bazelbuild.

the class BlazeGoTestEventsHandlerTest method testSuiteLocationResolvesToSingleSourceFile.

@Test
public void testSuiteLocationResolvesToSingleSourceFile() {
    TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//foo/bar:foo_test").setKind("go_test").setBuildFile(src("foo/bar/BUILD")).addSource(src("foo/bar/foo_test.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("foo/bar/foo_test.go"))).setImportPath("google3/foo/bar/foo"))).build();
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(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)));
    GoFile goFile = (GoFile) workspace.createPsiFile(new WorkspacePath("foo/bar/foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
    workspace.createFile(new WorkspacePath("foo/bar/BUILD"), "go_test(", "    name = 'foo_test',", "    srcs = ['foo_test.go'],", ")");
    String url = handler.suiteLocationUrl(null, "foo/bar/foo_test");
    Location<?> location = getLocation(url);
    assertThat(location).isNotNull();
    assertThat(location.getPsiElement()).isEqualTo(goFile);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GoFile(com.goide.psi.GoFile) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Aggregations

TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)77 Test (org.junit.Test)56 ProjectView (com.google.idea.blaze.base.projectview.ProjectView)33 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)17 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)16 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)15 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)12 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)10 BlazeSyncParams (com.google.idea.blaze.base.sync.BlazeSyncParams)10 BlazeScalaImportResult (com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult)10 File (java.io.File)10 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)9 BlazeJavaImportResult (com.google.idea.blaze.java.sync.model.BlazeJavaImportResult)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)8 ImmutableSet (com.google.common.collect.ImmutableSet)7