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