Search in sources :

Example 1 with SelectorValue

use of com.google.devtools.build.lib.syntax.SelectorValue in project bazel by bazelbuild.

the class BuildTypeTest method testSelectableConvert.

/**
   * Tests that {@link BuildType#selectableConvert} returns either the native type or a selector
   * on that type, in accordance with the provided input.
   */
@SuppressWarnings("unchecked")
@Test
public void testSelectableConvert() throws Exception {
    Object nativeInput = Arrays.asList("//a:a1", "//a:a2");
    Object selectableInput = SelectorList.of(new SelectorValue(ImmutableMap.of("//conditions:a", nativeInput, BuildType.Selector.DEFAULT_CONDITION_KEY, nativeInput), ""));
    List<Label> expectedLabels = ImmutableList.of(Label.create("@//a", "a1"), Label.create("@//a", "a2"));
    // Conversion to direct type:
    Object converted = BuildType.selectableConvert(BuildType.LABEL_LIST, nativeInput, null, currentRule);
    assertTrue(converted instanceof List<?>);
    assertThat((List<Label>) converted).containsExactlyElementsIn(expectedLabels);
    // Conversion to selectable type:
    converted = BuildType.selectableConvert(BuildType.LABEL_LIST, selectableInput, null, currentRule);
    BuildType.SelectorList<?> selectorList = (BuildType.SelectorList<?>) converted;
    assertThat(((Selector<Label>) selectorList.getSelectors().get(0)).getEntries().entrySet()).containsExactlyElementsIn(ImmutableMap.of(Label.parseAbsolute("//conditions:a"), expectedLabels, Label.parseAbsolute(BuildType.Selector.DEFAULT_CONDITION_KEY), expectedLabels).entrySet());
}
Also used : SelectorList(com.google.devtools.build.lib.syntax.SelectorList) Label(com.google.devtools.build.lib.cmdline.Label) SelectorValue(com.google.devtools.build.lib.syntax.SelectorValue) SelectorList(com.google.devtools.build.lib.syntax.SelectorList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Test(org.junit.Test)

Example 2 with SelectorValue

use of com.google.devtools.build.lib.syntax.SelectorValue in project bazel by bazelbuild.

the class BuildTypeTest method testConvertDoesNotAcceptSelectables.

/**
   * Tests that {@link com.google.devtools.build.lib.syntax.Type#convert} fails on selector inputs.
   */
@Test
public void testConvertDoesNotAcceptSelectables() throws Exception {
    Object selectableInput = SelectorList.of(new SelectorValue(ImmutableMap.of("//conditions:a", Arrays.asList("//a:a1", "//a:a2")), ""));
    try {
        BuildType.LABEL_LIST.convert(selectableInput, null, currentRule);
        fail("Expected conversion to fail on a selectable input");
    } catch (ConversionException e) {
        assertThat(e.getMessage()).contains("expected value of type 'list(label)'");
    }
}
Also used : ConversionException(com.google.devtools.build.lib.syntax.Type.ConversionException) SelectorValue(com.google.devtools.build.lib.syntax.SelectorValue) Test(org.junit.Test)

Aggregations

SelectorValue (com.google.devtools.build.lib.syntax.SelectorValue)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 Label (com.google.devtools.build.lib.cmdline.Label)1 SelectorList (com.google.devtools.build.lib.syntax.SelectorList)1 ConversionException (com.google.devtools.build.lib.syntax.Type.ConversionException)1 List (java.util.List)1