Search in sources :

Example 31 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeBuildSystemServiceTest method createMocksForAddDependency.

private void createMocksForAddDependency(Container applicationServices, Container projectServices) {
    projectServices.register(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(createMockBlazeProjectData()));
    projectServices.register(FileEditorManager.class, mock(FileEditorManager.class));
    projectServices.register(BuildReferenceManager.class, mock(BuildReferenceManager.class));
    projectServices.register(LazyRangeMarkerFactory.class, mock(LazyRangeMarkerFactoryImpl.class));
    applicationServices.register(VirtualFileSystemProvider.class, new MockVirtualFileSystemProvider("/foo/BUILD"));
    AndroidResourceModuleRegistry moduleRegistry = new AndroidResourceModuleRegistry();
    moduleRegistry.put(module, AndroidResourceModule.builder(TargetKey.forPlainTarget(Label.create("//foo:bar"))).build());
    projectServices.register(AndroidResourceModuleRegistry.class, moduleRegistry);
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) BuildReferenceManager(com.google.idea.blaze.base.lang.buildfile.references.BuildReferenceManager) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) LazyRangeMarkerFactoryImpl(com.intellij.openapi.editor.impl.LazyRangeMarkerFactoryImpl)

Example 32 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazeKotlinRunConfigureProducerTest method testMainClassInterpretedCorrectly.

@Test
public void testMainClassInterpretedCorrectly() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("kt_jvm_binary").setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.Main")).setLabel("//com/google/binary:just_main").addSource(sourceRoot("com/google/binary/JustMain.kt")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiFile justMainFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/JustMain.kt"), "@file:JvmName(\"Main\")", "package com.google.binary", "fun main(args: Array<String>) {}");
    RunConfiguration justMainRunConfig = createConfigurationFromLocation(justMainFile);
    assertThat(justMainRunConfig).isInstanceOf(BlazeRunConfiguration.class);
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeRunConfiguration(com.google.idea.blaze.base.run.BlazeRunConfiguration) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Test(org.junit.Test)

Example 33 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromTestCase.

@Test
public void testProducedFromTestCase() {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(googletest.TestCase):", "  def testSomething():", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
    assertThat(function).isNotNull();
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazePyTestConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=UnitTest.testSomething");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PyFunction(com.jetbrains.python.psi.PyFunction) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 34 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromPyClass.

@Test
public void testProducedFromPyClass() {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(googletest.TestCase):", "  def testSomething():", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PyClass pyClass = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyClass.class);
    assertThat(pyClass).isNotNull();
    ConfigurationContext context = createContextFromPsi(pyClass);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazePyTestConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=UnitTest");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PyClass(com.jetbrains.python.psi.PyClass) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 35 with MockBlazeProjectDataManager

use of com.google.idea.blaze.base.model.MockBlazeProjectDataManager in project intellij by bazelbuild.

the class PyImportResolverStrategyTestCase method doSetup.

@Before
public final void doSetup() {
    BlazeProjectDataManager mockProjectDataManager = new MockBlazeProjectDataManager(MockBlazeProjectDataBuilder.builder(workspaceRoot).setOutputBase(fileSystem.getRootDir()).build());
    registerProjectService(BlazeProjectDataManager.class, mockProjectDataManager);
}
Also used : MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) Before(org.junit.Before)

Aggregations

MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)68 Test (org.junit.Test)48 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)43 PsiFile (com.intellij.psi.PsiFile)37 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)34 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)27 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)23 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)21 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)14 Before (org.junit.Before)14 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)13 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)10 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)9 BlazeRunConfiguration (com.google.idea.blaze.base.run.BlazeRunConfiguration)8 PsiClass (com.intellij.psi.PsiClass)7 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)6 WorkspacePathResolverImpl (com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl)5 PsiDirectory (com.intellij.psi.PsiDirectory)5 GoFile (com.goide.psi.GoFile)4 EditorTestHelper (com.google.idea.blaze.base.EditorTestHelper)4