Cleanup @SkylarkCallable parameters and their error handling.
This involves enforcing additional compiletime restrictions on Param ordering and semantics.
RELNOTES: None.
PiperOrigin-RevId: 191927206
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index ee6fc42..3804a72 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -943,6 +943,38 @@
.testLookup("b", "with_params(1, true, false, true, false, a)");
}
+ /**
+ * This test verifies an error is raised when a method parameter is set both positionally and
+ * by name.
+ */
+ @Test
+ public void testArgSpecifiedBothByNameAndPosition() throws Exception {
+ // in with_params, 'posOrNamed' is positional parameter index 2. So by specifying both
+ // posOrNamed by name and three positional parameters, there is a conflict.
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .testIfErrorContains("got multiple values for keyword argument 'posOrNamed'",
+ "mock.with_params(1, True, True, posOrNamed=True, named=True)");
+ }
+
+ @Test
+ public void testTooManyPositionalArgs() throws Exception {
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .testIfErrorContains("expected no more than 3 positional arguments, but got 4",
+ "mock.with_params(1, True, True, 'toomany', named=True)");
+
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .testIfErrorContains("expected no more than 3 positional arguments, but got 5",
+ "mock.with_params(1, True, True, 'toomany', 'alsotoomany', named=True)");
+
+ new SkylarkTest()
+ .update("mock", new Mock())
+ .testIfErrorContains("expected no more than 1 positional arguments, but got 2",
+ "mock.is_empty('a', 'b')");
+ }
+
@Test
public void testJavaCallWithPositionalAndKwargs() throws Exception {
new SkylarkTest()