Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/vm/ExceptionDuringParsingTest.java @ 22424:fec62e298245
Rename package truffle.api.test to truffle.api to enable package-protected API access for testing.
author | Christian Humer <christian.humer@oracle.com> |
---|---|
date | Wed, 02 Dec 2015 15:16:27 +0100 |
parents | truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ExceptionDuringParsingTest.java@906a5f6e07cc |
children | b39b603e2a1e |
comparison
equal
deleted
inserted
replaced
22423:70a10a9f28ad | 22424:fec62e298245 |
---|---|
1 /* | |
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.vm; | |
24 | |
25 import com.oracle.truffle.api.impl.Accessor; | |
26 import com.oracle.truffle.api.source.Source; | |
27 | |
28 import static com.oracle.truffle.api.vm.ImplicitExplicitExportTest.L1; | |
29 | |
30 import com.oracle.truffle.api.vm.PolyglotEngine; | |
31 import com.oracle.truffle.api.vm.ImplicitExplicitExportTest.Ctx; | |
32 | |
33 import java.io.IOException; | |
34 | |
35 import org.junit.After; | |
36 | |
37 import static org.junit.Assert.assertEquals; | |
38 import static org.junit.Assert.assertNotNull; | |
39 import static org.junit.Assert.assertTrue; | |
40 import static org.junit.Assert.fail; | |
41 | |
42 import org.junit.Before; | |
43 import org.junit.Test; | |
44 | |
45 public class ExceptionDuringParsingTest { | |
46 public static Accessor API; | |
47 | |
48 @Before | |
49 @After | |
50 public void cleanTheSet() { | |
51 Ctx.disposed.clear(); | |
52 } | |
53 | |
54 @Test | |
55 public void canGetAccessToOwnLanguageInstance() throws Exception { | |
56 PolyglotEngine vm = PolyglotEngine.newBuilder().build(); | |
57 PolyglotEngine.Language language = vm.getLanguages().get(L1); | |
58 assertNotNull("L1 language is defined", language); | |
59 | |
60 final Source src = Source.fromText("parse=No, no, no!", "Fail on parsing").withMimeType(L1); | |
61 try { | |
62 vm.eval(src); | |
63 fail("Exception thrown"); | |
64 } catch (IOException ex) { | |
65 assertEquals(ex.getMessage(), "No, no, no!"); | |
66 } | |
67 | |
68 assertEquals("No dispose yet", 0, Ctx.disposed.size()); | |
69 | |
70 vm.dispose(); | |
71 | |
72 assertEquals("One context disposed", 1, Ctx.disposed.size()); | |
73 | |
74 try { | |
75 vm.eval(src); | |
76 fail("Should throw an exception"); | |
77 } catch (IllegalStateException ex) { | |
78 assertTrue(ex.getMessage(), ex.getMessage().contains("disposed")); | |
79 } | |
80 try { | |
81 vm.findGlobalSymbol("nothing"); | |
82 fail("Should throw an exception"); | |
83 } catch (IllegalStateException ex) { | |
84 assertTrue(ex.getMessage(), ex.getMessage().contains("disposed")); | |
85 } | |
86 try { | |
87 vm.dispose(); | |
88 fail("Should throw an exception"); | |
89 } catch (IllegalStateException ex) { | |
90 assertTrue(ex.getMessage(), ex.getMessage().contains("disposed")); | |
91 } | |
92 } | |
93 } |