|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.test.interop;
|
42 | 42 |
|
43 |
| -import org.junit.After; |
44 |
| -import org.junit.Before; |
45 |
| -import org.junit.Test; |
46 |
| -import static org.junit.Assert.assertFalse; |
47 | 43 | import static org.junit.Assert.assertEquals;
|
| 44 | +import static org.junit.Assert.assertFalse; |
| 45 | +import static org.junit.Assert.assertNotEquals; |
48 | 46 | import static org.junit.Assert.assertTrue;
|
| 47 | +import static org.junit.Assert.fail; |
| 48 | + |
| 49 | +import java.util.Arrays; |
| 50 | +import java.util.Iterator; |
| 51 | +import java.util.List; |
49 | 52 |
|
50 | 53 | import org.graalvm.polyglot.Context;
|
51 | 54 | import org.graalvm.polyglot.Context.Builder;
|
| 55 | +import org.graalvm.polyglot.PolyglotException; |
52 | 56 | import org.graalvm.polyglot.Value;
|
53 | 57 | import org.graalvm.polyglot.proxy.ProxyArray;
|
| 58 | +import org.junit.After; |
| 59 | +import org.junit.Before; |
| 60 | +import org.junit.Test; |
54 | 61 |
|
55 | 62 | import com.oracle.graal.python.test.PythonTests;
|
56 | 63 |
|
57 |
| -import java.util.Arrays; |
58 |
| -import java.util.Iterator; |
59 |
| -import java.util.List; |
60 |
| - |
61 | 64 | public class InteropLibraryTest extends PythonTests {
|
62 | 65 | private Context context;
|
63 | 66 |
|
@@ -165,6 +168,24 @@ public void testForItemInLazyArray() {
|
165 | 168 | assertEquals(list.size() * 3, tripples.getArraySize());
|
166 | 169 | }
|
167 | 170 |
|
| 171 | + @Test |
| 172 | + public void testException() { |
| 173 | + try { |
| 174 | + context.eval("python", "1/0"); |
| 175 | + } catch (PolyglotException e) { |
| 176 | + Value exception = e.getGuestObject(); |
| 177 | + assertTrue(exception.hasMember("args")); |
| 178 | + Value args = exception.getMember("args"); |
| 179 | + assertTrue(args.hasArrayElements()); |
| 180 | + assertEquals(1, args.getArraySize()); |
| 181 | + assertEquals("division by zero", args.getArrayElement(0).asString()); |
| 182 | + // This excercises isIdenticalOrUndefined message internally |
| 183 | + assertNotEquals(exception, args); |
| 184 | + return; |
| 185 | + } |
| 186 | + fail("didn't throw exception"); |
| 187 | + } |
| 188 | + |
168 | 189 | private static final class LazyArray implements ProxyArray {
|
169 | 190 |
|
170 | 191 | private final Iterator<?> it;
|
|
0 commit comments