Major refactoring of package names, class names
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import lua.StackState;
|
||||
import lua.addon.luacompat.LuaCompat;
|
||||
import lua.addon.luajava.LuaJava;
|
||||
import lua.io.Closure;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
import lua.value.LString;
|
||||
import lua.value.LValue;
|
||||
|
||||
/**
|
||||
* Program to run a compiled lua chunk for test purposes,
|
||||
* but with the LuaJava add-ons added in
|
||||
*
|
||||
* @author jim_roseborough
|
||||
*/
|
||||
public class LuaJavaAppRunner {
|
||||
|
||||
public static void main( String[] args ) throws IOException {
|
||||
|
||||
// add LuaCompat bindings
|
||||
LuaCompat.install();
|
||||
|
||||
// add LuaJava bindings
|
||||
LuaJava.install();
|
||||
|
||||
// get script name
|
||||
String script = (args.length>0? args[0]: "/swingapp.luac");
|
||||
System.out.println("loading '"+script+"'");
|
||||
|
||||
// new lua state
|
||||
StackState state = new StackState();
|
||||
|
||||
// load the file
|
||||
InputStream is = LuaJavaAppRunner.class.getResourceAsStream( script );
|
||||
Proto p = LoadState.undump(state, is, script);
|
||||
|
||||
// create closure and execute
|
||||
Closure c = new Closure( state, p );
|
||||
state.doCall(c, new LValue[0]);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import lua.StackState;
|
||||
import lua.VM;
|
||||
import lua.addon.luacompat.LuaCompat;
|
||||
import lua.addon.luajava.LuaJava;
|
||||
import lua.debug.DebugStackState;
|
||||
import lua.io.Closure;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
import lua.value.LValue;
|
||||
|
||||
/**
|
||||
* Program to run a compiled lua chunk for test purposes
|
||||
*
|
||||
* @author jim_roseborough
|
||||
*/
|
||||
public class LuacRunner {
|
||||
|
||||
public static void main( String[] args ) throws IOException {
|
||||
|
||||
// get script name
|
||||
String script = (args.length>0? args[0]: "/test2.luac");
|
||||
System.out.println("loading '"+script+"'");
|
||||
|
||||
// add LuaCompat bindings
|
||||
LuaCompat.install();
|
||||
LuaJava.install();
|
||||
|
||||
// new lua state
|
||||
StackState state = new StackState();
|
||||
VM vm = state;
|
||||
|
||||
// load the file
|
||||
InputStream is = LuacRunner.class.getResourceAsStream( script );
|
||||
Proto p = LoadState.undump(state, is, script);
|
||||
|
||||
// create closure and execute
|
||||
Closure c = new Closure( state, p );
|
||||
|
||||
// do the call
|
||||
vm.doCall( c, new LValue[0] );
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
|
||||
public class SampleClass {
|
||||
|
||||
public String s;
|
||||
public String t;
|
||||
|
||||
public SampleClass() {
|
||||
}
|
||||
|
||||
public SampleClass(String a, String b) {
|
||||
s = a;
|
||||
t = b;
|
||||
}
|
||||
|
||||
public String getS() {
|
||||
return s;
|
||||
}
|
||||
|
||||
public void setS(String s) {
|
||||
this.s = s;
|
||||
}
|
||||
}
|
||||
42
src/test/java/org/luaj/AllTests.java
Normal file
42
src/test/java/org/luaj/AllTests.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.luaj;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class AllTests {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("Test for org.luaj");
|
||||
|
||||
// compiler tests
|
||||
TestSuite compiler = new TestSuite("Compiler");
|
||||
compiler.addTestSuite(org.luaj.compiler.SimpleTests.class);
|
||||
compiler.addTestSuite(org.luaj.compiler.RegressionTests.class);
|
||||
compiler.addTestSuite(org.luaj.compiler.CompilerUnitTests.class);
|
||||
suite.addTest(compiler);
|
||||
|
||||
// debug tests
|
||||
TestSuite debug = new TestSuite("Debug");
|
||||
debug.addTestSuite(org.luaj.debug.DebugEventTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.DebugRequestTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.DebugResponseTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.DebugStackStateTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.EnumTypeTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.StackFrameTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.TableVariableTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.VariableTest.class);
|
||||
debug.addTestSuite(org.luaj.debug.j2se.LuaJVMTest.class);
|
||||
suite.addTest(debug);
|
||||
|
||||
// debug tests
|
||||
TestSuite vm = new TestSuite("VM");
|
||||
vm.addTestSuite(org.luaj.vm.LoadStateTest.class);
|
||||
vm.addTestSuite(org.luaj.vm.LStringTest.class);
|
||||
vm.addTestSuite(org.luaj.vm.LTableTest.class);
|
||||
vm.addTestSuite(org.luaj.vm.LuaJTest.class);
|
||||
suite.addTest(vm);
|
||||
|
||||
return suite;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package lua.addon.compile;
|
||||
package org.luaj.compiler;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -9,14 +9,15 @@ import java.io.PrintStream;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
|
||||
import org.luaj.compiler.Compiler;
|
||||
import org.luaj.compiler.DumpState;
|
||||
import org.luaj.debug.Print;
|
||||
import org.luaj.vm.LoadState;
|
||||
import org.luaj.vm.LPrototype;
|
||||
import org.luaj.vm.LuaState;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import lua.Print;
|
||||
import lua.StackState;
|
||||
import lua.addon.compile.Compiler;
|
||||
import lua.addon.compile.DumpState;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
|
||||
abstract
|
||||
public class AbstractUnitTests extends TestCase {
|
||||
@@ -37,12 +38,12 @@ public class AbstractUnitTests extends TestCase {
|
||||
|
||||
// compile in memory
|
||||
InputStream is = new ByteArrayInputStream( lua );
|
||||
Proto p = Compiler.compile(is, dir+"/"+file);
|
||||
LPrototype p = Compiler.compile(is, dir+"/"+file);
|
||||
String actual = protoToString( p );
|
||||
|
||||
// load expected value from jar
|
||||
byte[] luac = bytesFromJar( path + "c" );
|
||||
Proto e = loadFromBytes( luac, file );
|
||||
LPrototype e = loadFromBytes( luac, file );
|
||||
String expected = protoToString( e );
|
||||
|
||||
// compare results
|
||||
@@ -54,7 +55,7 @@ public class AbstractUnitTests extends TestCase {
|
||||
byte[] dumped = baos.toByteArray();
|
||||
|
||||
// re-undump
|
||||
Proto p2 = loadFromBytes( dumped, file );
|
||||
LPrototype p2 = loadFromBytes( dumped, file );
|
||||
String actual2 = protoToString( p2 );
|
||||
|
||||
// compare again
|
||||
@@ -77,13 +78,13 @@ public class AbstractUnitTests extends TestCase {
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
protected Proto loadFromBytes(byte[] bytes, String script) throws IOException {
|
||||
StackState state = new StackState();
|
||||
protected LPrototype loadFromBytes(byte[] bytes, String script) throws IOException {
|
||||
LuaState state = new LuaState();
|
||||
InputStream is = new ByteArrayInputStream( bytes );
|
||||
return LoadState.undump(state, is, script);
|
||||
}
|
||||
|
||||
protected String protoToString(Proto p) {
|
||||
protected String protoToString(LPrototype p) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintStream ps = new PrintStream( baos );
|
||||
Print.ps = ps;
|
||||
@@ -1,4 +1,4 @@
|
||||
package lua.addon.compile;
|
||||
package org.luaj.compiler;
|
||||
|
||||
|
||||
public class CompilerUnitTests extends AbstractUnitTests {
|
||||
@@ -1,4 +1,4 @@
|
||||
package lua.addon.compile;
|
||||
package org.luaj.compiler;
|
||||
|
||||
/**
|
||||
* Framework to add regression tests as problem areas are found.
|
||||
@@ -1,28 +1,30 @@
|
||||
package lua.addon.compile;
|
||||
package org.luaj.compiler;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.luaj.compiler.Compiler;
|
||||
import org.luaj.debug.Print;
|
||||
import org.luaj.vm.LClosure;
|
||||
import org.luaj.vm.LValue;
|
||||
import org.luaj.vm.LPrototype;
|
||||
import org.luaj.vm.LuaState;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.Print;
|
||||
import lua.StackState;
|
||||
import lua.io.Closure;
|
||||
import lua.io.Proto;
|
||||
import lua.value.LValue;
|
||||
|
||||
public class SimpleTests extends TestCase {
|
||||
|
||||
private void doTest( String script ) {
|
||||
try {
|
||||
InputStream is = new ByteArrayInputStream( script.getBytes("UTF8") );
|
||||
Proto p = Compiler.compile( is, "script" );
|
||||
LPrototype p = Compiler.compile( is, "script" );
|
||||
assertNotNull( p );
|
||||
Print.printCode( p );
|
||||
|
||||
// try running the code!
|
||||
StackState state = new StackState();
|
||||
Closure c = new Closure( state, p );
|
||||
LuaState state = new LuaState();
|
||||
LClosure c = new LClosure( state, p );
|
||||
state.doCall( c, new LValue[0] );
|
||||
} catch ( Exception e ) {
|
||||
fail("i/o exception: "+e );
|
||||
@@ -1,11 +1,13 @@
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
import org.luaj.debug.event.DebugEvent;
|
||||
import org.luaj.debug.event.DebugEventBreakpoint;
|
||||
import org.luaj.debug.event.DebugEventType;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.debug.event.DebugEvent;
|
||||
import lua.debug.event.DebugEventBreakpoint;
|
||||
import lua.debug.event.DebugEventType;
|
||||
|
||||
public class DebugEventTest extends TestCase {
|
||||
public void testDebugEventSerialization() {
|
||||
@@ -1,12 +1,14 @@
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
import org.luaj.debug.request.DebugRequest;
|
||||
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
||||
import org.luaj.debug.request.DebugRequestStack;
|
||||
import org.luaj.debug.request.DebugRequestType;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.debug.request.DebugRequest;
|
||||
import lua.debug.request.DebugRequestLineBreakpointToggle;
|
||||
import lua.debug.request.DebugRequestStack;
|
||||
import lua.debug.request.DebugRequestType;
|
||||
|
||||
public class DebugRequestTest extends TestCase {
|
||||
public void testDebugRequestSerialization() {
|
||||
@@ -1,12 +1,17 @@
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
import org.luaj.debug.StackFrame;
|
||||
import org.luaj.debug.TableVariable;
|
||||
import org.luaj.debug.Variable;
|
||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||
import org.luaj.debug.response.DebugResponseSimple;
|
||||
import org.luaj.debug.response.DebugResponseStack;
|
||||
import org.luaj.vm.Lua;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.Lua;
|
||||
import lua.debug.response.DebugResponseCallgraph;
|
||||
import lua.debug.response.DebugResponseSimple;
|
||||
import lua.debug.response.DebugResponseVariables;
|
||||
|
||||
public class DebugResponseTest extends TestCase {
|
||||
public void testDebugResponseSimpleSerialization() {
|
||||
@@ -46,10 +51,10 @@ public class DebugResponseTest extends TestCase {
|
||||
|
||||
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
||||
throws IOException {
|
||||
DebugResponseVariables stackIn = new DebugResponseVariables(variables);
|
||||
DebugResponseStack stackIn = new DebugResponseStack(variables);
|
||||
byte[] data = SerializationHelper.serialize(stackIn);
|
||||
DebugResponseVariables stackOut
|
||||
= (DebugResponseVariables) SerializationHelper.deserialize(data);
|
||||
DebugResponseStack stackOut
|
||||
= (DebugResponseStack) SerializationHelper.deserialize(data);
|
||||
Variable[] variablesIn = stackIn.getVariables();
|
||||
Variable[] variablesOut = stackOut.getVariables();
|
||||
assertNotNull(variablesIn);
|
||||
@@ -19,16 +19,18 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.luaj.debug.DebugStackState;
|
||||
import org.luaj.vm.LClosure;
|
||||
import org.luaj.vm.LValue;
|
||||
import org.luaj.vm.LoadState;
|
||||
import org.luaj.vm.LPrototype;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.io.Closure;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
import lua.value.LValue;
|
||||
|
||||
public class DebugStackStateTest extends TestCase {
|
||||
|
||||
@@ -38,10 +40,10 @@ public class DebugStackStateTest extends TestCase {
|
||||
// set up the vm
|
||||
final DebugStackState state = new DebugStackState();
|
||||
InputStream is = getClass().getResourceAsStream( script );
|
||||
Proto p = LoadState.undump(state, is, script);
|
||||
LPrototype p = LoadState.undump(state, is, script);
|
||||
|
||||
// create closure and execute
|
||||
final Closure c = new Closure( state, p );
|
||||
final LClosure c = new LClosure( state, p );
|
||||
|
||||
// suspend the vm right away
|
||||
state.suspend();
|
||||
@@ -1,8 +1,10 @@
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
import org.luaj.debug.event.DebugEventType;
|
||||
import org.luaj.debug.request.DebugRequestType;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.debug.event.DebugEventType;
|
||||
import lua.debug.request.DebugRequestType;
|
||||
|
||||
public class EnumTypeTest extends TestCase {
|
||||
public void testDebugRequestTypeSerialization() {
|
||||
@@ -1,7 +1,10 @@
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
import org.luaj.debug.StackFrame;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class StackFrameTest extends TestCase {
|
||||
@@ -1,15 +1,18 @@
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
import org.luaj.debug.TableVariable;
|
||||
import org.luaj.vm.LBoolean;
|
||||
import org.luaj.vm.LDouble;
|
||||
import org.luaj.vm.LInteger;
|
||||
import org.luaj.vm.LNil;
|
||||
import org.luaj.vm.LString;
|
||||
import org.luaj.vm.LTable;
|
||||
import org.luaj.vm.Lua;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.Lua;
|
||||
import lua.value.LBoolean;
|
||||
import lua.value.LDouble;
|
||||
import lua.value.LInteger;
|
||||
import lua.value.LNil;
|
||||
import lua.value.LString;
|
||||
import lua.value.LTable;
|
||||
|
||||
public class TableVariableTest extends TestCase {
|
||||
public void testCreate() {
|
||||
@@ -1,9 +1,12 @@
|
||||
package lua.debug;
|
||||
package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
import org.luaj.debug.Variable;
|
||||
import org.luaj.vm.Lua;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.Lua;
|
||||
|
||||
public class VariableTest extends TestCase {
|
||||
public void testSerialization() {
|
||||
@@ -19,14 +19,15 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package lua.debug.j2se;
|
||||
package org.luaj.debug.j2se;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.luaj.debug.j2se.StandardLuaJVM;
|
||||
import org.luaj.debug.j2se.StandardLuaJVM.ParseException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.debug.j2se.StandardLuaJVM;
|
||||
import lua.debug.j2se.StandardLuaJVM.ParseException;
|
||||
|
||||
/**
|
||||
* Sanity test for StandardLuaJVM.
|
||||
@@ -1,8 +1,10 @@
|
||||
package lua.value;
|
||||
package org.luaj.vm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.luaj.vm.LString;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class LStringTest extends TestCase {
|
||||
@@ -1,4 +1,11 @@
|
||||
package lua.value;
|
||||
package org.luaj.vm;
|
||||
|
||||
import org.luaj.vm.LDouble;
|
||||
import org.luaj.vm.LInteger;
|
||||
import org.luaj.vm.LNil;
|
||||
import org.luaj.vm.LString;
|
||||
import org.luaj.vm.LTable;
|
||||
import org.luaj.vm.LValue;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package lua.io;
|
||||
package org.luaj.vm;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.luaj.vm.LDouble;
|
||||
import org.luaj.vm.LInteger;
|
||||
import org.luaj.vm.LNumber;
|
||||
import org.luaj.vm.LoadState;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.value.LDouble;
|
||||
import lua.value.LInteger;
|
||||
import lua.value.LNumber;
|
||||
|
||||
public class LoadStateTest extends TestCase {
|
||||
double[] DOUBLE_VALUES = {
|
||||
@@ -1,17 +1,14 @@
|
||||
package lua;
|
||||
package org.luaj.vm;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import lua.addon.luacompat.LuaCompat;
|
||||
import lua.addon.luajava.LuaJava;
|
||||
import lua.debug.DebugStackState;
|
||||
import lua.io.Closure;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
import lua.value.LValue;
|
||||
|
||||
import org.luaj.debug.DebugStackState;
|
||||
import org.luaj.lib.MathLib;
|
||||
import org.luaj.lib.j2se.LuajavaLib;
|
||||
|
||||
|
||||
public class LuaJTest extends TestCase {
|
||||
@@ -43,7 +40,7 @@ public class LuaJTest extends TestCase {
|
||||
public void testTest7() throws IOException, InterruptedException {
|
||||
runTest( "test7" );
|
||||
}
|
||||
|
||||
|
||||
public void testAutoload() throws IOException, InterruptedException {
|
||||
runTest( "autoload" );
|
||||
}
|
||||
@@ -111,30 +108,27 @@ public class LuaJTest extends TestCase {
|
||||
public void testUpvalues2() throws IOException, InterruptedException {
|
||||
runTest( "upvalues2" );
|
||||
}
|
||||
|
||||
|
||||
private void runTest( String testName ) throws IOException, InterruptedException {
|
||||
|
||||
// Reset the _G table just in case some test mucks with it
|
||||
GlobalState.resetGlobals();
|
||||
|
||||
// new lua state
|
||||
LuaState state = new DebugStackState();
|
||||
|
||||
// add LuaJava bindings
|
||||
LuaJava.install();
|
||||
LuajavaLib.install(state._G);
|
||||
|
||||
// add LuaCompat bindings
|
||||
LuaCompat.install();
|
||||
|
||||
// new lua state
|
||||
StackState state = new StackState();
|
||||
MathLib.install(state._G);
|
||||
|
||||
// load the file
|
||||
Proto p = loadScriptResource( state, testName );
|
||||
LPrototype p = loadScriptResource( state, testName );
|
||||
|
||||
// Replace System.out with a ByteArrayOutputStream
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
Builtin.redirectOutput( outputStream );
|
||||
BaseLib.redirectOutput( outputStream );
|
||||
try {
|
||||
// create closure and execute
|
||||
Closure c = new Closure( state, p );
|
||||
LClosure c = new LClosure( p, state._G );
|
||||
state.doCall(c, new LValue[0]);
|
||||
|
||||
final String actualOutput = new String( outputStream.toByteArray() );
|
||||
@@ -142,12 +136,12 @@ public class LuaJTest extends TestCase {
|
||||
|
||||
assertEquals( expectedOutput, actualOutput );
|
||||
} finally {
|
||||
Builtin.restoreStandardOutput();
|
||||
BaseLib.restoreStandardOutput();
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
private Proto loadScriptResource( StackState state, String name ) throws IOException {
|
||||
private LPrototype loadScriptResource( LuaState state, String name ) throws IOException {
|
||||
InputStream script = getClass().getResourceAsStream( "/"+name+".luac" );
|
||||
if ( script == null ) {
|
||||
script = getClass().getResourceAsStream( "/"+name+".lua" );
|
||||
@@ -1,4 +1,4 @@
|
||||
package lua;
|
||||
package org.luaj.vm;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -12,16 +12,9 @@ import java.util.zip.ZipInputStream;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import lua.Builtin;
|
||||
import lua.StackState;
|
||||
import lua.addon.luacompat.LuaCompat;
|
||||
import lua.debug.DebugStackState;
|
||||
import lua.io.Closure;
|
||||
import lua.io.LoadState;
|
||||
import lua.io.Proto;
|
||||
import lua.value.LNil;
|
||||
import lua.value.LString;
|
||||
import lua.value.LValue;
|
||||
|
||||
import org.luaj.debug.DebugStackState;
|
||||
import org.luaj.lib.MathLib;
|
||||
|
||||
public class StandardTest extends TestCase {
|
||||
|
||||
@@ -37,7 +30,7 @@ public class StandardTest extends TestCase {
|
||||
while ( ( file = testSuiteArchive.getNextEntry() ) != null ) {
|
||||
final String entryName = file.getName();
|
||||
if ( entryName.endsWith( ".luac" ) ) {
|
||||
Proto p = LoadState.undump( new StackState(), testSuiteArchive, entryName );
|
||||
LPrototype p = LoadState.undump( new LuaState(), testSuiteArchive, entryName );
|
||||
tests.put( entryName.substring( 0, entryName.length() - 5 ), p );
|
||||
} else if ( entryName.endsWith( ".out" ) ) {
|
||||
results.put( entryName.substring( 0, entryName.length() - 4 ), readString( testSuiteArchive ) );
|
||||
@@ -51,7 +44,7 @@ public class StandardTest extends TestCase {
|
||||
|
||||
for ( Iterator keys = tests.keySet().iterator(); keys.hasNext(); ) {
|
||||
String test = (String)keys.next();
|
||||
final Proto code = (Proto)tests.get( test );
|
||||
final LPrototype code = (LPrototype)tests.get( test );
|
||||
final String expectedResult = (String)results.get( test );
|
||||
|
||||
if ( code != null && expectedResult != null ) {
|
||||
@@ -62,29 +55,28 @@ public class StandardTest extends TestCase {
|
||||
return suite;
|
||||
}
|
||||
|
||||
private final Proto code;
|
||||
private final LPrototype code;
|
||||
private final String expectedResult;
|
||||
|
||||
public StandardTest( String name, Proto code, String expectedResult ) {
|
||||
public StandardTest( String name, LPrototype code, String expectedResult ) {
|
||||
super( name );
|
||||
this.code = code;
|
||||
this.expectedResult = expectedResult;
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
GlobalState.resetGlobals();
|
||||
LuaCompat.install();
|
||||
LuaState state = new DebugStackState();
|
||||
MathLib.install(state._G);
|
||||
// hack: it's unpleasant when the test cases fail to terminate;
|
||||
// unfortunately, there is a test in the standard suite that
|
||||
// relies on weak tables having their elements removed by
|
||||
// the garbage collector. Until we implement that, remove the
|
||||
// built-in collectgarbage function.
|
||||
GlobalState.getGlobalsTable().put( "collectgarbage", LNil.NIL );
|
||||
StackState state = new DebugStackState();
|
||||
Closure c = new Closure( state, code );
|
||||
state._G.put( "collectgarbage", LNil.NIL );
|
||||
LClosure c = new LClosure( code, state._G );
|
||||
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
Builtin.redirectOutput( output );
|
||||
BaseLib.redirectOutput( output );
|
||||
try {
|
||||
try {
|
||||
state.doCall( c, new LValue[0] );
|
||||
@@ -94,7 +86,7 @@ public class StandardTest extends TestCase {
|
||||
|
||||
for ( int i = 0; i < ncalls; ++i ) {
|
||||
CallInfo call = state.calls[i];
|
||||
Proto p = call.closure.p;
|
||||
LPrototype p = call.closure.p;
|
||||
int line = p.lineinfo[call.pc-1];
|
||||
String func = call.closure.luaAsString().toJavaString();
|
||||
stackTrace[ncalls - i - 1] = new StackTraceElement(getName(), func, getName()+".lua", line );
|
||||
@@ -110,7 +102,7 @@ public class StandardTest extends TestCase {
|
||||
|
||||
assertEquals( expectedResult, actualResult );
|
||||
} finally {
|
||||
Builtin.restoreStandardOutput();
|
||||
BaseLib.restoreStandardOutput();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
obj = luajava.newInstance("java.lang.Object")
|
||||
print( obj )
|
||||
|
||||
obj = luajava.newInstance("SampleClass")
|
||||
obj = luajava.newInstance("org.luaj.sample.SampleClass")
|
||||
print( obj )
|
||||
obj.s = "Hello"
|
||||
print( obj.s )
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user