Improve error reporting.

This commit is contained in:
James Roseborough
2010-05-15 21:56:29 +00:00
parent a6a06776fb
commit 3a21941e57
7 changed files with 121 additions and 106 deletions

View File

@@ -21,7 +21,11 @@
******************************************************************************/
package org.luaj.vm2;
import java.io.IOException;
import java.io.InputStream;
import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.BaseLib;
/**
@@ -42,7 +46,14 @@ public class ErrorsTest extends ScriptDrivenTest {
super.setUp();
}
public void testBaseLibArgs() { runTest("baselibargs"); }
public void testBaseLibArgs() {
BaseLib.instance.STDIN = new InputStream() {
public int read() throws IOException {
return -1;
}
};
runTest("baselibargs");
}
public void testCoroutineLibArgs() { runTest("coroutinelibargs"); }
public void testIoLibArgs() { runTest("iolibargs"); }
public void testMathLibArgs() { runTest("mathlibargs"); }

View File

@@ -68,13 +68,13 @@ public class ScriptDrivenTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
initGlobals();
}
// */
protected void runTest(String testName) {
try {
// override print()
initGlobals();
final ByteArrayOutputStream output = new ByteArrayOutputStream();
final PrintStream oldps = BaseLib.instance.STDOUT;
final PrintStream ps = new PrintStream( output );

View File

@@ -19,17 +19,17 @@ checkallerrors('collectgarbage',{{aboolean, atable, afunction, athread}},'string
banner('dofile')
checkallpass('dofile', {})
checkallpass('dofile', {{'test/lua/errors/args.lua'}})
checkallerrors('dofile', {{'args.lua'}}, 'cannot open args.lua')
checkallerrors('dofile', {{'foo.bar'}}, 'cannot open foo.bar')
checkallerrors('dofile', {nonstring}, 'bad argument')
-- error
banner('error')
checkallerrors('error', {{'message'},{nil,0,1,2}}, 'message')
checkallerrors('error', {{123},{nil,1,2}}, 123)
checkallerrors('error', {{'message'},{nil,0,1,2,n=4}}, 'message')
checkallerrors('error', {{123},{nil,1,2,n=3}}, 123)
-- getfenv
banner('getfenv')
checkallpass('getfenv', {{nil,print,function()end,0,1,2}})
checkallpass('getfenv', {{nil,print,function()end,0,1,2,n=5}})
checkallerrors('getfenv', {{true,{},'abc'}}, 'bad argument')
-- getmetatable
@@ -44,8 +44,8 @@ checkallerrors('ipairs', {notatable}, 'bad argument')
-- load
banner('load')
checkallpass('load', {somefunction,{nil,astring}})
checkallerrors('load', {notafunction,{nil,astring,anumber}}, 'bad argument')
checkallpass('load', {somefunction,{nil,astring,n=2}})
checkallerrors('load', {notafunction,{nil,astring,anumber,n=3}}, 'bad argument')
checkallerrors('load', {somefunction,{afunction,atable}}, 'bad argument')
-- loadfile
@@ -62,13 +62,13 @@ checkallpass('loadstring', {{'return'}})
checkallpass('loadstring', {{'return'},{'mychunk'}})
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}},true)
checkallerrors('loadstring', {{'return a ... b'},{'mychunk'}},'hello')
checkallerrors('loadstring', {notastring,{nil,astring,anumber}}, 'bad argument')
checkallerrors('loadstring', {notastring,{nil,astring,anumber,n=3}}, 'bad argument')
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument')
-- next
banner('next')
checkallpass('next', {sometable,somekey})
checkallerrors('next', {notatable,{nil,1}}, 'bad argument')
checkallerrors('next', {notatable,{nil,1,n=2}}, 'bad argument')
checkallerrors('next', {sometable,nonkey}, 'invalid key')
-- pairs
@@ -84,7 +84,7 @@ checkallerrors('pcall',{},'bad argument')
-- print
banner('print')
checkallpass('print', {})
checkallpass('print', {{nil,astring,anumber,aboolean}})
checkallpass('print', {{nil,astring,anumber,aboolean,n=4}})
-- rawequal
banner('rawequal')
@@ -135,9 +135,9 @@ checkallerrors('setmetatable',{sometable,notatable},'bad argument')
-- tonumber
banner('tonumber')
checkallpass('tonumber',{somenumber,{nil,2,10,36}})
checkallpass('tonumber',{notanil,{nil,10}})
checkallerrors('tonumber',{{nil,afunction,atable},{2,9,11,36}},'bad argument')
checkallpass('tonumber',{somenumber,{nil,2,10,36,n=4}})
checkallpass('tonumber',{notanil,{nil,10,n=2}})
checkallerrors('tonumber',{{nil,afunction,atable,n=3},{2,9,11,36}},'bad argument')
checkallerrors('tonumber',{somenumber,{1,37,atable,afunction,aboolean}},'bad argument')
-- tostring