Skip to content

Commit 17fdace

Browse files
committed
Adapt tests for compat53.module.
Run tests for compat53.module if "module" is given as argument to the test script. Skip tests that don't apply in this case.
1 parent 0a59104 commit 17fdace

1 file changed

Lines changed: 73 additions & 55 deletions

File tree

tests/test.lua

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,26 @@ end
3636
local V = _VERSION:gsub("^.*(%d+)%.(%d+)$", "%1%2")
3737
if jit then V = "jit" end
3838

39-
print( "testing Lua API ..." )
39+
local mode = "global"
40+
if arg[1] == "module" then
41+
mode = "module"
42+
end
43+
44+
4045
package.path = "../?.lua;../?/init.lua;"..package.path
4146
package.cpath = "./?-"..V..".so;./?-"..V..".dll;./?.so;./?.dll"
42-
require("compat53")
47+
if mode == "module" then
48+
print( "testing Lua API using `compat53.module` ..." )
49+
_ENV = require("compat53.module")
50+
if setfenv then setfenv(1, _ENV) end
51+
else
52+
print( "testing Lua API using `compat53` ..." )
53+
require("compat53")
54+
end
4355

4456
___''
4557
do
46-
local t = setmetatable( {}, { __index = { 1, false, "three" } } )
58+
local t = setmetatable({}, { __index = { 1, false, "three" } })
4759
for i,v in ipairs(t) do
4860
print("ipairs", i, v)
4961
end
@@ -338,22 +350,24 @@ do
338350
print("xpcall()", xpcall(func, debug.traceback, false))
339351
print("xpcall()", xpcall(func, debug.traceback, true))
340352
print("xpcall()", xpcall(func, tb, true))
341-
local function func2(cb)
342-
print("xpcall()", xpcall(cb, debug.traceback, "str"))
343-
end
344-
local function func3(cb)
345-
print("pcall()", pcall(cb, "str"))
353+
if mode ~= "module" then
354+
local function func2(cb)
355+
print("xpcall()", xpcall(cb, debug.traceback, "str"))
356+
end
357+
local function func3(cb)
358+
print("pcall()", pcall(cb, "str"))
359+
end
360+
local function cb(arg)
361+
coroutine.yield(2)
362+
return arg
363+
end
364+
local c = coroutine.wrap(func2)
365+
print("xpcall()", c(cb))
366+
print("xpcall()", c())
367+
local c = coroutine.wrap(func3)
368+
print("pcall()", c(cb))
369+
print("pcall()", c())
346370
end
347-
local function cb(arg)
348-
coroutine.yield(2)
349-
return arg
350-
end
351-
local c = coroutine.wrap(func2)
352-
print("xpcall()", c(cb))
353-
print("xpcall()", c())
354-
local c = coroutine.wrap(func3)
355-
print("pcall()", c(cb))
356-
print("pcall()", c())
357371
end
358372

359373

@@ -387,9 +401,11 @@ do
387401
print("coroutine.running()", F(coroutine.running()))
388402
local main_co, co1, co2 = coroutine.running()
389403
-- coroutine.yield
390-
print("coroutine.yield()", pcall(function()
391-
coroutine.yield(1, 2, 3)
392-
end))
404+
if mode ~= "module" then
405+
print("coroutine.yield()", pcall(function()
406+
coroutine.yield(1, 2, 3)
407+
end))
408+
end
393409
print("coroutine.yield()", coroutine.wrap(function()
394410
coroutine.yield(1, 2, 3)
395411
end)())
@@ -428,13 +444,13 @@ do
428444
local path, prefix = "./?.lua;?/init.lua;../?.lua", "package.searchpath()"
429445
print(prefix, package.searchpath("no.such.module", path))
430446
print(prefix, package.searchpath("no.such.module", ""))
431-
print(prefix, package.searchpath("compat52", path))
447+
print(prefix, package.searchpath("compat53", path))
432448
print(prefix, package.searchpath("no:such:module", path, ":", "|"))
433449
end
434450

435451

436452
___''
437-
do
453+
if mode ~= "module" then
438454
local function mod_func() return {} end
439455
local function my_searcher(name)
440456
if name == "my.module" then
@@ -462,19 +478,19 @@ end
462478

