Search in sources :

Example 1 with StringLiteral

use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testProducedWhenInsideFuncallExpression.

@Test
public void testProducedWhenInsideFuncallExpression() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    assertThat(nameString).isNotNull();
    ConfigurationContext context = createContextFromPsi(nameString);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 2 with StringLiteral

use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testConfigWithTestFilterIgnored.

@Test
public void testConfigWithTestFilterIgnored() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    ConfigurationContext context = createContextFromPsi(nameString);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
    BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    handlerState.getBlazeFlagsState().setRawFlags(ImmutableList.of(BlazeFlags.TEST_FILTER + "=com.google.test.SingleTestClass#"));
    assertThat(new BlazeBuildFileRunConfigurationProducer().isConfigurationFromContext(config, context)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeBuildFileRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 3 with StringLiteral

use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.

the class BlazeBuildFileRunConfigurationProducerTest method testConfigFromContextRecognizesItsOwnConfig.

@Test
public void testConfigFromContextRecognizesItsOwnConfig() {
    PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
    StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
    ConfigurationContext context = createContextFromPsi(nameString);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
    assertThat(new BlazeBuildFileRunConfigurationProducer().isConfigurationFromContext(config, context)).isTrue();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeBuildFileRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 4 with StringLiteral

use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.

the class PackageReferenceTest method testLabelFragmentResolves.

@Test
public void testLabelFragmentResolves() {
    BuildFile buildFile1 = createBuildFile(new WorkspacePath("java/com/google/tools/BUILD"), "java_library(name = \"lib\")");
    BuildFile buildFile2 = createBuildFile(new WorkspacePath("java/com/google/other/BUILD"), "java_library(name = \"lib2\", exports = [\"//java/com/google/tools:lib\"])");
    FuncallExpression libTarget = buildFile1.firstChildOfClass(FuncallExpression.class);
    assertThat(libTarget).isNotNull();
    Argument.Keyword packagesArg = buildFile2.firstChildOfClass(FuncallExpression.class).getArgList().getKeywordArgument("exports");
    StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(packagesArg, StringLiteral.class);
    PsiReference[] references = string.getReferences();
    assertThat(Arrays.stream(references).map(PsiReference::resolve).collect(Collectors.toList())).containsAllOf(libTarget, buildFile1);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) PsiReference(com.intellij.psi.PsiReference) FuncallExpression(com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression) Test(org.junit.Test)

Example 5 with StringLiteral

use of com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral in project intellij by bazelbuild.

the class PackageReferenceTest method testDirectReferenceResolves.

@Test
public void testDirectReferenceResolves() {
    BuildFile buildFile1 = createBuildFile(new WorkspacePath("java/com/google/tools/BUILD"), "# contents");
    BuildFile buildFile2 = createBuildFile(new WorkspacePath("java/com/google/other/BUILD"), "package_group(name = \"grp\", packages = [\"//java/com/google/tools\"])");
    Argument.Keyword packagesArg = buildFile2.firstChildOfClass(FuncallExpression.class).getArgList().getKeywordArgument("packages");
    StringLiteral string = PsiUtils.findFirstChildOfClassRecursive(packagesArg, StringLiteral.class);
    assertThat(string.getReferencedElement()).isEqualTo(buildFile1);
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Argument(com.google.idea.blaze.base.lang.buildfile.psi.Argument) StringLiteral(com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral) Test(org.junit.Test)

Aggregations

StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)24 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)20 Test (org.junit.Test)20 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)17 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)11 PsiFile (com.intellij.psi.PsiFile)7 Argument (com.google.idea.blaze.base.lang.buildfile.psi.Argument)5 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)4 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)4 PsiReference (com.intellij.psi.PsiReference)4 BlazeBuildFileRunConfigurationProducer (com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer)3 PsiElement (com.intellij.psi.PsiElement)3 FunctionStatement (com.google.idea.blaze.base.lang.buildfile.psi.FunctionStatement)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 BuildFileIntegrationTestCase (com.google.idea.blaze.base.lang.buildfile.BuildFileIntegrationTestCase)1 Keyword (com.google.idea.blaze.base.lang.buildfile.psi.Argument.Keyword)1 ArgumentList (com.google.idea.blaze.base.lang.buildfile.psi.ArgumentList)1 Expression (com.google.idea.blaze.base.lang.buildfile.psi.Expression)1 GlobExpression (com.google.idea.blaze.base.lang.buildfile.psi.GlobExpression)1 ListLiteral (com.google.idea.blaze.base.lang.buildfile.psi.ListLiteral)1