From 5536159916b36d4521017aa266313ffb87fb74f4 Mon Sep 17 00:00:00 2001 From: Ian Farmer Date: Sun, 23 Sep 2007 03:51:26 +0000 Subject: [PATCH] Now that compiler is integrated, change LuaJTest to load source files when pre-compiled script is missing. --- src/test/java/lua/LuaJTest.java | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/test/java/lua/LuaJTest.java b/src/test/java/lua/LuaJTest.java index d9b73da8..3ceba4b3 100644 --- a/src/test/java/lua/LuaJTest.java +++ b/src/test/java/lua/LuaJTest.java @@ -64,6 +64,10 @@ public class LuaJTest extends TestCase { runTest( "compare" ); } + public void testMathLib() throws IOException, InterruptedException { + runTest( "mathlib" ); + } + public void testMetatables() throws IOException, InterruptedException { runTest( "metatables" ); } @@ -107,7 +111,7 @@ public class LuaJTest extends TestCase { StackState state = new StackState(); // load the file - Proto p = loadScriptResource( state, testName, "/" + testName + ".luac" ); + Proto p = loadScriptResource( state, testName ); // Replace System.out with a ByteArrayOutputStream ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -127,12 +131,19 @@ public class LuaJTest extends TestCase { } } - private Proto loadScriptResource( StackState state, String name, String path ) throws IOException { - InputStream compiledScript = getClass().getResourceAsStream( path ); + private Proto loadScriptResource( StackState state, String name ) throws IOException { + InputStream script = getClass().getResourceAsStream( "/"+name+".luac" ); + if ( script == null ) { + script = getClass().getResourceAsStream( "/"+name+".lua" ); + if ( script == null ) { + fail( "Could not load script for test case: "+name ); + } + } + try { - return LoadState.undump(state, compiledScript, name); + return LoadState.undump(state, script, name); } finally { - compiledScript.close(); + script.close(); } } @@ -147,6 +158,12 @@ public class LuaJTest extends TestCase { } } else { InputStream script = getClass().getResourceAsStream( "/" + testName + ".luac" ); + if ( script == null ) { + script = getClass().getResourceAsStream( "/" + testName + ".lua" ); + if ( script == null ) { + fail( "Could not find script for test case: "+testName ); + } + } try { return collectProcessOutput( new String[] { "lua", "-" }, script ); } finally {