Search in sources :

Example 1 with SelectorList

use of com.google.devtools.build.lib.syntax.SelectorList 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)

Aggregations

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 SelectorValue (com.google.devtools.build.lib.syntax.SelectorValue)1 List (java.util.List)1 Test (org.junit.Test)1