use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeClassJarProviderIntegrationTest method doSetup.
@Before
public void doSetup() {
module = testFixture.getModule();
ArtifactLocationDecoder decoder = (location) -> new File("/src", location.getExecutionRootRelativePath());
BlazeProjectData blazeProjectData = MockBlazeProjectDataBuilder.builder(workspaceRoot).setTargetMap(buildTargetMap()).setArtifactLocationDecoder(decoder).build();
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(blazeProjectData));
classJarProvider = new BlazeClassJarProvider(getProject());
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeGoRootsProviderTest method testPackageToTargetMap.
@Test
public void testPackageToTargetMap() {
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")).addSource(src("one/two/three/library.go")).setGoInfo(GoIdeInfo.builder().addSources(ImmutableList.of(src("one/two/library.go"), src("one/two/three/library.go"))).setImportPath("prefix/one/two/library"))).build();
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(new BlazeProjectData(0L, targetMap, null, null, null, null, new WorkspaceLanguageSettings(WorkspaceType.GO, ImmutableSet.of(LanguageClass.GO)), null, null)));
assertThat(BlazeGoRootsProvider.getPackageToTargetMap(getProject())).containsExactly("prefix/foo/bar/binary", TargetKey.forPlainTarget(Label.create("//foo/bar:binary")), "prefix/one/two/library", TargetKey.forPlainTarget(Label.create("//one/two:library")));
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeGoTestConfigurationProducerTest method testProducedFromTestCase.
@Test
public void testProducedFromTestCase() {
PsiFile goFile = createAndIndexFile(new WorkspacePath("foo/bar/foo_test.go"), "package foo", "import \"testing\"", "func TestFoo(t *testing.T) {}");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("go_test").setLabel("//foo/bar:foo_test").addSource(sourceRoot("foo/bar/foo_test.go")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
List<GoFunctionDeclaration> functions = PsiUtils.findAllChildrenOfClassRecursive(goFile, GoFunctionDeclaration.class);
assertThat(functions).hasSize(1);
GoFunctionDeclaration function = functions.get(0);
ConfigurationContext context = createContextFromPsi(function);
List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
assertThat(configurations).isNotNull();
assertThat(configurations).hasSize(1);
ConfigurationFromContext fromContext = configurations.get(0);
assertThat(fromContext.isProducedBy(BlazeGoTestConfigurationProducer.class)).isTrue();
assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//foo/bar:foo_test"));
assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=^TestFoo$");
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeScalaMainClassConfigurationProducerTest method testNoResultForObjectWithoutMainMethod.
@Test
public void testNoResultForObjectWithoutMainMethod() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/MainClass.scala")).setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.MainClass")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary { object MainClass {} }", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
assertThat(createConfigurationFromLocation(scalaFile)).isNull();
}
use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.
the class BlazeScalaMainClassConfigurationProducerTest method testScalaBinaryWithMatchingNameChosen.
@Test
public void testScalaBinaryWithMatchingNameChosen() {
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:UnrelatedName").addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).addTarget(TargetIdeInfo.builder().setKind("scala_binary").setLabel("//com/google/binary:MainClass").addSource(sourceRoot("com/google/binary/MainClass.scala")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
PsiFile scalaFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/MainClass.scala"), "package com.google.binary {", " object MainClass {", " def main(args: Array[String]) {}", " }", "}", "package scala { final class Array[T] {} }", "package java.lang { public final class String {} }");
RunConfiguration config = createConfigurationFromLocation(scalaFile);
assertThat(config).isInstanceOf(BlazeRunConfiguration.class);
BlazeRunConfiguration blazeConfig = (BlazeRunConfiguration) config;
assertThat(blazeConfig).isNotNull();
assertThat(blazeConfig.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//com/google/binary:MainClass"));
}
Aggregations