|
41 | 41 | package com.oracle.graal.python.test.interop; |
42 | 42 |
|
43 | 43 | import static org.junit.Assert.assertEquals; |
| 44 | +import static org.junit.Assert.assertFalse; |
44 | 45 | import static org.junit.Assert.assertNotNull; |
45 | 46 | import static org.junit.Assert.assertTrue; |
| 47 | +import static org.junit.Assert.fail; |
46 | 48 |
|
47 | 49 | import java.io.ByteArrayOutputStream; |
48 | 50 | import java.io.IOException; |
|
52 | 54 |
|
53 | 55 | import org.graalvm.polyglot.Context; |
54 | 56 | import org.graalvm.polyglot.Engine; |
| 57 | +import org.graalvm.polyglot.PolyglotException; |
55 | 58 | import org.graalvm.polyglot.Context.Builder; |
56 | 59 | import org.graalvm.polyglot.Source; |
57 | 60 | import org.graalvm.polyglot.Value; |
|
76 | 79 | @RunWith(Enclosed.class) |
77 | 80 | public class JavaInteropTest { |
78 | 81 | public static class GeneralInterop extends PythonTests { |
| 82 | + private static final String INCOMPLETE_SOURCE = "class A:"; |
79 | 83 | private ByteArrayOutputStream out; |
80 | 84 | private Context context; |
81 | 85 | private ByteArrayOutputStream err; |
@@ -107,6 +111,55 @@ public void evalFailsOnError() { |
107 | 111 | assertTrue(didFail); |
108 | 112 | } |
109 | 113 |
|
| 114 | + @Test |
| 115 | + public void evalNonInteractiveThrowsSyntaxError() throws IOException { |
| 116 | + try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) { |
| 117 | + c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(false).build()); |
| 118 | + } catch (PolyglotException t) { |
| 119 | + assertTrue(t.isSyntaxError()); |
| 120 | + assertFalse(t.isIncompleteSource()); |
| 121 | + return; |
| 122 | + } |
| 123 | + fail(); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void evalNonInteractiveInInteractiveTerminalThrowsSyntaxError() throws IOException { |
| 128 | + try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) { |
| 129 | + c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(false).build()); |
| 130 | + } catch (PolyglotException t) { |
| 131 | + assertTrue(t.isSyntaxError()); |
| 132 | + assertFalse(t.isIncompleteSource()); |
| 133 | + return; |
| 134 | + } |
| 135 | + fail(); |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void evalInteractiveInNonInteractiveTerminalThrowsSyntaxError() throws IOException { |
| 140 | + try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) { |
| 141 | + c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(true).build()); |
| 142 | + } catch (PolyglotException t) { |
| 143 | + assertTrue(t.isSyntaxError()); |
| 144 | + assertTrue(t.isIncompleteSource()); |
| 145 | + return; |
| 146 | + } |
| 147 | + fail(); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + public void evalInteractiveInInteractiveTerminalThrowsSyntaxError() throws IOException { |
| 152 | + try (Context c = Context.newBuilder().allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) { |
| 153 | + c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(true).build()); |
| 154 | + } catch (PolyglotException t) { |
| 155 | + assertTrue(t.isSyntaxError()); |
| 156 | + assertTrue(t.isIncompleteSource()); |
| 157 | + return; |
| 158 | + } |
| 159 | + |
| 160 | + fail(); |
| 161 | + } |
| 162 | + |
110 | 163 | @Test |
111 | 164 | public void truffleMethodExport() { |
112 | 165 | String source = "import polyglot\n" + |
|
0 commit comments