v 0.44, drop debug support

This commit is contained in:
James Roseborough
2008-08-06 20:38:15 +00:00
parent f42e8ef051
commit 4a87bae45d
52 changed files with 34 additions and 4231 deletions

View File

@@ -27,19 +27,6 @@ public class AllTests {
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);
return suite;
}

View File

@@ -10,7 +10,7 @@ import java.net.URL;
import junit.framework.TestCase;
import org.luaj.TestPlatform;
import org.luaj.debug.Print;
import org.luaj.jit.Print;
import org.luaj.vm.LPrototype;
import org.luaj.vm.LoadState;
import org.luaj.vm.LuaState;

View File

@@ -6,7 +6,7 @@ import java.io.InputStream;
import junit.framework.TestCase;
import org.luaj.TestPlatform;
import org.luaj.debug.Print;
import org.luaj.jit.Print;
import org.luaj.lib.BaseLib;
import org.luaj.vm.LClosure;
import org.luaj.vm.LPrototype;

View File

@@ -1,51 +0,0 @@
package org.luaj.debug;
import java.io.IOException;
import junit.framework.TestCase;
import org.luaj.debug.event.DebugEventBreakpoint;
import org.luaj.debug.event.DebugEventOutputRedirect;
public class DebugEventTest extends TestCase {
public void testDebugEventSerialization() {
try {
DebugMessage event = new DebugMessage(DebugMessageType.started);
byte[] data = SerializationHelper.serialize(event);
DebugMessage eventOut = (DebugMessage) SerializationHelper
.deserialize(data);
assertNotNull(eventOut);
assertEquals(event.getType(), eventOut.getType());
} catch (IOException e) {
fail(e.getMessage());
}
}
public void testDebugEventBreakpointSerialization() {
try {
DebugEventBreakpoint event = new DebugEventBreakpoint("test.lua",
100);
byte[] data = SerializationHelper.serialize(event);
DebugEventBreakpoint eventOut = (DebugEventBreakpoint) SerializationHelper
.deserialize(data);
assertNotNull(eventOut);
assertEquals(event.getSource(), eventOut.getSource());
assertEquals(event.getLineNumber(), eventOut.getLineNumber());
} catch (IOException e) {
fail(e.getMessage());
}
}
public void testDebugEventOutputRedirectSerialization() {
try {
String msg = "This is a testing message";
DebugEventOutputRedirect redirectEvent = new DebugEventOutputRedirect(msg);
byte[] data = SerializationHelper.serialize(redirectEvent);
DebugEventOutputRedirect redirectEventOut = (DebugEventOutputRedirect)
SerializationHelper.deserialize(data);
assertEquals(msg, redirectEventOut.getOutput());
} catch (IOException e) {
fail(e.getMessage());
}
}
}

View File

@@ -1,61 +0,0 @@
package org.luaj.debug;
import java.io.IOException;
import junit.framework.TestCase;
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
import org.luaj.debug.request.DebugRequestStack;
public class DebugRequestTest extends TestCase {
public void testDebugRequestSerialization() {
try {
DebugMessage request = new DebugMessage(DebugMessageType.resume);
byte[] data = SerializationHelper.serialize(request);
DebugMessage requestOut = (DebugMessage) SerializationHelper
.deserialize(data);
assertNotNull(requestOut);
assertEquals(request.getType(), requestOut.getType());
} catch (IOException e) {
fail(e.getMessage());
}
}
public void testDebugRequestStackSerialization() {
try {
DebugRequestStack request = new DebugRequestStack(1);
byte[] data = SerializationHelper.serialize(request);
DebugRequestStack requestOut = (DebugRequestStack) SerializationHelper
.deserialize(data);
assertNotNull(requestOut);
assertEquals(requestOut.getIndex(), 1);
} catch (IOException e) {
fail(e.getMessage());
}
}
public void testDebugRequestLineBreakpointToggleSerialization() {
try {
doTestDebugRequestLineBreakpointToggleSerialization(
DebugMessageType.lineBreakpointSet, "test.lua", 100);
doTestDebugRequestLineBreakpointToggleSerialization(
DebugMessageType.lineBreakpointClear, "test.lua", 50);
} catch (IOException e) {
fail(e.getMessage());
}
}
private void doTestDebugRequestLineBreakpointToggleSerialization(
DebugMessageType type, String source, int lineNo)
throws IOException {
DebugRequestLineBreakpointToggle request = new DebugRequestLineBreakpointToggle(
DebugMessageType.lineBreakpointSet, "test.lua", 100);
byte[] data = SerializationHelper.serialize(request);
DebugRequestLineBreakpointToggle requestOut = (DebugRequestLineBreakpointToggle) SerializationHelper
.deserialize(data);
assertNotNull(requestOut);
assertEquals(request.getType(), requestOut.getType());
assertEquals(request.getSource(), requestOut.getSource());
assertEquals(request.getLineNumber(), requestOut.getLineNumber());
}
}

