Search in sources :

Example 11 with MockBlazeProjectDataBuilder

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

the class BlazeKotlinRunConfigureProducerTest method testMainMethodIsRunnable.

@Test
public void testMainMethodIsRunnable() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("kt_jvm_binary").setJavaInfo(JavaIdeInfo.builder().setMainClass("com.google.binary.MainKt")).setLabel("//com/google/binary:main_kt").addSource(sourceRoot("com/google/binary/Main.kt")).build()).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 kotlinFile = createAndIndexFile(WorkspacePath.createIfValid("com/google/binary/Main.kt"), "package com.google.binary", "fun main(args: Array<String>) {}");
    RunConfiguration config = createConfigurationFromLocation(kotlinFile);
    assertThat(config).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 12 with MockBlazeProjectDataBuilder

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

the class BazelPyImportResolverStrategyTest method testImportQuickFix.

@Test
public void testImportQuickFix() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//foo:foo").setBuildFile(source("foo/BUILD")).setKind("py_library").addSource(source("foo/lib/bar.py"))).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    workspace.createPsiFile(WorkspacePath.createIfValid("foo/lib/bar.py"));
    PsiFile source = workspace.createPsiFile(WorkspacePath.createIfValid("baz/source.py"), "bar");
    PyReferenceExpression ref = PsiUtils.findFirstChildOfClassRecursive(source, PyReferenceExpression.class);
    assertThat(ref).isNotNull();
    AutoImportQuickFix quickFix = getImportQuickFix(ref);
    assertThat(quickFix.isAvailable()).isTrue();
    assertThat(quickFix.getText()).isEqualTo("Import 'foo.lib.bar'");
    quickFix.applyFix();
    assertThat(source.getText()).isEqualTo(Joiner.on('\n').join("from foo.lib import bar", "", "bar"));
}
Also used : MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression) AutoImportQuickFix(com.jetbrains.python.codeInsight.imports.AutoImportQuickFix) Test(org.junit.Test)

Example 13 with MockBlazeProjectDataBuilder

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

the class BlazePyBinaryConfigurationProducerTest method testProducedFromPyFile.

@Test
public void testProducedFromPyFile() {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/bin/main.py"), "def main():", "  return", "if __name__ == '__main__':", "  main()");
    workspace.createFile(new WorkspacePath("py/bin/BUILD"), "py_binary(name = 'main')");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_binary").setLabel("//py/bin:main").addSource(sourceRoot("py/bin/main.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(pyFile);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazePyBinaryConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//py/bin:main"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) 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 14 with MockBlazeProjectDataBuilder

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

the class BlazePyTestConfigurationProducerTest method testProducedFromPyFile.

@Test
public void testProducedFromPyFile() {
    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()));
    ConfigurationContext context = createContextFromPsi(pyFile);
    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)).isNull();
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) 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 15 with MockBlazeProjectDataBuilder

use of com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder 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);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) GoFunctionDeclaration(com.goide.psi.GoFunctionDeclaration) 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)

Aggregations

MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)42 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)42 Test (org.junit.Test)40 PsiFile (com.intellij.psi.PsiFile)37 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)27 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)26 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)23 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)21 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)10 BlazeRunConfiguration (com.google.idea.blaze.base.run.BlazeRunConfiguration)8 PsiClass (com.intellij.psi.PsiClass)7 PsiDirectory (com.intellij.psi.PsiDirectory)4 ScalaFile (org.jetbrains.plugins.scala.lang.psi.api.ScalaFile)3 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)2 PsiMethod (com.intellij.psi.PsiMethod)2 GoFunctionDeclaration (com.goide.psi.GoFunctionDeclaration)1 BlazeCommandRunConfigurationHandlerProvider (com.google.idea.blaze.base.run.confighandler.BlazeCommandRunConfigurationHandlerProvider)1 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)1 AutoImportQuickFix (com.jetbrains.python.codeInsight.imports.AutoImportQuickFix)1 PyClass (com.jetbrains.python.psi.PyClass)1