From 58a4dec882cd510ba6fefb12de1bdded4eb96a92 Mon Sep 17 00:00:00 2001 From: Enrico Horn Date: Thu, 8 Jul 2021 22:45:26 +0200 Subject: [PATCH] Update errors tests for lua 5.2 --- luaj-test/src/test/resources/errors/args.lua | 1 + .../src/test/resources/errors/baselibargs.lua | 30 ++++++++----------- .../src/test/resources/errors/iolibargs.lua | 6 +++- .../src/test/resources/errors/operators.lua | 12 ++++---- .../test/resources/errors/stringlibargs.lua | 8 ++--- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/luaj-test/src/test/resources/errors/args.lua b/luaj-test/src/test/resources/errors/args.lua index f74e48fa..69d8aaad 100644 --- a/luaj-test/src/test/resources/errors/args.lua +++ b/luaj-test/src/test/resources/errors/args.lua @@ -24,6 +24,7 @@ somenumber = { anumber, astrnum } someboolean = { aboolean } sometable = { atable } somefunction = { afunction } +somethread = { athread } somenil = { anil } somekey = { akey } notakey = { astring, anumber, aboolean, atable, afunction } diff --git a/luaj-test/src/test/resources/errors/baselibargs.lua b/luaj-test/src/test/resources/errors/baselibargs.lua index a2cc6d1c..4c9e5bdf 100644 --- a/luaj-test/src/test/resources/errors/baselibargs.lua +++ b/luaj-test/src/test/resources/errors/baselibargs.lua @@ -40,24 +40,17 @@ checkallerrors('ipairs', {notatable}, 'bad argument') -- load banner('load') 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 -banner('loadfile') ---checkallpass('loadfile', {}) ---checkallpass('loadfile', {{'bogus'}}) ---checkallpass('loadfile', {{'test/lua/errors/args.lua'}}) ---checkallpass('loadfile', {{'args.lua'}}) ---checkallerrors('loadfile', {nonstring}, 'bad argument') - --- load -banner('load') checkallpass('load', {{'return'}}) checkallpass('load', {{'return'},{'mychunk'}}) checkallpass('load', {{'return a ... b'},{'mychunk'}},true) -checkallerrors('load', {notastring,{nil,astring,anumber,n=3}}, 'bad argument') -checkallerrors('load', {{'return'},{afunction,atable}}, 'bad argument') +checkallerrors('load', {somefunction,nonstring}, 'bad argument') +checkallerrors('load', {{nil,aboolean,atable,athread},notastring}, 'bad argument') +checkallerrors('load', {{'return'},nonstring}, 'bad argument') + +-- loadfile +banner('loadfile') +checkallpass('loadfile', {{'args.lua'}}) +checkallerrors('loadfile', {nonstring}, 'bad argument') -- next banner('next') @@ -110,15 +103,16 @@ checkallerrors('select', {notanumber}, 'bad argument') -- setmetatable banner('setmetatable') -checkallpass('setmetatable', {sometable,sometable}) -checkallpass('setmetatable', {sometable,{}}) +checkallpass('setmetatable', {sometable, {nil,atable,n=2}}) checkallerrors('setmetatable',{notatable,sometable},'bad argument') checkallerrors('setmetatable',{sometable,nontable},'bad argument') -- tonumber banner('tonumber') checkallpass('tonumber',{somenumber,{nil,2,10,36,n=4}}) -checkallpass('tonumber',{notanil,{nil,10,n=2}}) +checkallpass('tonumber',{notanil,{nil,n=1}}) +checkallpass('tonumber',{somestring,{10}}) +checkallerrors('tonumber',{notastring,{10}},'bad argument') checkallerrors('tonumber',{{nil,afunction,atable,n=3},{2,9,11,36}},'bad argument') checkallerrors('tonumber',{somenumber,{1,37,atable,afunction,aboolean}},'bad argument') diff --git a/luaj-test/src/test/resources/errors/iolibargs.lua b/luaj-test/src/test/resources/errors/iolibargs.lua index 1f8a3ac4..558eeeda 100644 --- a/luaj-test/src/test/resources/errors/iolibargs.lua +++ b/luaj-test/src/test/resources/errors/iolibargs.lua @@ -21,7 +21,7 @@ banner('io.lines') io.input("abc.txt") checkallpass('io.lines',{{"abc.txt"}}) checkallerrors('io.lines',{{f}},'bad argument') -checkallerrors('io.lines',{notastring},'bad argument') +checkallerrors('io.lines',{nonstring},'bad argument') -- io.open (filename [, mode]) banner('io.open') @@ -83,3 +83,7 @@ checkallerrors('file.setvbuf',{},'bad argument') checkallerrors('file.setvbuf',{{file},notastring},'bad argument') checkallerrors('file.setvbuf',{{file},{"full"},nonnumber},'bad argument') +pcall( file.close, f ) +os.remove("abc.txt") +pcall( file.close, file ) +os.remove("seektest.txt") diff --git a/luaj-test/src/test/resources/errors/operators.lua b/luaj-test/src/test/resources/errors/operators.lua index ba53b507..f1359d08 100644 --- a/luaj-test/src/test/resources/errors/operators.lua +++ b/luaj-test/src/test/resources/errors/operators.lua @@ -2,7 +2,7 @@ package.path = "?.lua;test/lua/errors/?.lua" require 'args' -- arg types for language operator - +local notstringortable = { nil, anumber, aboolean, afunction, athread, n=5 } -- ========= unary operators: - # not -- unary minus - @@ -15,7 +15,7 @@ checkallerrors('negative',{notanumber},'attempt to perform arithmetic') banner('#') lengthop = function(a) return #a end checkallpass('lengthop',{sometable}) -checkallerrors('lengthop',{notatable},'attempt to get length of') +checkallerrors('lengthop',{notstringortable},'attempt to get length of') -- length banner('not') @@ -127,14 +127,14 @@ checkallerrors('gtop',{{astring,astrnum},notastring},'attempt to compare') banner( '[]' ) bracketop = function(a,b) return a[b] end checkallpass('bracketop',{sometable,notanil}) -checkallerrors('bracketop',{notatable,notanil},'attempt to index') -checkallerrors('bracketop',{sometable},'attempt to index') +checkallerrors('bracketop',{notstringortable,notanil},'attempt to index') +--checkallerrors('bracketop',{sometable},'attempt to index') banner( '.' ) dotop = function(a,b) return a.b end checkallpass('dotop',{sometable,notanil}) -checkallerrors('dotop',{notatable,notanil},'attempt to index') -checkallerrors('dotop',{sometable},'attempt to index') +checkallerrors('dotop',{notstringortable,notanil},'attempt to index') +--checkallerrors('dotop',{sometable},'attempt to index') banner( 'and' ) types = {['table']='table',['function']='function',['thread']='thread'} diff --git a/luaj-test/src/test/resources/errors/stringlibargs.lua b/luaj-test/src/test/resources/errors/stringlibargs.lua index 6cb732e8..1fad33ef 100644 --- a/luaj-test/src/test/resources/errors/stringlibargs.lua +++ b/luaj-test/src/test/resources/errors/stringlibargs.lua @@ -21,8 +21,8 @@ checkallpass('string.char',{{60},{70}}) checkallpass('string.char',{{60},{70},{80}}) checkallpass('string_char',{{0,9,40,127,128,255,'0','9','255','9.2',9.2}}) checkallpass('string_char',{{0,127,255},{0,127,255}}) -checkallerrors('string_char',{},'bad argument') -checkallerrors('string_char',{{nil,-1,256,3}},'bad argument') +--checkallerrors('string_char',{},'bad argument') +checkallerrors('string_char',{{nil,-1,256}},'bad argument') checkallerrors('string_char',{notanumber,{23,'45',6.7}},'bad argument') checkallerrors('string_char',{{23,'45',6.7},nonnumber},'bad argument') @@ -53,7 +53,7 @@ checkallpass('string.format',{somestring,anylua}) checkallpass('string.format',{numfmts,somenumber}) checkallpass('string.format',{strfmts,somestring}) checkallerrors('string.format',{numfmts,notanumber},'bad argument') -checkallerrors('string.format',{strfmts,notastring},'bad argument') +checkallerrors('string.format',{{'%q'},notastring},'bad argument') checkallerrors('string.format',{badfmts,somestring},"invalid option '%w'") -- string.gmatch @@ -90,7 +90,7 @@ checkallerrors('string.match',{},'bad argument') checkallerrors('string.match',{nonstring,somestring},'bad argument') checkallerrors('string.match',{somestring},'bad argument') checkallerrors('string.match',{somestring,nonstring},'bad argument') -checkallerrors('string.match',{somestring,somestring,notanumber},'bad argument') +checkallerrors('string.match',{somestring,somestring,nonnumber},'bad argument') -- string.reverse banner('string.reverse')