diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/analysis/select')
3 files changed, 16 insertions, 34 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 ac89f9f0eb..4901884590 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 @@ -16,7 +16,6 @@ package com.google.devtools.build.lib.analysis.select; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; -import com.google.common.collect.Lists; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.AbstractAttributeMapper; @@ -29,6 +28,7 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.syntax.Type; import java.util.List; +import java.util.stream.Collectors; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -116,27 +116,20 @@ public class AbstractAttributeMapperTest extends BuildViewTestCase { assertThat(mapper.isAttributeValueExplicitlySpecified("nonsense")).isFalse(); } - 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(attrName)) { - labelsVisited.add(label.toString()); - } - } - } - @Test public void testVisitation() throws Exception { - VisitationRecorder recorder = new VisitationRecorder("srcs"); - mapper.visitLabels(recorder); - assertThat(recorder.labelsVisited).containsExactly("//p:a", "//p:b", "//p:c"); + assertThat(getLabelsForAttribute(mapper, "srcs")).containsExactly("//p:a", "//p:b", "//p:c"); + } + + protected static List<String> getLabelsForAttribute( + AttributeMap attributeMap, String attributeName) throws InterruptedException { + return attributeMap + .visitLabels() + .stream() + .filter((d) -> d.getAttribute().getName().equals(attributeName)) + .map(AttributeMap.DepEdge::getLabel) + .map(Label::toString) + .collect(Collectors.toList()); } @Test 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 a8f912602c..073c751766 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 @@ -146,9 +146,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': ['default.sh'],", " }))"); - VisitationRecorder recorder = new VisitationRecorder("srcs"); - AggregatingAttributeMapper.of(rule).visitLabels(recorder); - assertThat(recorder.labelsVisited) + assertThat(getLabelsForAttribute(AggregatingAttributeMapper.of(rule), "srcs")) .containsExactlyElementsIn( ImmutableList.of( "//a:a.sh", "//a:b.sh", "//a:default.sh", "//conditions:a", "//conditions:b")); @@ -163,9 +161,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest " '//conditions:a': None,", " }))"); - VisitationRecorder recorder = new VisitationRecorder("malloc"); - AggregatingAttributeMapper.of(rule).visitLabels(recorder); - assertThat(recorder.labelsVisited) + assertThat(getLabelsForAttribute(AggregatingAttributeMapper.of(rule), "malloc")) .containsExactly("//conditions:a", getDefaultMallocLabel(rule).toString()); } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java index e5f38cb650..2078904857 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java @@ -18,8 +18,6 @@ import static org.junit.Assert.fail; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.packages.Attribute; -import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RawAttributeMapper; import com.google.devtools.build.lib.packages.Rule; @@ -97,12 +95,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest { public void testVisitLabels() throws Exception { RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule()); try { - rawMapper.visitLabels(new AttributeMap.AcceptsLabelAttribute() { - @Override - public void acceptLabelAttribute(Label label, Attribute attribute) { - // Nothing to do. - } - }); + rawMapper.visitLabels(); fail("Expected label visitation to fail since one attribute is configurable"); } catch (IllegalArgumentException e) { assertThat(e) |