Remove project dependency on luaj vm1

This commit is contained in:
James Roseborough
2010-05-14 14:32:02 +00:00
parent 36845ba1b4
commit 6296068a49
5 changed files with 33 additions and 15 deletions

View File

@@ -42,7 +42,7 @@
</unzip> </unzip>
</target> </target>
<target name="compile" depends="wtk-or-fail,bcel-lib,luaj1-lib"> <target name="compile" depends="wtk-or-fail,bcel-lib">
<mkdir dir="build/core/src"/> <mkdir dir="build/core/src"/>
<mkdir dir="build/core/classes"/> <mkdir dir="build/core/classes"/>
<mkdir dir="build/jme/classes"/> <mkdir dir="build/jme/classes"/>

View File

@@ -24,7 +24,6 @@ package org.luaj.vm2;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.luajc.LuaJC; import org.luaj.vm2.luajc.LuaJC;
/** /**

View File

@@ -162,7 +162,7 @@ public class ScriptDrivenTest extends TestCase {
} }
} }
private String collectProcessOutput(String[] cmd, final InputStream input) public static String collectProcessOutput(String[] cmd, final InputStream input)
throws IOException, InterruptedException { throws IOException, InterruptedException {
Runtime r = Runtime.getRuntime(); Runtime r = Runtime.getRuntime();
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -237,7 +237,7 @@ public class ScriptDrivenTest extends TestCase {
return new String(baos.toByteArray()); return new String(baos.toByteArray());
} }
private void copy(InputStream is, OutputStream os) throws IOException { private static void copy(InputStream is, OutputStream os) throws IOException {
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int r; int r;
while ((r = is.read(buf)) >= 0) { while ((r = is.read(buf)) >= 0) {

View File

@@ -33,24 +33,28 @@ import junit.framework.TestCase;
import org.luaj.vm2.LuaThread; import org.luaj.vm2.LuaThread;
import org.luaj.vm2.LuaValue; import org.luaj.vm2.LuaValue;
import org.luaj.vm2.ScriptDrivenTest;
/** /**
* Test for compatiblity between luaj 1.0 and 2.0 vms * Test for compatiblity between luaj 1.0 and 2.0.
* *
* Runs an archive of the tests that were used in
* the luaj-vm 1.0 development, modified to account
* for changes to interpetation of the lua vm spec.
*/ */
public class Luajvm1CompatibilityTest extends TestCase { public class Luajvm1CompatibilityTest extends TestCase {
private static final String zipfile = "luajvm1-tests.zip"; private static final String zipfile = "luajvm1-tests.zip";
private static String jarpath; private static String jarpath;
private void runTest(String test) { protected void runTest(String test) {
try { try {
URL zip = getClass().getResource(zipfile); URL zip = getClass().getResource(zipfile);
jarpath = "jar:"+zip.toExternalForm()+"!/"; jarpath = "jar:"+zip.toExternalForm()+"!/";
String luaj10 = luaj10Run(test); String lua = luaRun(test);
String luaj20 = luaj20Run(test); String luaj20 = luaj20Run(test);
assertEquals( luaj10, luaj20 ); assertEquals( lua, luaj20 );
} catch ( IOException ioe ) { } catch ( Exception ioe ) {
fail( ioe.toString() ); fail( ioe.toString() );
} }
} }
@@ -65,8 +69,24 @@ public class Luajvm1CompatibilityTest extends TestCase {
return null; return null;
} }
} }
private String luaj10Run(String test) throws IOException { private String luaRun(String test) throws Exception {
InputStream script =open(test+".lua");
if ( script == null )
fail("Could not load script for test case: " + test);
try {
String luaCommand = System.getProperty("LUA_COMMAND");
if ( luaCommand == null )
luaCommand = "lua";
String[] args = new String[] { luaCommand, "-", "jse" };
return ScriptDrivenTest.collectProcessOutput(args, script);
} finally {
script.close();
}
}
/*
private String luaj10Run(String test) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try { try {
org.luaj.vm.Platform.setInstance(new org.luaj.platform.J2sePlatform() { org.luaj.vm.Platform.setInstance(new org.luaj.platform.J2sePlatform() {
@@ -87,7 +107,8 @@ public class Luajvm1CompatibilityTest extends TestCase {
outputStream.close(); outputStream.close();
} }
} }
*/
private String luaj20Run(String test) throws IOException { private String luaj20Run(String test) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream( outputStream ); PrintStream printStream = new PrintStream( outputStream );
@@ -102,7 +123,7 @@ public class Luajvm1CompatibilityTest extends TestCase {
if ( is == null ) if ( is == null )
return LuaValue.valueOf("not found: "+file); return LuaValue.valueOf("not found: "+file);
try { try {
return org.luaj.vm2.LoadState.load(is, file, env); return org.luaj.vm2.LoadState.load(is, "@stdin", env);
} catch (IOException e) { } catch (IOException e) {
return LuaValue.valueOf(e.toString()); return LuaValue.valueOf(e.toString());
} finally { } finally {
@@ -116,7 +137,6 @@ public class Luajvm1CompatibilityTest extends TestCase {
return outputStream.toString(); return outputStream.toString();
} finally { } finally {
printStream.close(); printStream.close();
// script.close();
} }
} }
@@ -129,7 +149,6 @@ public class Luajvm1CompatibilityTest extends TestCase {
public void testTest4() { runTest("test4"); } public void testTest4() { runTest("test4"); }
public void testTest5() { runTest("test5"); } public void testTest5() { runTest("test5"); }
public void testTest6() { runTest("test6"); } public void testTest6() { runTest("test6"); }
public void testTest7() { runTest("test7"); }
public void testTest8() { runTest("test8"); } public void testTest8() { runTest("test8"); }
public void testTest9() { runTest("test9"); } public void testTest9() { runTest("test9"); }
public void testAutoload() { runTest("autoload"); } public void testAutoload() { runTest("autoload"); }