Add --all_incompatible_changes invocation policy test.
By the time the invocation policy gets enforced, the expansion flag should have been
expanded, and policy should act as on any other expansion flag.
@@ -17,6 +17,9 @@ package com.google.devtools.build.lib.runtime;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
+import com.google.devtools.build.lib.flags.InvocationPolicyEnforcer;
+import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy;
+import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.UseDefault;
import com.google.devtools.common.options.Converters;
import com.google.devtools.common.options.ExpansionFunction;
import com.google.devtools.common.options.IsolatedOptionsData;
@@ -144,6 +147,30 @@ public class AllIncompatibleChangesExpansionTest {
assertThat(opts.incompatibleB).isTrue();
}
+ @Test
+ public void invocationPolicy() throws OptionsParsingException {
+ // Check that all-expansion behaves just like any other expansion flag and can be filtered
+ // by invocation policy.
+ InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder();
+ invocationPolicyBuilder.addFlagPoliciesBuilder()
+ .setFlagName("incompatible_A")
+ .setUseDefault(UseDefault.getDefaultInstance())
+ .build();
+ InvocationPolicy policy = invocationPolicyBuilder.build();
+ InvocationPolicyEnforcer enforcer = new InvocationPolicyEnforcer(policy);
+
+ OptionsParser parser =
+ OptionsParser.newOptionsParser(ExampleOptions.class);
+ parser.parse("--all");
+ enforcer.enforce(parser);
+
+ ExampleOptions opts = parser.getOptions(ExampleOptions.class);
+ assertThat(opts.x).isFalse();
+ assertThat(opts.y).isTrue();
+ assertThat(opts.incompatibleA).isFalse(); // A should have been removed from the expansion.
+ assertThat(opts.incompatibleB).isTrue(); // B, without a policy, should have been left alone.
+ }
+
// There's no unit test to check that the expansion of --all is sorted. IsolatedOptionsData is not
// exposed from OptionsParser, making it difficult to check, and it's not clear that exposing it
// would be worth it.
