Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java @ 21889:45083be8a812
Truffle: add a version string to the information provided with Language registration
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Fri, 05 Jun 2015 18:05:13 -0700 |
parents | c8418635b575 |
children |
rev | line source |
---|---|
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * questions. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 */ |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.api.test.vm; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
25 import com.oracle.truffle.api.vm.TruffleVM; |
21690
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
26 import java.io.IOException; |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
27 import java.util.Random; |
21690
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
28 import static org.junit.Assert.*; |
21490
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
29 import org.junit.Test; |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
30 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
31 /** |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
32 * A collection of tests that can certify language implementaiton to be complient with most recent |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
33 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
34 * include in your test suite. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
35 */ |
21691
99588c43c4b8
Making TruffleTCK abstract after skipping abstract test classes in GraalJUnitCore
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21690
diff
changeset
|
36 public abstract class TruffleTCK { |
21490
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
37 private TruffleVM tckVM; |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
38 |
21691
99588c43c4b8
Making TruffleTCK abstract after skipping abstract test classes in GraalJUnitCore
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21690
diff
changeset
|
39 protected TruffleTCK() { |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
40 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
41 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
42 /** |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
43 * This methods is called before first test is executed. It's purpose is to set a TruffleVM with |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
44 * your language up, so it is ready for testing. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
45 * {@link TruffleVM#eval(java.lang.String, java.lang.String) Execute} any scripts you need, and |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
46 * prepare global symbols with proper names. The symbols will then be looked up by the |
21692
c8418635b575
Verifying behavior of TruffleLanguage when it faces invalid source code.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
diff
changeset
|
47 * infrastructure (using the names provided by you from methods like {@link #plusInt()}) and |
c8418635b575
Verifying behavior of TruffleLanguage when it faces invalid source code.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
diff
changeset
|
48 * used for internal testing. |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
49 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
50 * @return initialized Truffle virtual machine |
21490
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
51 * @throws java.lang.Exception thrown when the VM preparation fails |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
52 */ |
21691
99588c43c4b8
Making TruffleTCK abstract after skipping abstract test classes in GraalJUnitCore
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21690
diff
changeset
|
53 protected abstract TruffleVM prepareVM() throws Exception; |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
54 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
55 /** |
21690
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
56 * Mimetype associated with your language. The mimetype will be passed to |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
57 * {@link TruffleVM#eval(java.lang.String, java.lang.String)} method of the {@link #prepareVM() |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
58 * created TruffleVM}. |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
59 * |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
60 * @return mime type of the tested language |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
61 */ |
21691
99588c43c4b8
Making TruffleTCK abstract after skipping abstract test classes in GraalJUnitCore
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21690
diff
changeset
|
62 protected abstract String mimeType(); |
21690
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
63 |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
64 /** |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
65 * Name of function which will return value 42 as a number. The return value of the method |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
66 * should be instance of {@link Number} and its {@link Number#intValue()} should return |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
67 * <code>42</code>. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
68 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
69 * @return name of globally exported symbol |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
70 */ |
21691
99588c43c4b8
Making TruffleTCK abstract after skipping abstract test classes in GraalJUnitCore
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21690
diff
changeset
|
71 protected abstract String fourtyTwo(); |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
72 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
73 /** |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
74 * Name of a function that returns <code>null</code>. Truffle languages are encouraged to have |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
75 * their own type representing <code>null</code>, but when such value is returned from |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
76 * {@link TruffleVM#eval}, it needs to be converted to real Java <code>null</code> by sending a |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
77 * foreign access <em>isNull</em> message. There is a test to verify it is really true. |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
78 * |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
79 * @return name of globally exported symbol |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
80 */ |
21692
c8418635b575
Verifying behavior of TruffleLanguage when it faces invalid source code.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
diff
changeset
|
81 protected abstract String returnsNull(); |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
82 |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
83 /** |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
84 * Name of function to add two integer values together. The symbol will be invoked with two |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
85 * parameters of type {@link Integer} and expects result of type {@link Number} which's |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 * {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
87 * |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
88 * @return name of globally exported symbol |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
89 */ |
21691
99588c43c4b8
Making TruffleTCK abstract after skipping abstract test classes in GraalJUnitCore
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21690
diff
changeset
|
90 protected abstract String plusInt(); |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
91 |
21690
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
92 /** |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
93 * Return a code snippet that is invalid in your language. Its |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
94 * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
95 * an exception. |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
96 * |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
97 * @return code snippet invalid in the tested language |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
98 */ |
21691
99588c43c4b8
Making TruffleTCK abstract after skipping abstract test classes in GraalJUnitCore
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21690
diff
changeset
|
99 protected abstract String invalidCode(); |
21690
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
100 |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
101 private TruffleVM vm() throws Exception { |
21490
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
102 if (tckVM == null) { |
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
103 tckVM = prepareVM(); |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
104 } |
21490
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
105 return tckVM; |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
106 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
107 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
108 // |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
109 // The tests |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
110 // |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
111 |
21490
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
112 @Test |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
113 public void testFortyTwo() throws Exception { |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
114 TruffleVM.Symbol fourtyTwo = findGlobalSymbol(fourtyTwo()); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
115 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
116 Object res = fourtyTwo.invoke(null); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
117 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
118 assert res instanceof Number : "should yield a number, but was: " + res; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
119 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
120 Number n = (Number) res; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
121 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
122 assert 42 == n.intValue() : "The value is 42 = " + n.intValue(); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
123 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
124 |
21490
3286fb5fea4a
Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21468
diff
changeset
|
125 @Test |
21689
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
126 public void testNull() throws Exception { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
127 if (getClass() == TruffleTCK.class) { |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
128 return; |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
129 } |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
130 TruffleVM.Symbol retNull = findGlobalSymbol(returnsNull()); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
131 |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
132 Object res = retNull.invoke(null); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
133 |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
134 assertNull("Should yield real Java null", res); |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
135 } |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
136 |
ed234a3178af
Behavior of null-like values is now part of the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21557
diff
changeset
|
137 @Test |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
138 public void testPlusWithInts() throws Exception { |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
139 Random r = new Random(); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
140 int a = r.nextInt(100); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
141 int b = r.nextInt(100); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
142 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
143 TruffleVM.Symbol plus = findGlobalSymbol(plusInt()); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
144 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
145 Object res = plus.invoke(null, a, b); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
146 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
147 assert res instanceof Number : "+ on two ints should yield a number, but was: " + res; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
148 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
149 Number n = (Number) res; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
150 |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
151 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
152 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
153 |
21690
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
154 @Test(expected = IOException.class) |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
155 public void testInvalidTestMethod() throws Exception { |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
156 String mime = mimeType(); |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
157 String code = invalidCode(); |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
158 Object ret = vm().eval(mime, code); |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
159 fail("Should yield IOException, but returned " + ret); |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
160 } |
e59895e16377
TCK now checks behavior when parsing unparseable code
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21490
diff
changeset
|
161 |
21468
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
162 private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception { |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
163 TruffleVM.Symbol s = vm().findGlobalSymbol(name); |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
164 assert s != null : "Symbol " + name + " is not found!"; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
165 return s; |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
166 } |
99942eac9c6d
Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
167 } |