diff options
author | 2016-03-08 03:08:26 +0000 | |
---|---|---|
committer | 2016-03-08 03:46:11 +0000 | |
commit | e5e3e9193a457ace9043bf70ff0253333c3435e5 (patch) | |
tree | ca5658164daeaf0d3659fd1c8ae204d1084c4498 /src/test/java/com/google/devtools/build/lib | |
parent | 2ef3f0b9caccfe4e1e6c096d542ea5d7f422ac6a (diff) |
Skylark: improved documentation and error messages of getattr() and hasattr() when being called with the name of an existing method.
While hasattr(obj, 'existing method') continues to return true, getattr(obj, 'existing method') always throws an exception (with a more detailed message than before), regardless of whether a default value was specified or not.
--
MOS_MIGRATED_REVID=116613716
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java index 55b0de2e1a..ec2d00f8d9 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java @@ -442,6 +442,25 @@ public class MethodLibraryTest extends EvaluationTestCase { } @Test + public void testGetAttrMissingField() throws Exception { + new SkylarkTest() + .testIfExactError( + "Object of type 'string' has no attribute \"not_there\"", + "getattr('a string', 'not_there')") + .testStatement("getattr('a string', 'not_there', 'use this')", "use this"); + } + + @Test + public void testGetAttrWithMethods() throws Exception { + String msg = + "Object of type 'string' has no attribute \"count\", however, " + + "a method of that name exists"; + new SkylarkTest() + .testIfExactError(msg, "getattr('a string', 'count')") + .testIfExactError(msg, "getattr('a string', 'count', 'unused default')"); + } + + @Test public void testDir() throws Exception { new SkylarkTest() .testStatement( |