Search in sources :

Example 66 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestSizeHeuristicTest method testFilterOneMatch.

@Test
public void testFilterOneMatch() throws Exception {
    File source = new File("java/com/foo/FooTest.java");
    ImmutableList<TargetInfo> rules = ImmutableList.of(TargetIdeInfo.builder().setLabel("//foo:test1").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.MEDIUM)).build().toTargetInfo(), TargetIdeInfo.builder().setLabel("//foo:test2").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.SMALL)).build().toTargetInfo());
    TargetInfo match = TestTargetHeuristic.chooseTestTargetForSourceFile(project, null, source, rules, TestSize.SMALL);
    assertThat(match.label).isEqualTo(Label.create("//foo:test2"));
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 67 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestTargetSourcesHeuristicTest method testPredicateMatchingSource.

@Test
public void testPredicateMatchingSource() {
    File source = workspaceRoot.fileForPath(new WorkspacePath("java/com/foo/FooTest.java"));
    TargetInfo target = TargetIdeInfo.builder().setLabel("//foo:test").setKind("java_test").addSource(sourceRoot("java/com/bar/OtherTest.java")).addSource(sourceRoot("java/com/foo/FooTest.java")).build().toTargetInfo();
    assertThat(new TestTargetSourcesHeuristic().matchesSource(project, target, null, source, null)).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 68 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestMapTest method testTrivialTestMap.

@Test
public void testTrivialTestMap() throws Exception {
    mockBlazeProjectDataManager.targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test").setKind("java_test").addSource(sourceRoot("test/Test.java"))).build();
    Collection<TargetInfo> targets = SourceToTargetFinder.findTargetsForSourceFile(project, new File("/test/Test.java"), Optional.of(RuleType.TEST));
    assertThat(targets.stream().map(t -> t.label).collect(Collectors.toList())).containsExactly(Label.create("//test:test"));
}
Also used : RuleType(com.google.idea.blaze.base.model.primitives.RuleType) SourceToTargetFinder(com.google.idea.blaze.base.run.SourceToTargetFinder) RunWith(org.junit.runner.RunWith) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ReverseDependencyMap(com.google.idea.blaze.base.targetmaps.ReverseDependencyMap) Nullable(javax.annotation.Nullable) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) Collection(java.util.Collection) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) SyncCache(com.google.idea.blaze.base.sync.SyncCache) ExtensionPointImpl(com.intellij.openapi.extensions.impl.ExtensionPointImpl) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 69 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestMapTest method testBfsPreferred.

@Test
public void testBfsPreferred() throws Exception {
    mockBlazeProjectDataManager.targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib").setKind("java_library").addSource(sourceRoot("test/Test.java"))).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib2").setKind("java_library").addDependency("//test:lib")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test2").setKind("java_test").addDependency("//test:lib2")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test").setKind("java_test").addDependency("//test:lib")).build();
    Collection<TargetInfo> targets = SourceToTargetFinder.findTargetsForSourceFile(project, new File("/test/Test.java"), Optional.of(RuleType.TEST));
    assertThat(targets.stream().map(t -> t.label).collect(Collectors.toList())).containsExactly(Label.create("//test:test"), Label.create("//test:test2")).inOrder();
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Aggregations

TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)69 File (java.io.File)43 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)19 PsiFile (com.intellij.psi.PsiFile)18 Nullable (javax.annotation.Nullable)15 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)14 PsiElement (com.intellij.psi.PsiElement)9 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)7 Label (com.google.idea.blaze.base.model.primitives.Label)7 PsiClass (com.intellij.psi.PsiClass)7 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 RuleType (com.google.idea.blaze.base.model.primitives.RuleType)6 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5