changeset 21690:e59895e16377

TCK now checks behavior when parsing unparseable code
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 27 May 2015 10:49:06 +0200
parents 12e3d0dfffeb
children 99588c43c4b8
files graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTckTest.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java
diffstat 3 files changed, 65 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java	Wed May 27 10:18:54 2015 +0200
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java	Wed May 27 10:49:06 2015 +0200
@@ -23,7 +23,9 @@
 package com.oracle.truffle.api.test.vm;
 
 import com.oracle.truffle.api.vm.TruffleVM;
+import java.io.IOException;
 import java.util.Random;
+import static org.junit.Assert.*;
 import org.junit.Test;
 
 /**
@@ -53,6 +55,17 @@
     }
 
     /**
+     * Mimetype associated with your language. The mimetype will be passed to
+     * {@link TruffleVM#eval(java.lang.String, java.lang.String)} method of the {@link #prepareVM()
+     * created TruffleVM}.
+     *
+     * @return mime type of the tested language
+     */
+    protected String mimeType() { // abstract
+        return null;
+    }
+
+    /**
      * Name of function which will return value 42 as a number. The return value of the method
      * should be instance of {@link Number} and its {@link Number#intValue()} should return
      * <code>42</code>.
@@ -74,6 +87,17 @@
         return null;
     }
 
+    /**
+     * Return a code snippet that is invalid in your language. Its
+     * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield
+     * an exception.
+     *
+     * @return code snippet invalid in the tested language
+     */
+    protected String invalidCode() { // abstract
+        return null;
+    }
+
     private TruffleVM vm() throws Exception {
         if (tckVM == null) {
             tckVM = prepareVM();
@@ -121,6 +145,17 @@
         assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") =  " + n.intValue();
     }
 
+    @Test(expected = IOException.class)
+    public void testInvalidTestMethod() throws Exception {
+        if (getClass() == TruffleTCK.class) {
+            return;
+        }
+        String mime = mimeType();
+        String code = invalidCode();
+        Object ret = vm().eval(mime, code);
+        fail("Should yield IOException, but returned " + ret);
+    }
+
     private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception {
         TruffleVM.Symbol s = vm().findGlobalSymbol(name);
         assert s != null : "Symbol " + name + " is not found!";
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTckTest.java	Wed May 27 10:18:54 2015 +0200
+++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTckTest.java	Wed May 27 10:49:06 2015 +0200
@@ -41,18 +41,25 @@
     @Override
     protected TruffleVM prepareVM() throws Exception {
         TruffleVM vm = TruffleVM.newVM().build();
-        vm.eval("application/x-sl", // your langage
-                        "function fourtyTwo() {\n" + // your script
-                                        "  return 42;\n" + //
-                                        "}\n" + //
-                                        "function plus(a, b) {\n" + //
-                                        "  return a + b;\n" + //
-                                        "}\n" //
+        // @formatter:off
+        vm.eval("application/x-sl",
+            "function fourtyTwo() {\n" +
+            "  return 42;\n" +
+            "}\n" +
+            "function plus(a, b) {\n" +
+            "  return a + b;\n" +
+            "}\n"
         );
+        // @formatter:on
         return vm;
     }
 
     @Override
+    protected String mimeType() {
+        return "application/x-sl";
+    }
+
+    @Override
     protected String fourtyTwo() {
         return "fourtyTwo";
     }
@@ -61,4 +68,15 @@
     protected String plusInt() {
         return "plus";
     }
+
+    @Override
+    protected String invalidCode() {
+        // @formatter:off
+        return
+            "f unction main() {\n" +
+            "  retu rn 42;\n" +
+            "}\n";
+        // @formatter:on
+    }
+
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Wed May 27 10:18:54 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Wed May 27 10:49:06 2015 +0200
@@ -372,7 +372,11 @@
 
     @Override
     protected Object eval(Source code) throws IOException {
-        context.executeMain(code);
+        try {
+            context.executeMain(code);
+        } catch (Exception e) {
+            throw new IOException(e);
+        }
         return null;
     }