View File

@@ -1,85 +0,0 @@
package org.luaj.debug;
import java.io.IOException;
import junit.framework.TestCase;
import org.luaj.debug.response.DebugResponseCallgraph;
import org.luaj.debug.response.DebugResponseStack;
import org.luaj.vm.Lua;
public class DebugResponseTest extends TestCase {
public void testDebugResponseStackSerialization() {
try {
doTestDebugResponseStackSerialization(0, null);
doTestDebugResponseStackSerialization(1, new Variable[0]);
Variable[] variables = new Variable[5];
variables[0] = new Variable(0, "variable1", Lua.LUA_TSTRING,
"value1");
variables[1] = new Variable(1, "variable2", Lua.LUA_TNIL, "nil");
variables[2] = new Variable(2, "variable3", Lua.LUA_TBOOLEAN,
"false");
TableVariable childTable = new TableVariable(0, "child",
Lua.LUA_TTABLE, new String[0], new Object[0]);
String[] keys = new String[] { "key1", "key2" };
Object[] values = new Object[] { "value1", childTable };
variables[3] = new TableVariable(2, "variable4", Lua.LUA_TTABLE,
keys, values);
variables[4] = new Variable(2, "variable3", Lua.LUA_TNUMBER, "10");
doTestDebugResponseStackSerialization(2, variables);
} catch (IOException e) {
fail(e.getMessage());
}
}
private void doTestDebugResponseStackSerialization(int index, Variable[] variables)
throws IOException {
DebugResponseStack stackIn = new DebugResponseStack(index, variables);
byte[] data = SerializationHelper.serialize(stackIn);
DebugResponseStack stackOut = (DebugResponseStack) SerializationHelper
.deserialize(data);
Variable[] variablesIn = stackIn.getVariables();
Variable[] variablesOut = stackOut.getVariables();
assertNotNull(variablesIn);
assertNotNull(variablesOut);
assertEquals(stackIn.getIndex(), stackOut.getIndex());
assertEquals(variablesIn.length, variablesOut.length);
for (int i = 0; i < variablesIn.length; i++) {
assertEquals(variablesIn[i], variablesOut[i]);
}
}
public void testDebugResponseCallgraphSerialization() {
try {
doTestDebugResponseCallgraphSerialization(null);
doTestDebugResponseCallgraphSerialization(new StackFrame[0]);
StackFrame[] frames = new StackFrame[1];
frames[0] = new StackFrame("test.lua", 100);
doTestDebugResponseCallgraphSerialization(frames);
} catch (IOException e) {
fail(e.getMessage());
}
}
private void doTestDebugResponseCallgraphSerialization(StackFrame[] frames)
throws IOException {
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
byte[] data = SerializationHelper.serialize(responseIn);
DebugResponseCallgraph responseOut = (DebugResponseCallgraph) SerializationHelper
.deserialize(data);
assertNotNull(responseOut);
StackFrame[] inFrames = responseIn.getCallgraph();
StackFrame[] outFrames = responseOut.getCallgraph();
assertNotNull(outFrames);
assertEquals(inFrames.length, outFrames.length);
for (int i = 0; i < inFrames.length; i++) {
assertEquals(inFrames[i], outFrames[i]);
}
}
}

View File

