changeset 13762:e34d5cca7496

Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
author Christian Wimmer <christian.wimmer@oracle.com>
date Fri, 24 Jan 2014 18:18:49 -0800
parents 7c418666c6c9
children cad8bed1a1ac
files graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AbstractTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AddTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/BuiltinsTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/CallTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/ComparisonTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/DivTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/FibonacciTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopPrintTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/MulTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SubTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SumTest.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/TernaryTest.java graal/com.oracle.truffle.sl.test/tests/Add.output graal/com.oracle.truffle.sl.test/tests/Add.sl graal/com.oracle.truffle.sl.test/tests/Arithmetic.output graal/com.oracle.truffle.sl.test/tests/Arithmetic.sl graal/com.oracle.truffle.sl.test/tests/Builtins.output graal/com.oracle.truffle.sl.test/tests/Builtins.sl graal/com.oracle.truffle.sl.test/tests/Call.output graal/com.oracle.truffle.sl.test/tests/Call.sl graal/com.oracle.truffle.sl.test/tests/Comparison.output graal/com.oracle.truffle.sl.test/tests/Comparison.sl graal/com.oracle.truffle.sl.test/tests/DefineFunction.output graal/com.oracle.truffle.sl.test/tests/DefineFunction.sl graal/com.oracle.truffle.sl.test/tests/Div.output graal/com.oracle.truffle.sl.test/tests/Div.sl graal/com.oracle.truffle.sl.test/tests/Fibonacci.output graal/com.oracle.truffle.sl.test/tests/Fibonacci.sl graal/com.oracle.truffle.sl.test/tests/Loop.output graal/com.oracle.truffle.sl.test/tests/Loop.sl graal/com.oracle.truffle.sl.test/tests/LoopPrint.output graal/com.oracle.truffle.sl.test/tests/LoopPrint.sl graal/com.oracle.truffle.sl.test/tests/Mul.output graal/com.oracle.truffle.sl.test/tests/Mul.sl graal/com.oracle.truffle.sl.test/tests/Sub.output graal/com.oracle.truffle.sl.test/tests/Sub.sl graal/com.oracle.truffle.sl.test/tests/Sum.output graal/com.oracle.truffle.sl.test/tests/Sum.sl
diffstat 40 files changed, 319 insertions(+), 720 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AbstractTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import java.io.*;
-
-import org.junit.*;
-
-import com.oracle.truffle.sl.*;
-
-public class AbstractTest {
-
-    public static final int REPEATS = 10;
-    private static final String NEWLINE = System.getProperty("line.separator");
-
-    private static String concat(String[] string) {
-        StringBuilder result = new StringBuilder();
-        for (String s : string) {
-            result.append(s).append(NEWLINE);
-        }
-        return result.toString();
-    }
-
-    private static String repeat(String s, int count) {
-        StringBuilder result = new StringBuilder(s.length() * count);
-        for (int i = 0; i < count; i++) {
-            result.append(s);
-        }
-        return result.toString();
-    }
-
-    protected static void executeSL(String[] input, String[] expectedOutput, boolean useConsole) {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        PrintStream printer = new PrintStream(useConsole ? new SplitOutputStream(out, System.err) : out);
-        PrintStream origErr = System.err;
-        System.setErr(printer);
-
-        SimpleLanguage.run("(test)", concat(input), printer, REPEATS, false);
-
-        System.setErr(origErr);
-        Assert.assertEquals(repeat(concat(expectedOutput), REPEATS), new String(out.toByteArray()));
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/AddTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class AddTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  print(3 + 4);  ",
-        "  print(3 + \"4\");  ",
-        "  print(\"3\" + 4);  ",
-        "  print(\"3\" + \"4\");  ",
-        "  print(3 + 4000000000000);  ",
-        "  print(3000000000000 + 4);  ",
-        "  print(3000000000000 + 4000000000000);  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "7",
-        "34",
-        "34",
-        "34",
-        "4000000000003",
-        "3000000000004",
-        "7000000000000",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/BuiltinsTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class BuiltinsTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  print(\"Hello World!\");  ",
-        "  time();  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "Hello World!",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/CallTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class CallTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function ret(a) { return a; } ",
-        "function dub(a) { return a * 2; } ",
-        "function inc(a) { return a + 1; } ",
-        "function dec(a) { return a - 1; } ",
-        "function call(f, v) { return f(v); } ",
-        "function main {  ",
-        "  print(ret(42));",
-        "  print(dub(21));",
-        "  print(inc(41));",
-        "  print(dec(43));",
-        "  print(call(ret, 42));",
-        "  print(call(dub, 21));",
-        "  print(call(inc, 41));",
-        "  print(call(dec, 43));",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "42",
-        "42",
-        "42",
-        "42",
-        "42",
-        "42",
-        "42",
-        "42",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/ComparisonTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class ComparisonTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  print(4 < 20);  ",
-        "  print(4 < \"20\");  ",
-        "  print(\"4\" < 20);  ",
-        "  print(\"4\" < \"20\");  ",
-        "  print(4 < 20000000000000);  ",
-        "  print(4000000000000 < 20);  ",
-        "  print(4000000000000 < 20000000000000);  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "true",
-        "false",
-        "false",
-        "false",
-        "true",
-        "false",
-        "true",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/DivTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class DivTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  print(4 / 2);  ",
-        "  print(4 / 4000000000000);  ",
-        "  print(3000000000000 / 3);  ",
-        "  print(3000000000000 / 3000000000000);  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "2",
-        "0",
-        "1000000000000",
-        "1",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/FibonacciTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,89 +0,0 @@
-/*
- * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import javax.script.*;
-
-import org.junit.*;
-
-import com.oracle.truffle.api.*;
-import com.oracle.truffle.sl.*;
-import com.oracle.truffle.sl.runtime.*;
-
-// @formatter:off
-public class FibonacciTest extends AbstractTest{
-
-    private static String[] INPUT = new String[] {
-        "function fib(num) { ",
-        "  if (num < 1) {return 0;}",
-        "  n1 = 0;",
-        "  n2 = 1;",
-        "  i = 1;",
-        "  while (i < num) {",
-        "    next = n2 + n1;",
-        "    n1 = n2;",
-        "    n2 = next;",
-        "    i = i + 1;",
-        "  }",
-        "  return n2;",
-        "}",
-        "function main(num) {  ",
-        "  return fib(num);",
-        "}  ",
-    };
-
-    // java reference
-    private static int test(int num) {
-        if (num <= 0) {
-            return 0;
-        }
-        int n1 = 0;
-        int n2 = 1;
-        for (int i = 1; i < num; i++) {
-            final int next = n2 + n1;
-            n1 = n2;
-            n2 = next;
-        }
-        return n2;
-    }
-
-    private static final int TEST_VALUE = 42;
-    private static final int ITERATIONS = 5000;
-
-    @Test
-    public void test() throws ScriptException {
-        StringBuilder s = new StringBuilder();
-        for (String line : INPUT) {
-            s.append(line).append("\n");
-        }
-        final SLContext context = new SLContext(System.out);
-        final Source source = context.getSourceManager().get("(fib test)", s.toString());
-        SLScript script = SLScript.create(context, source);
-        Integer reference = test(TEST_VALUE);
-        for (int i = 0; i < ITERATIONS; i++) {
-            if (!reference.equals(script.run(TEST_VALUE))) {
-                throw new AssertionError();
-            }
-        }
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopPrintTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class LoopPrintTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  i = 0;  ",
-        "  while (i < 1000) {  ",
-        "    i = i + 1;  ",
-        "  }  ",
-        "  print(i);  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "1000",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/LoopTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class LoopTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  i = 0;  ",
-        "  while (i < 1000) {  ",
-        "    i = i + 1;  ",
-        "  }  ",
-        "  return i;  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "1000",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/MulTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class MulTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  print(3 * 4);  ",
-        "  print(3 * 4000000000000);  ",
-        "  print(3000000000000 * 4);  ",
-        "  print(3000000000000 * 4000000000000);  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "12",
-        "12000000000000",
-        "12000000000000",
-        "12000000000000000000000000",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.truffle.sl.test;
+
+import java.io.*;
+import java.nio.file.*;
+import java.nio.file.attribute.*;
+import java.util.*;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.source.*;
+import com.oracle.truffle.sl.*;
+import com.oracle.truffle.sl.runtime.*;
+
+public class SLTestRunner {
+
+    private static final int REPEATS = 10;
+    private static final String TEST_DIR = "tests";
+    private static final String INPUT_SUFFIX = ".sl";
+    private static final String OUTPUT_SUFFIX = ".output";
+
+    static class TestCase {
+        protected final String name;
+        protected final Source input;
+        protected final String expectedOutput;
+        protected String actualOutput;
+
+        protected TestCase(String name, Source input, String expectedOutput) {
+            this.name = name;
+            this.input = input;
+            this.expectedOutput = expectedOutput;
+        }
+    }
+
+    protected boolean useConsole = false;
+
+    protected final SourceManager sourceManager = new SourceManager();
+    protected final List<TestCase> testCases = new ArrayList<>();
+
+    protected boolean runTests(String namePattern) throws IOException {
+        Path testsRoot = FileSystems.getDefault().getPath(TEST_DIR);
+
+        Files.walkFileTree(testsRoot, new SimpleFileVisitor<Path>() {
+            @Override
+            public FileVisitResult visitFile(Path inputFile, BasicFileAttributes attrs) throws IOException {
+                String name = inputFile.getFileName().toString();
+                if (name.endsWith(INPUT_SUFFIX)) {
+                    name = name.substring(0, name.length() - INPUT_SUFFIX.length());
+                    Path outputFile = inputFile.resolveSibling(name + OUTPUT_SUFFIX);
+                    if (!Files.exists(outputFile)) {
+                        throw new Error("Output file does not exist: " + outputFile);
+                    }
+
+                    testCases.add(new TestCase(name, sourceManager.get(inputFile.toString()), new String(Files.readAllBytes(outputFile))));
+                }
+                return FileVisitResult.CONTINUE;
+            }
+        });
+
+        if (testCases.size() == 0) {
+            System.out.format("No test cases match filter %s", namePattern);
+            return false;
+        }
+
+        boolean success = true;
+        for (TestCase testCase : testCases) {
+            if (namePattern.length() == 0 || testCase.name.toLowerCase().contains(namePattern.toLowerCase())) {
+                success = success & executeTest(testCase);
+            }
+        }
+        return success;
+    }
+
+    protected boolean executeTest(TestCase testCase) {
+        System.out.format("Running %s\n", testCase.name);
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        PrintStream printer = new PrintStream(useConsole ? new SplitOutputStream(out, System.err) : out);
+        PrintStream origErr = System.err;
+        try {
+            System.setErr(printer);
+            SLContext context = new SLContext(sourceManager, printer);
+            SLMain.run(context, testCase.input, null, REPEATS);
+        } catch (Throwable ex) {
+            ex.printStackTrace(printer);
+        } finally {
+            System.setErr(origErr);
+        }
+        testCase.actualOutput = new String(out.toByteArray());
+
+        if (testCase.actualOutput.equals(repeat(testCase.expectedOutput, REPEATS))) {
+            System.out.format("OK %s\n", testCase.name);
+            return true;
+        } else {
+            if (!useConsole) {
+                System.out.format("== Expected ==\n%s\n", testCase.expectedOutput);
+                System.out.format("== Actual ==\n%s\n", testCase.actualOutput);
+            }
+            System.out.format("FAILED %s\n", testCase.name);
+            return false;
+        }
+    }
+
+    private static String repeat(String s, int count) {
+        StringBuilder result = new StringBuilder(s.length() * count);
+        for (int i = 0; i < count; i++) {
+            result.append(s);
+        }
+        return result.toString();
+    }
+
+    public static void main(String[] args) throws IOException {
+        String namePattern = "";
+        if (args.length > 0) {
+            namePattern = args[0];
+        }
+        boolean success = new SLTestRunner().runTests(namePattern);
+        if (!success) {
+            System.exit(1);
+        }
+    }
+
+    @Test
+    public void test() throws IOException {
+        Assert.assertTrue(runTests(""));
+    }
+}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SubTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class SubTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  print(3 - 4);  ",
-        "  print(3 - 4000000000000);  ",
-        "  print(3000000000000 - 4);  ",
-        "  print(3000000000000 - 4000000000000);  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "-1",
-        "-3999999999997",
-        "2999999999996",
-        "-1000000000000",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SumTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class SumTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  ",
-        "  i = 0;  ",
-        "  sum = 0;  ",
-        "  while (i < 100000) {  ",
-        "    sum = sum + 1000000;  ",
-        "    i = i + 1;  ",
-        "  }  ",
-        "  return sum;  ",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "100000000000",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/TernaryTest.java	Fri Jan 24 18:16:24 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.truffle.sl.test;
-
-import org.junit.*;
-
-// @formatter:off
-public class TernaryTest extends AbstractTest {
-
-    private static String[] INPUT = new String[] {
-        "function main {  " +
-        "  print(#(1 < 2) ? 1 : 2);" +
-        "  print(#(2 < 1) ? 100000000000000 : 1);  ",
-        "  print(#(1 < 2) ? 100000000000000 : 1);  ",
-        "  print(#(2 < 1) ? \"wrong\" : \"true\");",
-        "  print(#(2 < 1) ? \"wrong\" : 1);",
-        "}  ",
-    };
-
-    private static String[] OUTPUT = new String[] {
-        "1",
-        "1",
-        "100000000000000",
-        "true",
-        "1",
-    };
-
-    @Test
-    public void test() {
-        executeSL(INPUT, OUTPUT, false);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Add.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,7 @@
+7
+34
+34
+34
+4000000000003
+3000000000004
+7000000000000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Add.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,9 @@
+function main() {  
+  print(3 + 4);  
+  print(3 + "4");  
+  print("3" + 4);  
+  print("3" + "4");  
+  print(3 + 4000000000000);  
+  print(3000000000000 + 4);  
+  print(3000000000000 + 4000000000000);  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Arithmetic.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,10 @@
+5
+1
+-3
+14
+11
+5
+-3
+1
+18
+11
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Arithmetic.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,12 @@
+function main() {  
+  print(3 + 4 - 2);  
+  print(3 - 4 + 2);  
+  print(3 - 4 - 2);  
+  print(3 * 4 + 2);  
+  print(3 + 4 * 2);  
+  print(3 + (4 - 2));  
+  print(3 - (4 + 2));  
+  print(3 - (4 - 2));  
+  print(3 * (4 + 2));  
+  print(3 + (4 * 2));  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Builtins.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,1 @@
+Hello World!
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Builtins.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,4 @@
+function main() {  
+  print("Hello World!");  
+  time();  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Call.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,8 @@
+42
+42
+42
+42
+42
+42
+42
+42
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Call.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,16 @@
+function ret(a) { return a; } 
+function dub(a) { return a * 2; } 
+function inc(a) { return a + 1; } 
+function dec(a) { return a - 1; } 
+function call(f, v) { return f(v); }
+ 
+function main() {  
+  print(ret(42));
+  print(dub(21));
+  print(inc(41));
+  print(dec(43));
+  print(call(ret, 42));
+  print(call(dub, 21));
+  print(call(inc, 41));
+  print(call(dec, 43));
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Comparison.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,7 @@
+true
+false
+false
+false
+true
+false
+true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Comparison.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,9 @@
+function main() {  
+  print(4 < 20);  
+  print(4 < "20");  
+  print("4" < 20);  
+  print("4" < "20");  
+  print(4 < 20000000000000);  
+  print(4000000000000 < 20);  
+  print(4000000000000 < 20000000000000);  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/DefineFunction.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,2 @@
+42
+38
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/DefineFunction.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,11 @@
+function foo() {
+  print(test(40, 2));
+}
+
+function main() {
+  defineFunction("function test(a, b) { return a + b; }");
+  foo();
+
+  defineFunction("function test(a, b) { return a - b; }");
+  foo();
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Div.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,4 @@
+2
+0
+1000000000000
+1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Div.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,6 @@
+function main() {  
+  print(4 / 2);  
+  print(4 / 4000000000000);  
+  print(3000000000000 / 3);  
+  print(3000000000000 / 3000000000000);  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Fibonacci.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,1 @@
+267914296
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Fibonacci.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,17 @@
+function fib(num) { 
+  if (num < 1) {return 0;}
+  n1 = 0;
+  n2 = 1;
+  i = 1;
+  while (i < num) {
+    next = n2 + n1;
+    n1 = n2;
+    n2 = next;
+    i = i + 1;
+  }
+  return n2;
+}
+
+function main() {  
+  print(fib(42));
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Loop.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,1 @@
+1000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Loop.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,7 @@
+function main() {  
+  i = 0;  
+  while (i < 1000) {  
+    i = i + 1;  
+  }  
+  return i;  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/LoopPrint.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,1 @@
+1000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/LoopPrint.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,7 @@
+function main() {  
+  i = 0;  
+  while (i < 1000) {  
+    i = i + 1;  
+  }  
+  print(i);  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Mul.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,4 @@
+12
+12000000000000
+12000000000000
+12000000000000000000000000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Mul.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,6 @@
+function main() {  
+  print(3 * 4);  
+  print(3 * 4000000000000);  
+  print(3000000000000 * 4);  
+  print(3000000000000 * 4000000000000);  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Sub.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,4 @@
+-1
+-3999999999997
+2999999999996
+-1000000000000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Sub.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,6 @@
+function main() {  
+  print(3 - 4);  
+  print(3 - 4000000000000);  
+  print(3000000000000 - 4);  
+  print(3000000000000 - 4000000000000);  
+}  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Sum.output	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,1 @@
+100000000000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.sl.test/tests/Sum.sl	Fri Jan 24 18:18:49 2014 -0800
@@ -0,0 +1,9 @@
+function main() {  
+  i = 0;  
+  sum = 0;  
+  while (i < 100000) {  
+    sum = sum + 1000000;  
+    i = i + 1;  
+  }  
+  return sum;  
+}