aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/analysis/select
diff options
context:
space:
mode:
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.java28
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java19
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java10
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java15
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java23
5 files changed, 78 insertions, 17 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 5e6c31bd50..400729e7bc 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
@@ -14,6 +14,11 @@
package com.google.devtools.build.lib.analysis.select;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@@ -29,16 +34,22 @@ import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.util.PackageFactoryApparatus;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.testutil.FoundationTestCase;
+import com.google.devtools.build.lib.testutil.FoundationTestCaseForJunit4;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
import java.util.List;
/**
* Unit tests for {@link AbstractAttributeMapper}.
*/
-public class AbstractAttributeMapperTest extends FoundationTestCase {
+@RunWith(JUnit4.class)
+public class AbstractAttributeMapperTest extends FoundationTestCaseForJunit4 {
private Package pkg;
protected Rule rule;
@@ -61,9 +72,8 @@ public class AbstractAttributeMapperTest extends FoundationTestCase {
return pkg.getRule(ruleName);
}
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public final void initializeRuleAndMapper() throws Exception {
rule = createRule("x", "myrule",
"cc_binary(name = 'myrule',",
" srcs = ['a', 'b', 'c'])");
@@ -71,17 +81,20 @@ public class AbstractAttributeMapperTest extends FoundationTestCase {
mapper = new TestMapper(pkg, ruleClass, rule.getLabel(), rule.getAttributeContainer());
}
+ @Test
public void testRuleProperties() throws Exception {
assertEquals(rule.getName(), mapper.getName());
assertEquals(rule.getLabel(), mapper.getLabel());
}
+ @Test
public void testPackageDefaultProperties() throws Exception {
assertEquals(pkg.getDefaultHdrsCheck(), mapper.getPackageDefaultHdrsCheck());
assertEquals(pkg.getDefaultTestOnly(), mapper.getPackageDefaultTestOnly());
assertEquals(pkg.getDefaultDeprecation(), mapper.getPackageDefaultDeprecation());
}
+ @Test
public void testAttributeTypeChecking() throws Exception {
// Good typing:
mapper.get("srcs", BuildType.LABEL_LIST);
@@ -103,16 +116,19 @@ public class AbstractAttributeMapperTest extends FoundationTestCase {
}
}
+ @Test
public void testGetAttributeType() throws Exception {
assertEquals(BuildType.LABEL_LIST, mapper.getAttributeType("srcs"));
assertNull(mapper.getAttributeType("nonsense"));
}
+ @Test
public void testGetAttributeDefinition() {
assertEquals("srcs", mapper.getAttributeDefinition("srcs").getName());
assertNull(mapper.getAttributeDefinition("nonsense"));
}
+ @Test
public void testIsAttributeExplicitlySpecified() throws Exception {
assertTrue(mapper.isAttributeValueExplicitlySpecified("srcs"));
assertFalse(mapper.isAttributeValueExplicitlySpecified("deps"));
@@ -129,6 +145,7 @@ public class AbstractAttributeMapperTest extends FoundationTestCase {
}
}
+ @Test
public void testVisitation() throws Exception {
VisitationRecorder recorder = new VisitationRecorder();
mapper.visitLabels(recorder);
@@ -136,6 +153,7 @@ public class AbstractAttributeMapperTest extends FoundationTestCase {
.containsExactlyElementsIn(ImmutableList.of("//x:a", "//x:b", "//x:c"));
}
+ @Test
public void testComputedDefault() throws Exception {
// Should return a valid ComputedDefault instance since this is a computed default:
assertThat(mapper.getComputedDefault("$stl", BuildType.LABEL))
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 184a9242a6..f4370c8f04 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
@@ -14,6 +14,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.collect.ImmutableList;
import com.google.common.collect.Iterables;
@@ -25,14 +26,19 @@ import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.testutil.TestConstants;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
/**
* Unit tests for {@link AggregatingAttributeMapper}.
*/
+@RunWith(JUnit4.class)
public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest {
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public final void createMapper() throws Exception {
// Run AbstractAttributeMapper tests through an AggregatingAttributeMapper.
mapper = AggregatingAttributeMapper.of(rule);
}
@@ -41,6 +47,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
* Tests that {@link AggregatingAttributeMapper#visitAttribute} returns an
* attribute's sole value when declared directly (i.e. not as a configurable dict).
*/
+ @Test
public void testGetPossibleValuesDirectAttribute() throws Exception {
Rule rule = createRule("a", "myrule",
"sh_binary(name = 'myrule',",
@@ -53,6 +60,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
* Tests that {@link AggregatingAttributeMapper#visitAttribute} returns
* every possible value that a configurable attribute can resolve to.
*/
+ @Test
public void testGetPossibleValuesConfigurableAttribute() throws Exception {
Rule rule = createRule("a", "myrule",
"sh_binary(name = 'myrule',",
@@ -69,6 +77,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
ImmutableList.of(Label.create("a", "default.sh"))));
}
+ @Test
public void testGetPossibleValuesWithConcatenatedSelects() throws Exception {
Rule rule = createRule("a", "myrule",
"sh_binary(name = 'myrule',",
@@ -92,6 +101,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
* Given a large number of selects, we expect better than the naive
* exponential performance from evaluating select1 x select2 x select3 x ...
*/
+ @Test
public void testGetPossibleValuesWithManySelects() throws Exception {
String pattern = " + select({'//conditions:a1': '%c', '//conditions:a2': '%s'})";
StringBuilder ruleDef = new StringBuilder();
@@ -110,6 +120,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
* Tests that, on rule visitation, {@link AggregatingAttributeMapper} visits *every* possible
* value in a configurable attribute (including configuration key labels).
*/
+ @Test
public void testVisitationConfigurableAttribute() throws Exception {
Rule rule = createRule("a", "myrule",
"sh_binary(name = 'myrule',",
@@ -127,6 +138,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
"//a:a.sh", "//a:b.sh", "//a:default.sh", "//conditions:a", "//conditions:b"));
}
+ @Test
public void testGetReachableLabels() throws Exception {
Rule rule = createRule("x", "main",
"cc_binary(",
@@ -156,6 +168,7 @@ public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest
assertThat(mapper.getReachableLabels("srcs", false)).containsExactlyElementsIn(valueLabels);
}
+ @Test
public void testDuplicateCheckOnNullValues() throws Exception {
if (TestConstants.THIS_IS_BAZEL) {
return;
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java
index 37a1cbc93e..6023b6dbd8 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java
@@ -18,6 +18,10 @@ import com.google.devtools.build.lib.analysis.ConfiguredAttributeMapper;
import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
import com.google.devtools.build.lib.packages.AbstractAttributeMapper;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
/**
* Tests that {@link ConfiguredAttributeMapper} fulfills all behavior expected
* of {@link AbstractAttributeMapper}.
@@ -27,10 +31,10 @@ import com.google.devtools.build.lib.packages.AbstractAttributeMapper;
* inherit from {@link com.google.devtools.build.lib.analysis.util.BuildViewTestCase} to run tests
* with build configurations.
*/
+@RunWith(JUnit4.class)
public class ConfiguredAttributeMapperCommonTest extends AbstractAttributeMapperTest {
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public final void createMapper() throws Exception {
mapper = ConfiguredAttributeMapper.of(rule, ImmutableSet.<ConfigMatchingProvider>of());
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java
index a7c035ea3c..a634c1108a 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java
@@ -14,18 +14,25 @@
package com.google.devtools.build.lib.analysis.select;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
import com.google.devtools.build.lib.syntax.Type;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
/**
* Unit tests for {@link NonconfigurableAttributeMapper}.
*/
+@RunWith(JUnit4.class)
public class NonconfigurableAttributeMapperTest extends AbstractAttributeMapperTest {
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public final void createRule() throws Exception {
rule = createRule("x", "myrule",
"cc_binary(",
" name = 'myrule',",
@@ -34,11 +41,13 @@ public class NonconfigurableAttributeMapperTest extends AbstractAttributeMapperT
" deprecation = \"this rule is deprecated!\")");
}
+ @Test
public void testGetNonconfigurableAttribute() throws Exception {
assertEquals("this rule is deprecated!",
NonconfigurableAttributeMapper.of(rule).get("deprecation", Type.STRING));
}
+ @Test
public void testGetConfigurableAttribute() throws Exception {
try {
NonconfigurableAttributeMapper.of(rule).get("linkstatic", Type.BOOLEAN);
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 fad95ffce5..0d9c7616aa 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
@@ -14,6 +14,11 @@
package com.google.devtools.build.lib.analysis.select;
import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.cmdline.Label;
@@ -23,16 +28,21 @@ import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.RawAttributeMapper;
import com.google.devtools.build.lib.packages.Rule;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
import java.util.List;
/**
* Unit tests for {@link RawAttributeMapper}.
*/
+@RunWith(JUnit4.class)
public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public final void createMapper() throws Exception {
// Run AbstractAttributeMapper tests through a RawAttributeMapper.
mapper = RawAttributeMapper.of(rule);
}
@@ -49,6 +59,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
" data = [ ':data_a', ':data_b' ])");
}
+ @Test
public void testGetAttribute() throws Exception {
RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
List<Label> value = rawMapper.get("data", BuildType.LABEL_LIST);
@@ -67,12 +78,14 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
}
@Override
+ @Test
public void testGetAttributeType() throws Exception {
RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("data")); // not configurable
assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("srcs")); // configurable
}
+ @Test
public void testConfigurabilityCheck() throws Exception {
RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
assertFalse(rawMapper.isConfigurable("data", BuildType.LABEL_LIST));
@@ -82,6 +95,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
/**
* Tests that RawAttributeMapper can't handle label visitation with configurable attributes.
*/
+ @Test
public void testVisitLabels() throws Exception {
RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
try {
@@ -98,6 +112,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
}
}
+ @Test
public void testGetConfigurabilityKeys() throws Exception {
RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
assertThat(rawMapper.getConfigurabilityKeys("srcs", BuildType.LABEL_LIST))
@@ -109,6 +124,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
assertThat(rawMapper.getConfigurabilityKeys("data", BuildType.LABEL_LIST)).isEmpty();
}
+ @Test
public void testGetMergedValues() throws Exception {
Rule rule = createRule("x", "myrule",
"sh_binary(",
@@ -125,6 +141,7 @@ public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
.inOrder();
}
+ @Test
public void testMergedValuesWithConcatenatedSelects() throws Exception {
Rule rule = createRule("x", "myrule",
"sh_binary(",