@@ -1,171 +0,0 @@
/*******************************************************************************
* Copyright (c) 2007 LuaJ. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package org.luaj.debug;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
import org.luaj.TestPlatform;
import org.luaj.compiler.LuaC;
import org.luaj.vm.DebugNetSupport;
import org.luaj.vm.LClosure;
import org.luaj.vm.LPrototype;
import org.luaj.vm.LValue;
import org.luaj.vm.LoadState;
import org.luaj.vm.Platform;
public class DebugStackStateTest extends TestCase {
protected void setUp() throws Exception {
System.setProperty(Platform.PROPERTY_LUAJ_DEBUG, "true");
Platform.setInstance(new TestPlatform() {
public DebugNetSupport getDebugSupport() throws IOException {
return null;
}
});
LuaC.install();
}
public void testStackStateUpvalues() throws Exception {
tryScript(
"print( 'aaa' ); local a = 3;\n"+
"print( 'bbb' ); local f = function()\n"+
" print('in f'); local b = 4; a=33\n"+
" print( 'bbb' ); local g = function()\n"+
" print('in g'); local c = 6; b=444; a=333\n" +
" return c, b, a\n"+
" end; print( 'calling g' ); g(); return b, a\n"+
"end\n"+
"print('calling f'); f()\n"+
"print( 'returned from f' ); local d = 6\n"+
"return 123, a, b, c, d\n" );
}
public void testStackStateLocals() throws Exception {
tryScript(
"print('hello, world')\n"+
"print('aaa'); local a = 3; print('aaa')\n"+
"print('bbb'); local b = 4; print('bbb')\n"+
"print('ccc'); local c = 5; print('ccc')\n"+
"print('ddd'); local d = 6; print('ddd')\n"+
"print( a,b,c,d )\n"+
"return 123\n" );
}
private void tryScript(String script) throws Exception {
// set up closure
final DebugLuaState vm = (DebugLuaState) Platform.newLuaState();
final InputStream is = new ByteArrayInputStream(script.getBytes());
final LPrototype p = LoadState.undump(vm, is, "script");
final LClosure c = p.newClosure( vm._G );
// suspend the vm right away
vm.suspend();
// start the call processing in its own thread
Thread t = new Thread() {
public void run() {
try {
vm.doCall( c, new LValue[0] );
} catch ( Throwable e ) {
System.out.println(e.toString());
}
}
};
t.start();
for ( int i=0; i<20; i++ ) {
vm.stepInto();
printStackState(vm);
Thread.sleep(100);
}
vm.stop();
}
public void testDebugStackState() throws InterruptedException, IOException {
String script = "src/test/res/test6.lua";
final DebugLuaState state = (DebugLuaState) Platform.newLuaState();
InputStream is = new FileInputStream( script );
LPrototype p = LoadState.undump(state, is, script);
// create closure and execute
final LClosure c = p.newClosure( state._G );
// suspend the vm right away
state.suspend();
state.setBreakpoint(script, 14);
// start the call processing in its own thread
new Thread() {
public void run() {
try {
state.doCall( c, new LValue[0] );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}.start();
// step for 5 steps
for ( int i=0; i<5; i++ ) {
state.stepOver();
Thread.sleep(500);
System.out.println("--- callgraph="+state.getCallgraph() );
System.out.println("--- stack="+state.getStack(0) );
}
// resume the vm
state.resume();
Thread.sleep(500);
System.out.println("--- callgraph="+state.getCallgraph() );
state.resume();
Thread.sleep(500);
System.out.println("--- callgraph="+state.getCallgraph() );
}
private void printStackState(DebugLuaState vm) {
int n = vm.getCallgraph().length;
System.out.println("stacks: "+n);
for ( int j=0; j<n; j++ ) {
try {
Variable[] v = vm.getStack(j);
for ( int i=0; i<v.length; i++ )
System.out.println("v["+j+","+i+"]= index="+v[i].index+" "+v[i].name+"="+v[i].value+" type="+v[i].type);
} catch ( Throwable t ) {
System.out.println(t.toString());
return;
}
}
}
}

View File

@@ -1,30 +0,0 @@
package org.luaj.debug;
import junit.framework.TestCase;
public class EnumTypeTest extends TestCase {
public void testDebugRequestTypeSerialization() {
try {
DebugMessageType type = DebugMessageType.lineBreakpointClear;
byte[] data = SerializationHelper.serialize(type);
DebugMessageType typeOut = (DebugMessageType) SerializationHelper
.deserialize(data);
assertEquals(type, typeOut);
} catch (Exception e) {
fail(e.getMessage());
}
}
public void testDebugEventTypeSerialization() {
try {
DebugMessageType type = DebugMessageType.suspendedOnError;
byte[] data = SerializationHelper.serialize(type);
DebugMessageType typeOut = (DebugMessageType) SerializationHelper
.deserialize(data);
assertNotNull(typeOut);
assertEquals(type, typeOut);
} catch (Exception e) {
fail(e.getMessage());
}
}
}

View File

@@ -1,24 +0,0 @@
package org.luaj.debug;
import java.io.PrintWriter;
import junit.framework.TestCase;
import org.luaj.debug.event.DebugEventListener;
public class RedirectOutputStreamTest extends TestCase {
public void testRedirectOutputStream() {
RedirectOutputStream redirectOut = new RedirectOutputStream(
new DebugEventListener(){
public void notifyDebugEvent(DebugMessage event) {
assertEquals(event.toString(), "outputRedirect: true\r\na");
}
});
PrintWriter writer = new PrintWriter(redirectOut);
writer.print(true);
writer.println();
writer.print('a');
writer.close();
}
}

View File

@@ -1,22 +0,0 @@
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 {
public void testSerialization() {
try {
StackFrame stackIn = new StackFrame("test.lua", 10);
byte[] data = SerializationHelper.serialize(stackIn);
StackFrame stackOut = (StackFrame) SerializationHelper.deserialize(data);
assertNotNull(stackOut);
assertEquals(stackIn, stackOut);
} catch (IOException e) {
fail(e.getMessage());
}
}
}

View File

@@ -1,137 +0,0 @@
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;
public class TableVariableTest extends TestCase {
public void testCreate() {
LTable table = new LTable();
table.put("key1", new LString("value1"));
table.put("key2", new LNil());
table.put("key3", LBoolean.TRUE);
table.put("key4", LInteger.valueOf(10));
table.put("key5", new LDouble(0.5));
LTable childTable = new LTable();
childTable.put("childKey1", new LString("childValue1"));
table.put("key6", childTable);
TableVariable tableVariable = new TableVariable(0, "tableVar", Lua.LUA_TTABLE, table);
String[] keys = tableVariable.getKeys();
assertNotNull(keys);
assertEquals(keys.length, 6);
for (int i = 0; i < 6; i++) {
assertTrue(keys[i].startsWith("key"));
}
Object[] values = tableVariable.getValues();
assertNotNull(values);
assertEquals(values.length, 6);
for (int i = 0; i < 6; i++) {
if (values[i] instanceof String) {
assertTrue(values[i].equals("value1") ||
values[i].equals("nil") ||
values[i].equals("true") ||
values[i].equals("10") ||
values[i].equals("0.5"));
} else if (values[i] instanceof TableVariable) {
TableVariable child = (TableVariable) values[i];
String[] childKeys = child.getKeys();
assertNotNull(childKeys);
assertEquals(childKeys.length, 1);
assertEquals(childKeys[0], "childKey1");
Object[] childValues = child.getValues();
assertNotNull(childValues);
assertEquals(childValues.length, 1);
assertEquals(childValues[0], "childValue1");
} else {
fail("bad value type");
}
}
}
public void testSerialization() {
String[] keys = null;
Object[] values = null;
try {
doTestSerialization(0, "name", Lua.LUA_TTABLE, keys, values);
} catch (IOException e) {
fail(e.getMessage());
}
keys = new String[0];
values = new String[0];
try {
doTestSerialization(0, "name", Lua.LUA_TTABLE, keys, values);
} catch (IOException e) {
fail(e.getMessage());
}
keys = new String[] {"key1", "key2"};
values = new String[] {"value1", "value2"};
try {
doTestSerialization(0, "name", Lua.LUA_TTABLE, keys, values);
} catch (IOException e) {
fail(e.getMessage());
}
TableVariable grandchild = new TableVariable(1, "child", Lua.LUA_TTABLE, keys, values);
keys = new String[] {"grandchild1", "grandchild2", "grandchild3"};
values = new Object[] {"value1", "value2", grandchild};
TableVariable child = new TableVariable(1, "child", Lua.LUA_TTABLE, keys, values);
keys = new String[] {"child1", "child2"};
values = new Object[] {"value1", child};
try {
doTestSerialization(0, "name", Lua.LUA_TTABLE, keys, values);
} catch (IOException e) {
fail(e.getMessage());
}
}
protected void doTestSerialization(int index, String name, int type,
String[] keys, Object[] values)
throws IOException {
TableVariable in = new TableVariable(index, name, type, keys, values);
byte[] data = SerializationHelper.serialize(in);
TableVariable out = (TableVariable) SerializationHelper.deserialize(data);
assertTableVariable(in, out);
}
private void assertTableVariable(TableVariable in, TableVariable out) {
assertEquals(in.getIndex(), out.getIndex());
assertEquals(in.getType(), out.getType());
assertEquals(in.getName(), out.getName());
String[] inKeys = in.getKeys();
String[] outKeys = out.getKeys();
assertEquals(inKeys == null ? 0 : inKeys.length, outKeys == null ? 0 : outKeys.length);
for (int i = 0; inKeys != null && i < inKeys.length; i++) {
assertEquals(inKeys[i], outKeys[i]);
}
Object[] inValues = in.getValues();
Object[] outValues = out.getValues();
assertEquals(inValues == null ? 0 : inValues.length, outValues == null ? 0 : outValues.length);
for (int i = 0; inValues != null && i < inValues.length; i++) {
if (inValues[i] instanceof String && outValues[i] instanceof String) {
assertEquals(inValues[i], outValues[i]);
} else if (inValues[i] instanceof TableVariable && outValues[i] instanceof TableVariable) {
assertTableVariable((TableVariable)inValues[i], (TableVariable)outValues[i]);
} else {
fail("bad serialization");
}
}
}
}

View File

@@ -1,29 +0,0 @@
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;
public class VariableTest extends TestCase {
public void testSerialization() {
doTestSerialization(0, "varName", Lua.LUA_TSTRING, null);
doTestSerialization(0, "varName", Lua.LUA_TSTRING, "varValue");
}
protected void doTestSerialization(int index, String varName, int type, String varValue) {
Variable varIn = new Variable(index, varName, type, varValue);
Variable varOut = null;
try {
byte[] data = SerializationHelper.serialize(varIn);
varOut = (Variable) SerializationHelper.deserialize(data);
} catch (IOException e) {
fail(e.getMessage());
}
assertNotNull(varOut);
assertEquals(varIn, varOut);
}
}

View File

@@ -1,268 +0,0 @@
/*******************************************************************************
* Copyright (c) 2007 LuaJ. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package org.luaj.debug.j2se;
import java.net.URL;
import java.util.Properties;
import junit.framework.TestCase;
import org.luaj.TestPlatform;
import org.luaj.debug.j2se.StandardLuaJVM.ParseException;
import org.luaj.vm.Platform;
/**
* Sanity test for StandardLuaJVM.
*/
public class LuaJVMTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
System.setProperty(Platform.PROPERTY_LUAJ_DEBUG_PORT, "1999");
Platform.setInstance(new TestPlatform());
}
public void testCommandLineParse() {
// null arguments
String[] args = null;
StandardLuaJVM vm = new StandardLuaJVM();
try {
vm.parse(args);
fail("Bad parsing program. Should never reach this line.");
} catch (ParseException e) {}
// empty arguments
args = new String[] {};
vm = new StandardLuaJVM();
try {
vm.parse(args);
fail("Bad parsing program. Should never reach this line.");
} catch (ParseException e) {}
// incomplete arguments
args = new String[] { "-D" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
fail("Bad parsing program. Should never reach this line.");
} catch (ParseException e) {}
args = new String[] { "-D1046" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
fail("Bad parsing program. Should never reach this line.");
} catch (ParseException e) {}
args = new String[] { "-DsuspendOnStart=true" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
fail("Bad parsing program. Should never reach this line.");
} catch (ParseException e) {}
// invalid debug option format
args = new String[] { "-Dport=1044:suspendOnStart=true", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertFalse(1044 == vm.getDebugPort());
assertFalse(true == vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
//expected
}
args = new String[] { "-Dport=1044,suspendOnStart=xyz", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertTrue(1044 == vm.getDebugPort());
assertFalse(true == vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
//expected
}
// missing script name
args = new String[] { "-Dport=1047,suspendOnStart=true"};
vm = new StandardLuaJVM();
try {
vm.parse(args);
fail("Bad parsing program. Should never reach this line.");
} catch (ParseException e) {}
// lua script cannot be found
args = new String[] { "-Dport=1046,suspendOnStart", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
vm.run();
fail("Should never reach this line.");
} catch (ParseException e) {}
// lua script cannot be found
args = new String[] { "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
vm.run();
} catch (ParseException e) {
fail("Should never reach this line.");
}
// valid command line
args = new String[] { "-Dport=1044,suspendOnStart=true", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertEquals(1044, vm.getDebugPort());
assertEquals(true, vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
}
args = new String[] { "-Dport=1044,suspendOnStart=True", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertEquals(1044, vm.getDebugPort());
assertEquals(true, vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
}
args = new String[] { "-DsuspendOnStart=true,port=1044", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertEquals(1044, vm.getDebugPort());
assertEquals(true, vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
}
args = new String[] { "-DsuspendOnStart=TRUE,port=1044", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertEquals(1044, vm.getDebugPort());
assertEquals(true, vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
}
args = new String[] { "-Dport=1044", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertEquals(1044, vm.getDebugPort());
assertEquals(false, vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
}
System.setProperty("LUA_PATH", "c:/work/CSI/prototypes/uidemo/?.lua");
args = new String[] {"dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertEquals("c:/work/CSI/prototypes/uidemo/?.lua", vm.getLuaPath());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
}
System.setProperty("LUA_PATH", "c:/work/CSI/prototypes/uidemo/?.lua");
args = new String[] { "-Dport=1044", "dummy.lua" };
vm = new StandardLuaJVM();
try {
vm.parse(args);
assertEquals(1044, vm.getDebugPort());
assertEquals("c:/work/CSI/prototypes/uidemo/?.lua", vm.getLuaPath());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
}
}
public void testRun() {
Properties props = System.getProperties();
props.remove(Platform.PROPERTY_LUAJ_DEBUG);
props.remove(Platform.PROPERTY_LUAJ_DEBUG_HOST);
props.remove(Platform.PROPERTY_LUAJ_DEBUG_PORT);
props.remove(Platform.PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START);
System.setProperties(props);
String[] tests = new String[] { "autoload", "boolean", "calls",
"coercions", "compare", "math", "mathlib", "metatables",
"select", "setlist", "swingapp", "test1", "test2", "test3",
"test4", "test5", "test6", "test7", "type", "upvalues",
"strlib"
};
doRun(tests);
}
public void testDebugRun() {
Properties props = System.getProperties();
props.setProperty(Platform.PROPERTY_LUAJ_DEBUG, "true");
props.setProperty(Platform.PROPERTY_LUAJ_DEBUG_PORT, "1999");
System.setProperties(props);
String[] tests = new String[] { "boolean", "calls",
"coercions", "compare", "math", "mathlib", "metatables",
"select", "setlist", "swingapp", "test1", "test2", "test3",
"test4", "test5", "test6", "test7", "type", "upvalues"
};
doRun(tests);
}
private void doRun(String[] tests) {
for (int i = 0; i < tests.length; i++) {
String test = tests[i];
System.out.println("==> running test: " + test + ".lua");
doTestRun(test + ".lua");
System.out.println("==> running test: " + test + ".luac");
doTestRun(test + ".luac");
System.out.println();
}
}
protected void doTestRun(String testName) {
String[] args = new String[1];
URL filePath = getClass().getResource("/" + testName);
if (filePath != null) {
args[0] = filePath.getPath();
try {
StandardLuaJVM.main(args);
} catch (Exception e) {
e.printStackTrace();
fail("Test " + testName + " failed due to " + e.getMessage());
}
}
}
}