aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java
index 9629bbd54e..dcd80382f7 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlagTest.java
@@ -76,6 +76,25 @@ public final class ConfigFeatureFlagTest extends SkylarkTestCase {
"config_feature_flag(",
" name = 'flag',",
" allowed_values = ['default', 'configured', 'other'],",
+ ")");
+ assertThat(ConfigFeatureFlagProvider.fromTarget(getConfiguredTarget("//test:top")).getValue())
+ .isEqualTo("configured");
+ }
+
+ @Test
+ public void configFeatureFlagProvider_usesConfiguredValueOverDefault() throws Exception {
+ scratch.file(
+ "test/BUILD",
+ "feature_flag_setter(",
+ " name = 'top',",
+ " exports_flag = ':flag',",
+ " flag_values = {",
+ " ':flag': 'configured',",
+ " },",
+ ")",
+ "config_feature_flag(",
+ " name = 'flag',",
+ " allowed_values = ['default', 'configured', 'other'],",
" default_value = 'default',",
")");
assertThat(ConfigFeatureFlagProvider.fromTarget(getConfiguredTarget("//test:top")).getValue())
@@ -250,6 +269,34 @@ public final class ConfigFeatureFlagTest extends SkylarkTestCase {
}
@Test
+ public void configFeatureFlagProvider_throwsErrorIfNeitherDefaultNorConfiguredValueSet()
+ throws Exception {
+ reporter.removeHandler(failFastHandler); // expecting an error
+ scratch.file(
+ "test/BUILD",
+ "feature_flag_setter(",
+ " name = 'top',",
+ " exports_flag = ':flag',",
+ " flag_values = {",
+ " ':other': 'configured',",
+ " },",
+ ")",
+ "config_feature_flag(",
+ " name = 'flag',",
+ " allowed_values = ['other', 'configured'],",
+ ")",
+ "config_feature_flag(",
+ " name = 'other',",
+ " allowed_values = ['default', 'configured', 'other'],",
+ " default_value = 'default',",
+ ")");
+ assertThat(getConfiguredTarget("//test:flag")).isNull();
+ assertContainsEvent(
+ "in config_feature_flag rule //test:flag: "
+ + "flag has no default and must be set, but was not set");
+ }
+
+ @Test
public void allowedValuesAttribute_cannotBeEmpty() throws Exception {
reporter.removeHandler(failFastHandler); // expecting an error
scratch.file(
@@ -282,7 +329,7 @@ public final class ConfigFeatureFlagTest extends SkylarkTestCase {
}
@Test
- public void defaultValueAttribute_mustBeMemberOfAllowedValues() throws Exception {
+ public void defaultValueAttribute_mustBeMemberOfAllowedValuesIfPresent() throws Exception {
reporter.removeHandler(failFastHandler); // expecting an error
scratch.file(
"test/BUILD",
@@ -305,7 +352,7 @@ public final class ConfigFeatureFlagTest extends SkylarkTestCase {
}
@Test
- public void configurationValue_mustBeMemberOfAllowedValues() throws Exception {
+ public void configurationValue_mustBeMemberOfAllowedValuesIfPresent() throws Exception {
reporter.removeHandler(failFastHandler); // expecting an error
scratch.file(
"test/BUILD",