# HG changeset patch # User Jaroslav Tulach # Date 1432716546 -7200 # Node ID e59895e16377d088766f4be44a1a6b49e5cb1d2c # Parent 12e3d0dfffeb37fe2636612e26bff9ce967217ba TCK now checks behavior when parsing unparseable code diff -r 12e3d0dfffeb -r e59895e16377 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/TruffleTCK.java --- 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 * 42. @@ -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!"; diff -r 12e3d0dfffeb -r e59895e16377 graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTckTest.java --- 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 + } + } diff -r 12e3d0dfffeb -r e59895e16377 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java --- 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; }