aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2018-04-16 11:45:12 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-16 11:47:22 -0700
commit8f495c97762ec7d23c9f338da971fee30b2800e1 (patch)
treef89d597d5b47594b9b174a6949320e50d2835ed2 /src/test
parent6924da260265d4475685530584e82ecaefc04d89 (diff)
Implement positional overloads for ctx.actions.args.
We now support calls like: args = ctx.action.args() args.add("--foo", value) args.add_all("--foo", values) RELNOTES: Support two-arg overloads for ctx.actions.args (eg. args.add("--foo", val)) PiperOrigin-RevId: 193074060
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index f0a00dc60d..4e656ce3d2 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -1764,7 +1764,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
"args.add('-')",
"args.add('foo', format='format%s')",
"args.add('-')",
- "args.add(arg_name='--foo', value='val')",
+ "args.add('--foo', 'val')",
"ruleContext.actions.run(",
" inputs = depset(ruleContext.files.srcs),",
" outputs = ruleContext.files.srcs,",
@@ -1805,7 +1805,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
"args = ruleContext.actions.args()",
"args.add_all([1, 2])",
"args.add('-')",
- "args.add_all(arg_name='--foo', values=[1, 2])",
+ "args.add_all('--foo', [1, 2])",
"args.add('-')",
"args.add_all([1, 2], before_each='-before')",
"args.add('-')",
@@ -1894,11 +1894,11 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
"args.add('-')",
"args.add_joined([], join_with=',', omit_if_empty=False)",
"args.add('-')",
- "args.add_all(arg_name='--foo', values=[])",
+ "args.add_all('--foo', [])",
"args.add('-')",
- "args.add_all(arg_name='--foo', values=[], omit_if_empty=False)",
+ "args.add_all('--foo', [], omit_if_empty=False)",
"args.add('-')",
- "args.add_all(arg_name='--foo', values=[1], map_each=filter, terminate_with='hello')",
+ "args.add_all('--foo', [1], map_each=filter, terminate_with='hello')",
"ruleContext.actions.run(",
" inputs = depset(ruleContext.files.srcs),",
" outputs = ruleContext.files.srcs,",
@@ -2185,6 +2185,32 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
}
@Test
+ public void testArgsAddInvalidTypesForArgAndValues() throws Exception {
+ setSkylarkSemanticsOptions("--incompatible_disallow_old_style_args_add=true");
+ SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
+ checkError(
+ ruleContext,
+ "expected value of type 'string' for arg name, got 'Integer'",
+ "args = ruleContext.actions.args()",
+ "args.add(1, 'value')");
+ checkError(
+ ruleContext,
+ "expected value of type 'string' for arg name, got 'Integer'",
+ "args = ruleContext.actions.args()",
+ "args.add_all(1, [1, 2])");
+ checkError(
+ ruleContext,
+ "expected value of type 'sequence or depset' for values, got 'Integer'",
+ "args = ruleContext.actions.args()",
+ "args.add_all(1)");
+ checkErrorContains(
+ ruleContext,
+ "expected value of type 'sequence or depset' for parameter 'values'",
+ "args = ruleContext.actions.args()",
+ "args.add_all('--foo', 1)");
+ }
+
+ @Test
public void testLazyArgIllegalFormatString() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
evalRuleContextCode(
@@ -2492,10 +2518,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
commandLines.add(
getCommandLine("args = ruleContext.actions.args()", "args.add('foo')", "args"));
commandLines.add(
- getCommandLine(
- "args = ruleContext.actions.args()",
- "args.add(arg_name='--foo', value='foo')",
- "args"));
+ getCommandLine("args = ruleContext.actions.args()", "args.add('--foo', 'foo')", "args"));
commandLines.add(
getCommandLine(
"args = ruleContext.actions.args()", "args.add('foo', format='--foo=%s')", "args"));
@@ -2504,9 +2527,7 @@ public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
"args = ruleContext.actions.args()", "args.add_all(['foo', 'bar'])", "args"));
commandLines.add(
getCommandLine(
- "args = ruleContext.actions.args()",
- "args.add_all(arg_name='-foo', values=['foo', 'bar'])",
- "args"));
+ "args = ruleContext.actions.args()", "args.add_all('-foo', ['foo', 'bar'])", "args"));
commandLines.add(
getCommandLine(
"args = ruleContext.actions.args()",