diff options
author | John Cater <jcater@google.com> | 2018-03-13 09:21:08 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-13 09:23:01 -0700 |
commit | fd017b692f649a233efc2b5ee3c7266472737fe6 (patch) | |
tree | 49bf90d9aa832addabcaabb536254eb841996214 /src/test/java/com/google/devtools/build | |
parent | 9df3b45a739d7d7181b8d1fdeccc7c2276138f48 (diff) |
Clean up testing of constraint-based selects to not rely on anything that uses toolchains.
Closes #4833.
Change-Id: I9f58dc98cc00d0b2246d479d33a5086114d95073
PiperOrigin-RevId: 188882007
Diffstat (limited to 'src/test/java/com/google/devtools/build')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java index 97769f98a7..a616efceb9 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java @@ -85,15 +85,20 @@ public class ConfigurableAttributesTest extends BuildViewTestCase { private static final String DEFAULTDEP_INPUT = "bin java/hello/libdefaultdep.jar"; /** - * Checks that, given the specified configuration parameters, the input rule *has* the - * expected dependencies and *doesn't have* the unexpected dependencies. + * Checks that, given the specified configuration parameters, the input rule *has* the expected + * attribute values and *doesn't have* the unexpected attribute values. */ - private void checkRule(String ruleLabel, Collection<String> options, - Iterable<String> expected, Iterable<String> notExpected) throws Exception { + private void checkRule( + String ruleLabel, + String attributeName, + Collection<String> options, + Iterable<String> expected, + Iterable<String> notExpected) + throws Exception { useConfiguration(options.toArray(new String[options.size()])); ConfiguredTarget binary = getConfiguredTarget(ruleLabel); assertThat(binary).isNotNull(); - Set<String> actualDeps = artifactsToStrings(getPrerequisiteArtifacts(binary, "deps")); + Set<String> actualDeps = artifactsToStrings(getPrerequisiteArtifacts(binary, attributeName)); expected.forEach(expectedInput -> assertThat(actualDeps).contains(expectedInput)); notExpected.forEach(unexpectedInput -> assertThat(actualDeps).doesNotContain(unexpectedInput)); } @@ -103,6 +108,15 @@ public class ConfigurableAttributesTest extends BuildViewTestCase { checkRule(ruleLabel, ImmutableList.of(option), expected, notExpected); } + private void checkRule( + String ruleLabel, + Collection<String> options, + Iterable<String> expected, + Iterable<String> notExpected) + throws Exception { + checkRule(ruleLabel, "deps", options, expected, notExpected); + } + private static final MockRule RULE_WITH_OUTPUT_ATTR = () -> MockRule.define("rule_with_output_attr", attr("out", BuildType.OUTPUT)); @@ -1148,29 +1162,47 @@ public class ConfigurableAttributesTest extends BuildViewTestCase { @Test public void selectOnConstraints() throws Exception { - writeHelloRules(/*includeDefaultCondition=*/true); - scratch.file("conditions/BUILD", - "constraint_setting(name = 'fruit')", - "constraint_value(name = 'apple', constraint_setting = 'fruit')", - "constraint_value(name = 'banana', constraint_setting = 'fruit')", - "platform(", - " name = 'apple_platform',", - " constraint_values = [':apple'],", - ")", - "platform(", - " name = 'banana_platform',", - " constraint_values = [':banana'],", - ")", - "config_setting(", - " name = 'a',", - " constraint_values = [':apple']", - ")", - "config_setting(", - " name = 'b',", - " constraint_values = [':banana']", - ")"); - checkRule("//java/hello:hello", "--experimental_platforms=//conditions:apple_platform", - /*expected:*/ ImmutableList.of(ADEP_INPUT), - /*not expected:*/ ImmutableList.of(BDEP_INPUT, DEFAULTDEP_INPUT)); + // create some useful constraints and platforms. + scratch.file( + "conditions/BUILD", + "constraint_setting(name = 'fruit')", + "constraint_value(name = 'apple', constraint_setting = 'fruit')", + "constraint_value(name = 'banana', constraint_setting = 'fruit')", + "platform(", + " name = 'apple_platform',", + " constraint_values = [':apple'],", + ")", + "platform(", + " name = 'banana_platform',", + " constraint_values = [':banana'],", + ")", + "config_setting(", + " name = 'a',", + " constraint_values = [':apple']", + ")", + "config_setting(", + " name = 'b',", + " constraint_values = [':banana']", + ")"); + scratch.file("afile", "acontents"); + scratch.file("bfile", "bcontents"); + scratch.file("defaultfile", "defaultcontents"); + scratch.file( + "check/BUILD", + "filegroup(name = 'adep', srcs = ['afile'])", + "filegroup(name = 'bdep', srcs = ['bfile'])", + "filegroup(name = 'defaultdep', srcs = ['defaultfile'])", + "filegroup(name = 'hello',", + " srcs = select({", + " '//conditions:a': [':adep'],", + " '//conditions:b': [':bdep'],", + " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': [':defaultdep'],", + " }))"); + checkRule( + "//check:hello", + "srcs", + ImmutableList.of("--experimental_platforms=//conditions:apple_platform"), + /*expected:*/ ImmutableList.of("src check/afile"), + /*not expected:*/ ImmutableList.of("src check/bfile", "src check/defaultfile")); } } |