From 7520dcce42217c8076b06ed88c0e4e04ed99a0f4 Mon Sep 17 00:00:00 2001 From: cparsons Date: Wed, 4 Apr 2018 13:59:27 -0700 Subject: Migrate SkylarkNativeModule methods to use @SkylarkCallable instead of @SkylarkSignature Most notably, this involves introduction of a new function abstraction, BuiltinMethod, which can wrap a {objc, SkylarkCallable} pair into a BaseFunction for later calling. (This is required due to the current layer of indirection on the end "native" module) RELNOTES: None. PiperOrigin-RevId: 191642467 --- .../build/lib/syntax/SkylarkEvaluationTest.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java') 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 ed8fb91906..ee6fc425bb 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 @@ -163,6 +163,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { return ImmutableMap.of("a", ImmutableList.of("b", "c")); } + @SkylarkCallable( name = "with_params", documented = false, @@ -352,6 +353,18 @@ public class SkylarkEvaluationTest extends EvaluationTest { + ")"; } + @SkylarkCallable(name = "proxy_methods_object", + doc = "Returns a struct containing all callable method objects of this mock", + allowReturnNones = true) + public ClassObject proxyMethodsObject() { + ImmutableMap.Builder builder = new ImmutableMap.Builder<>(); + for (String nativeFunction : FuncallExpression.getMethodNames(Mock.class)) { + builder.put(nativeFunction, + FuncallExpression.getBuiltinCallable(this, nativeFunction)); + } + return NativeProvider.STRUCT.create(builder.build(), "no native callable '%s'"); + } + @Override public String toString() { return ""; @@ -920,6 +933,16 @@ public class SkylarkEvaluationTest extends EvaluationTest { .testLookup("m", MutableList.of(env, "b", "c", "extra_string")); } + @Test + public void testProxyMethodsObject() throws Exception { + new SkylarkTest() + .update("mock", new Mock()) + .setUp( + "m = mock.proxy_methods_object()", + "b = m.with_params(1, True, named=True)") + .testLookup("b", "with_params(1, true, false, true, false, a)"); + } + @Test public void testJavaCallWithPositionalAndKwargs() throws Exception { new SkylarkTest() @@ -1527,6 +1550,7 @@ public class SkylarkEvaluationTest extends EvaluationTest { "is_empty", "nullfunc_failing", "nullfunc_working", + "proxy_methods_object", "return_bad", "string", "string_list", -- cgit v1.2.3