463479
___''
464480
do
465-
print("string.find()", ("abc\0abc\0abc"):find("[^a\0]+"))
466-
print("string.find()", ("abc\0abc\0abc"):find("%w+\0", 5))
467-
for x in ("abc\0def\0ghi"):gmatch("[^\0]+") do
481+
print("string.find()", string.find("abc\0abc\0abc", "[^a\0]+"))
482+
print("string.find()", string.find("abc\0abc\0abc", "%w+\0", 5))
483+
for x in string.gmatch("abc\0def\0ghi", "[^\0]+") do
468484
print("string.gmatch()", x)
469485
end
470-
for x in ("abc\0def\0ghi"):gmatch("%w*\0") do
486+
for x in string.gmatch("abc\0def\0ghi", "%w*\0") do
471487
print("string.gmatch()", #x)
472488
end
473-
print("string.gsub()", ("abc\0def\0ghi"):gsub("[\0]", "X"))
474-
print("string.gsub()", ("abc\0def\0ghi"):gsub("%w*\0", "X"))
475-
print("string.gsub()", ("abc\0def\0ghi"):gsub("%A", "X"))
476-
print("string.match()", ("abc\0abc\0abc"):match("([^\0a]+)"))
477-
print("string.match()", #("abc\0abc\0abc"):match(".*\0"))
489+
print("string.gsub()", string.gsub("abc\0def\0ghi", "[\0]", "X"))
490+
print("string.gsub()", string.gsub("abc\0def\0ghi", "%w*\0", "X"))
491+
print("string.gsub()", string.gsub("abc\0def\0ghi", "%A", "X"))
492+
print("string.match()", string.match("abc\0abc\0abc", "([^\0a]+)"))
493+
print("string.match()", #string.match("abc\0abc\0abc", ".*\0"))
478494
print("string.rep()", string.rep("a", 0))
479495
print("string.rep()", string.rep("b", 1))
480496
print("string.rep()", string.rep("c", 4))
@@ -533,30 +549,32 @@ do
533549
print("io.lines()", pcall(function()
534550
for l in io.lines("no_such_file.txt") do print(l) end
535551
end))
536-
local f = assert(io.open("test.lua", "r"))
537-
for a,b in f:lines(2, "*l") do
538-
print("file:lines()", a, b)
539-
break
552+
if mode ~= "module" then
553+
local f = assert(io.open("test.lua", "r"))
554+
for a,b in f:lines(2, "*l") do
555+
print("file:lines()", a, b)
556+
break
557+
end
558+
f:close()
559+
f = assert(io.open("data.txt", "r"))
560+
for n1,n2,rest in f:lines("*n", "*n", "*a") do
561+
print("file:lines()", n1, n2, rest)
562+
end
563+
f:close()
564+
f = assert(io.open("data.txt", "r"))
565+
for l in f:lines() do
566+
print("file:lines()", l)
567+
end
568+
f:close()
569+
print("file:lines()", pcall(function()
570+
for l in f:lines() do print(l) end
571+
end))
572+
print("file:lines()", pcall(function()
573+
local f = assert(io.open("data.txt", "r"))
574+
for l in f:lines("*l", "*x") do print(l) end
575+
f:close()
576+
end))
540577
end
541-
f:close()
542-
f = assert(io.open("data.txt", "r"))
543-
for n1,n2,rest in f:lines("*n", "*n", "*a") do
544-
print("file:lines()", n1, n2, rest)
545-
end
546-
f:close()
547-
f = assert(io.open("data.txt", "r"))
548-
for l in f:lines() do
549-
print("file:lines()", l)
550-
end
551-
f:close()
552-
print("file:lines()", pcall(function()
553-
for l in f:lines() do print(l) end
554-
end))
555-
print("file:lines()", pcall(function()
556-
local f = assert(io.open("data.txt", "r"))
557-
for l in f:lines("*l", "*x") do print(l) end
558-
f:close()
559-
end))
560578
os.remove("data.txt")
561579
end
562580
___''

0 commit comments

Comments
 (0)