aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/analysis/select
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2016-04-28 17:04:58 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-04-29 08:09:34 +0000
commitffa14a6a372b22b16a9ac12f3d78a1b2859043cc (patch)
tree18ee1abb88979bdf0e0de158174b98cba4e7e137 /src/test/java/com/google/devtools/build/lib/analysis/select
parent6144616cf3116df20551003d30379b104edca4cf (diff)
Let select() "unset" values via: select({"//some:condition: None }).
This not only uses the default value when applicable, but also causes ConfiguredAttributeMapper.isAttributeValueExplicitlySpecified to return false. Note the default value can come from two places: from the rule definition if specified, otherwise from the type default. RELNOTES[NEW]: select({"//some:condition: None }) is now possible (this "unsets" the attribute). -- MOS_MIGRATED_REVID=121029815
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/analysis/select')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java10
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java40
2 files changed, 47 insertions, 3 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java
index beb15a8f97..4ecd5ed560 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java
@@ -137,9 +137,15 @@ public class AbstractAttributeMapperTest extends FoundationTestCase {
protected static class VisitationRecorder implements AttributeMap.AcceptsLabelAttribute {
public List<String> labelsVisited = Lists.newArrayList();
+ private final String attrName;
+
+ public VisitationRecorder(String attrName) {
+ this.attrName = attrName;
+ }
+
@Override
public void acceptLabelAttribute(Label label, Attribute attribute) {
- if (attribute.getName().equals("srcs")) {
+ if (attribute.getName().equals(attrName)) {
labelsVisited.add(label.toString());
}
}
@@ -147,7 +153,7 @@ public class AbstractAttributeMapperTest extends FoundationTestCase {
@Test
public void testVisitation() throws Exception {
- VisitationRecorder recorder = new VisitationRecorder();
+ VisitationRecorder recorder = new VisitationRecorder("srcs");
mapper.visitLabels(recorder);
assertThat(recorder.labelsVisited)
.containsExactlyElementsIn(ImmutableList.of("//x:a", "//x:b", "//x:c"));
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java
index 4aafb58752..e9f4305d29 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.analysis.select;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertNull;
+import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.cmdline.Label;
@@ -43,6 +44,11 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
mapper = AggregatingAttributeMapper.of(rule);
}
+ private static Label getDefaultMallocLabel(Rule rule) {
+ return Verify.verifyNotNull(
+ (Label) rule.getRuleClassObject().getAttributeByName("malloc").getDefaultValueForTesting());
+ }
+
/**
* Tests that {@link AggregatingAttributeMapper#visitAttribute} returns an
* attribute's sole value when declared directly (i.e. not as a configurable dict).
@@ -130,7 +136,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
" '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],",
" }))");
- VisitationRecorder recorder = new VisitationRecorder();
+ VisitationRecorder recorder = new VisitationRecorder("srcs");
AggregatingAttributeMapper.of(rule).visitLabels(recorder);
assertThat(recorder.labelsVisited)
.containsExactlyElementsIn(
@@ -139,6 +145,23 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
}
@Test
+ public void testVisitationWithDefaultValues() throws Exception {
+ Rule rule = createRule("a", "myrule",
+ "cc_binary(name = 'myrule',",
+ " srcs = [],",
+ " malloc = select({",
+ " '//conditions:a': None,",
+ " }))");
+
+ VisitationRecorder recorder = new VisitationRecorder("malloc");
+ AggregatingAttributeMapper.of(rule).visitLabels(recorder);
+ assertThat(recorder.labelsVisited)
+ .containsExactlyElementsIn(
+ ImmutableList.of("//conditions:a", getDefaultMallocLabel(rule).toString()));
+ }
+
+
+ @Test
public void testGetReachableLabels() throws Exception {
Rule rule = createRule("x", "main",
"cc_binary(",
@@ -170,6 +193,21 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
}
@Test
+ public void testGetReachableLabelsWithDefaultValues() throws Exception {
+ Rule rule = createRule("a", "myrule",
+ "cc_binary(name = 'myrule',",
+ " srcs = [],",
+ " malloc = select({",
+ " '//conditions:a': None,",
+ " }))");
+
+ AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
+ assertThat(mapper.getReachableLabels("malloc", true))
+ .containsExactly(
+ getDefaultMallocLabel(rule), Label.create("@//conditions", "a"));
+ }
+
+ @Test
public void testDuplicateCheckOnNullValues() throws Exception {
if (TestConstants.THIS_IS_BAZEL) {
return;