Skip to content

Commit 9843c46

Browse files
committed
XXX
1 parent 832a1db commit 9843c46

File tree

6 files changed

+33
-22
lines changed

6 files changed

+33
-22
lines changed

tests/lapi/lib.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@ Test helpers.
77

88
-- The function determines a Lua version.
99
local function lua_version()
10-
local maj, min = _VERSION:match("([%d]+)%.(%d+)")
11-
local maj_num, min_num = tonumber(maj), tonumber(min)
10+
local major, minor = _VERSION:match("([%d]+)%.(%d+)")
11+
local version = {
12+
major = tonumber(major),
13+
minor = tonumber(minor),
14+
}
1215
local is_luajit, _ = pcall(require, "jit")
13-
if is_luajit then
14-
return "LuaJIT", maj_num, min_num
16+
local lua_name = is_luajit and "LuaJIT" or "PUC Rio Lua"
17+
return lua_name, version
18+
end
19+
20+
local function version_ge(version1, version2)
21+
if version1.major ~= version2.major then
22+
return version1.major > version2.major
23+
else
24+
return version1.minor > version2.minor
1525
end
26+
end
1627

17-
return _VERSION, maj_num, min_num
28+
local function lua_current_version_ge_than(major, minor)
29+
local _, current_version = lua_version()
30+
return version_ge(current_version, { major = major, minor = minor })
1831
end
1932

2033
-- By default `lua_Integer` is ptrdiff_t in Lua 5.1 and Lua 5.2
@@ -59,8 +72,7 @@ local function bitwise_op(op_name)
5972
end
6073

6174
local function math_pow(x, y)
62-
local chunk = ("return %f ^ %f"):format(x, y)
63-
return assert(load(chunk))()
75+
return x ^ y
6476
end
6577

6678
local function approx_equal(a, b, epsilon)
@@ -72,6 +84,7 @@ return {
7284
approx_equal = approx_equal,
7385
bitwise_op = bitwise_op,
7486
lua_version = lua_version,
87+
lua_current_version_ge_than = lua_current_version_ge_than,
7588
math_pow = math_pow,
7689
MAX_INT64 = MAX_INT64,
7790
MIN_INT64 = MIN_INT64,

tests/lapi/math_log_test.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ Synopsis: math.log(x [, b])
1717
local luzer = require("luzer")
1818
local test_lib = require("lib")
1919

20-
-- The function `math.pow()` has been deprecated in PUC Rio Lua 5.3,
21-
-- see Lua 5.3 Reference Manual, 8.2 – Changes in the Libraries.
20+
-- The function `math.pow()` has been deprecated in PUC Rio Lua
21+
-- 5.3, see Lua 5.3 Reference Manual, 8.2 – Changes in the
22+
-- Libraries.
2223
--
2324
-- 1. https://www.lua.org/manual/5.3/manual.html
2425
local pow
25-
if test_lib.lua_version() == "LuaJIT" then
26-
pow = math.pow
27-
else
26+
if test_lib.lua_current_version_ge_than(5, 3) then
2827
pow = test_lib.math_pow
28+
else
29+
pow = math.pow
2930
end
3031

3132
local function TestOneInput(buf, _size)

tests/lapi/math_pow_test.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ local test_lib = require("lib")
2828
--
2929
-- 1. https://www.lua.org/manual/5.3/manual.html
3030
local pow
31-
if test_lib.lua_version() == "LuaJIT" then
32-
pow = math.pow
33-
else
31+
if test_lib.lua_current_version_ge_than(5, 3) then
3432
pow = test_lib.math_pow
33+
else
34+
pow = math.pow
3535
end
3636

3737
local function TestOneInput(buf, _size)

tests/lapi/math_randomseed_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ local function TestOneInput(buf)
2222
-- that were effectively used, so that setting them again
2323
-- repeats the sequence.
2424
local a, b = math.randomseed(x, y)
25-
local version_str, maj, min = test_lib.lua_version()
26-
if version_str ~= "LuaJIT" and maj >= 5 and min >= 4 then
25+
if test_lib.lua_current_version_ge_than(5, 4) then
2726
assert(type(a) == "number" and type(b) == "number")
2827
end
2928
end

tests/lapi/math_tointeger_test.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ local luzer = require("luzer")
1515
local test_lib = require("lib")
1616

1717
-- The function `math.tointeger()` is available since Lua 5.3.
18-
local _, version_major, version_minor = test_lib.lua_version()
19-
if version_major <= 5 and version_minor < 3 then
18+
if not test_lib.lua_current_version_ge_than(5, 3) then
2019
print("Unsupported version.")
2120
os.exit(0)
2221
end

tests/lapi/math_ult_test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ Synopsis: math.ult(m, n)
1414
local luzer = require("luzer")
1515
local test_lib = require("lib")
1616

17-
-- The function `math.tointeger()` is available since Lua 5.3.
18-
local _, version_major, version_minor = test_lib.lua_version()
19-
if version_major <= 5 and version_minor < 3 then
17+
-- The function `math.ult()` is available since Lua 5.3.
18+
if not test_lib.lua_current_version_ge_than(5, 3) then
2019
print("Unsupported version.")
2120
os.exit(0)
2221
end

0 commit comments

Comments
 (0)