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);
}
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();
}
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();
}
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);
}
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);
}
Aggregations