diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2015-04-26 19:15:18 +0200 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2015-04-26 19:15:18 +0200 |
| commit | 17fdace5c04486db3470fe7022aee7eac8efc3af (patch) | |
| tree | 4c0c92126d40b6f68b8db2e1f73f9cf5c2df31a3 /tests/test.lua | |
| parent | 0a59104baac417a8559947ee007b35a086c3ec73 (diff) | |
| download | lua-compat-5.3-17fdace5c04486db3470fe7022aee7eac8efc3af.tar.gz lua-compat-5.3-17fdace5c04486db3470fe7022aee7eac8efc3af.tar.bz2 lua-compat-5.3-17fdace5c04486db3470fe7022aee7eac8efc3af.zip | |
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.
Diffstat (limited to 'tests/test.lua')
| -rwxr-xr-x | tests/test.lua | 128 |
1 files changed, 73 insertions, 55 deletions
diff --git a/tests/test.lua b/tests/test.lua index 664cfa6..856230b 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -36,14 +36,26 @@ end | |||
| 36 | local V = _VERSION:gsub("^.*(%d+)%.(%d+)$", "%1%2") | 36 | local V = _VERSION:gsub("^.*(%d+)%.(%d+)$", "%1%2") |
| 37 | if jit then V = "jit" end | 37 | if jit then V = "jit" end |
| 38 | 38 | ||
| 39 | print( "testing Lua API ..." ) | 39 | local mode = "global" |
| 40 | if arg[1] == "module" then | ||
| 41 | mode = "module" | ||
| 42 | end | ||
| 43 | |||
| 44 | |||
| 40 | package.path = "../?.lua;../?/init.lua;"..package.path | 45 | package.path = "../?.lua;../?/init.lua;"..package.path |
| 41 | package.cpath = "./?-"..V..".so;./?-"..V..".dll;./?.so;./?.dll" | 46 | 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 | ||
| 43 | 55 | ||
| 44 | ___'' | 56 | ___'' |
| 45 | do | 57 | do |
| 46 | local t = setmetatable( {}, { __index = { 1, false, "three" } } ) | 58 | local t = setmetatable({}, { __index = { 1, false, "three" } }) |
| 47 | for i,v in ipairs(t) do | 59 | for i,v in ipairs(t) do |
| 48 | print("ipairs", i, v) | 60 | print("ipairs", i, v) |
| 49 | end | 61 | end |
| @@ -338,22 +350,24 @@ do | |||
| 338 | print("xpcall()", xpcall(func, debug.traceback, false)) | 350 | print("xpcall()", xpcall(func, debug.traceback, false)) |
| 339 | print("xpcall()", xpcall(func, debug.traceback, true)) | 351 | print("xpcall()", xpcall(func, debug.traceback, true)) |
| 340 | print("xpcall()", xpcall(func, tb, true)) | 352 | print("xpcall()", xpcall(func, tb, true)) |
| 341 | local function func2(cb) | 353 | if mode ~= "module" then |
| 342 | print("xpcall()", xpcall(cb, debug.traceback, "str")) | 354 | local function func2(cb) |
| 343 | end | 355 | print("xpcall()", xpcall(cb, debug.traceback, "str")) |
| 344 | local function func3(cb) | 356 | end |
| 345 | print("pcall()", pcall(cb, "str")) | 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()) | ||
| 346 | end | 370 | 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()) | ||
| 357 | end | 371 | end |
| 358 | 372 | ||
| 359 | 373 | ||
| @@ -387,9 +401,11 @@ do | |||
| 387 | print("coroutine.running()", F(coroutine.running())) | 401 | print("coroutine.running()", F(coroutine.running())) |
| 388 | local main_co, co1, co2 = coroutine.running() | 402 | local main_co, co1, co2 = coroutine.running() |
| 389 | -- coroutine.yield | 403 | -- coroutine.yield |
| 390 | print("coroutine.yield()", pcall(function() | 404 | if mode ~= "module" then |
| 391 | coroutine.yield(1, 2, 3) | 405 | print("coroutine.yield()", pcall(function() |
| 392 | end)) | 406 | coroutine.yield(1, 2, 3) |
| 407 | end)) | ||
| 408 | end | ||
| 393 | print("coroutine.yield()", coroutine.wrap(function() | 409 | print("coroutine.yield()", coroutine.wrap(function() |
| 394 | coroutine.yield(1, 2, 3) | 410 | coroutine.yield(1, 2, 3) |
| 395 | end)()) | 411 | end)()) |
| @@ -428,13 +444,13 @@ do | |||
| 428 | local path, prefix = "./?.lua;?/init.lua;../?.lua", "package.searchpath()" | 444 | local path, prefix = "./?.lua;?/init.lua;../?.lua", "package.searchpath()" |
| 429 | print(prefix, package.searchpath("no.such.module", path)) | 445 | print(prefix, package.searchpath("no.such.module", path)) |
| 430 | print(prefix, package.searchpath("no.such.module", "")) | 446 | print(prefix, package.searchpath("no.such.module", "")) |
| 431 | print(prefix, package.searchpath("compat52", path)) | 447 | print(prefix, package.searchpath("compat53", path)) |
| 432 | print(prefix, package.searchpath("no:such:module", path, ":", "|")) | 448 | print(prefix, package.searchpath("no:such:module", path, ":", "|")) |
| 433 | end | 449 | end |
| 434 | 450 | ||
| 435 | 451 | ||
| 436 | ___'' | 452 | ___'' |
| 437 | do | 453 | if mode ~= "module" then |
| 438 | local function mod_func() return {} end | 454 | local function mod_func() return {} end |
| 439 | local function my_searcher(name) | 455 | local function my_searcher(name) |
| 440 | if name == "my.module" then | 456 | if name == "my.module" then |
| @@ -462,19 +478,19 @@ end | |||
| 462 | 478 | ||
| 463 | ___'' | 479 | ___'' |
| 464 | do | 480 | do |
| 465 | print("string.find()", ("abc\0abc\0abc"):find("[^a\0]+")) | 481 | print("string.find()", string.find("abc\0abc\0abc", "[^a\0]+")) |
| 466 | print("string.find()", ("abc\0abc\0abc"):find("%w+\0", 5)) | 482 | print("string.find()", string.find("abc\0abc\0abc", "%w+\0", 5)) |
| 467 | for x in ("abc\0def\0ghi"):gmatch("[^\0]+") do | 483 | for x in string.gmatch("abc\0def\0ghi", "[^\0]+") do |
| 468 | print("string.gmatch()", x) | 484 | print("string.gmatch()", x) |
| 469 | end | 485 | end |
| 470 | for x in ("abc\0def\0ghi"):gmatch("%w*\0") do | 486 | for x in string.gmatch("abc\0def\0ghi", "%w*\0") do |
| 471 | print("string.gmatch()", #x) | 487 | print("string.gmatch()", #x) |
| 472 | end | 488 | end |
| 473 | print("string.gsub()", ("abc\0def\0ghi"):gsub("[\0]", "X")) | 489 | print("string.gsub()", string.gsub("abc\0def\0ghi", "[\0]", "X")) |
| 474 | print("string.gsub()", ("abc\0def\0ghi"):gsub("%w*\0", "X")) | 490 | print("string.gsub()", string.gsub("abc\0def\0ghi", "%w*\0", "X")) |
| 475 | print("string.gsub()", ("abc\0def\0ghi"):gsub("%A", "X")) | 491 | print("string.gsub()", string.gsub("abc\0def\0ghi", "%A", "X")) |
| 476 | print("string.match()", ("abc\0abc\0abc"):match("([^\0a]+)")) | 492 | print("string.match()", string.match("abc\0abc\0abc", "([^\0a]+)")) |
| 477 | print("string.match()", #("abc\0abc\0abc"):match(".*\0")) | 493 | print("string.match()", #string.match("abc\0abc\0abc", ".*\0")) |
| 478 | print("string.rep()", string.rep("a", 0)) | 494 | print("string.rep()", string.rep("a", 0)) |
| 479 | print("string.rep()", string.rep("b", 1)) | 495 | print("string.rep()", string.rep("b", 1)) |
| 480 | print("string.rep()", string.rep("c", 4)) | 496 | print("string.rep()", string.rep("c", 4)) |
| @@ -533,30 +549,32 @@ do | |||
| 533 | print("io.lines()", pcall(function() | 549 | print("io.lines()", pcall(function() |
| 534 | for l in io.lines("no_such_file.txt") do print(l) end | 550 | for l in io.lines("no_such_file.txt") do print(l) end |
| 535 | end)) | 551 | end)) |
| 536 | local f = assert(io.open("test.lua", "r")) | 552 | if mode ~= "module" then |
| 537 | for a,b in f:lines(2, "*l") do | 553 | local f = assert(io.open("test.lua", "r")) |
| 538 | print("file:lines()", a, b) | 554 | for a,b in f:lines(2, "*l") do |
| 539 | break | 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)) | ||
| 540 | end | 577 | 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)) | ||
| 560 | os.remove("data.txt") | 578 | os.remove("data.txt") |
| 561 | end | 579 | end |
| 562 | ___'' | 580 | ___'' |
