[Tarantool-patches] [PATCH v2 09/10] test: update lua-Harness to b7b1a9a2

Maxim Kokryashkin max.kokryashkin at gmail.com
Tue Jul 20 19:26:57 MSK 2021


This patch backports several small commits from lua-Harness suite:
- follow ravi 1.0-beta4[1]
- refactor with near[2]
- follow LuaJIT[3]
- fix when no debug[4]
- check if luac exists[5]
- https[6]
- more assert[7]

[1]: https://framagit.org/fperrad/lua-Harness/-/commit/9455281b
[2]: https://framagit.org/fperrad/lua-Harness/-/commit/70404580
[3]: https://framagit.org/fperrad/lua-Harness/-/commit/ac7671b6
[4]: https://framagit.org/fperrad/lua-Harness/-/commit/4db7e539
[5]: https://framagit.org/fperrad/lua-Harness/-/commit/97e9e4c1
[6]: https://framagit.org/fperrad/lua-Harness/-/commit/673c7869
[7]: https://framagit.org/fperrad/lua-Harness/-/commit/b7b1a9a2

Part of #5970
Part of #4473
---
 test/lua-Harness-tests/200-examples.t     |  2 +-
 test/lua-Harness-tests/203-lexico.t       |  2 +-
 test/lua-Harness-tests/241-standalone.t   |  3 +-
 test/lua-Harness-tests/242-luac.t         |  4 +++
 test/lua-Harness-tests/301-basic.t        |  2 +-
 test/lua-Harness-tests/304-string.t       |  2 +-
 test/lua-Harness-tests/307-math.t         | 44 +++++++++++------------
 test/lua-Harness-tests/310-debug.t        |  2 --
 test/lua-Harness-tests/320-stdin.t        | 14 +++++---
 test/lua-Harness-tests/401-bitop.t        |  2 +-
 test/lua-Harness-tests/402-ffi.t          |  2 +-
 test/lua-Harness-tests/403-jit.t          |  2 +-
 test/lua-Harness-tests/404-ext.t          |  2 +-
 test/lua-Harness-tests/411-luajit.t       |  2 +-
 test/lua-Harness-tests/profile_ravi.lua   |  4 +--
 test/lua-Harness-tests/test_assertion.lua |  9 +++++
 16 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/test/lua-Harness-tests/200-examples.t b/test/lua-Harness-tests/200-examples.t
index 7020af4d..9d7ec6d9 100755
--- a/test/lua-Harness-tests/200-examples.t
+++ b/test/lua-Harness-tests/200-examples.t
@@ -70,7 +70,7 @@ equals(iter_factorial(7), 5040, "factorial (iter)")
 --[[
 
   Knuth's "man or boy" test.
-  See http://en.wikipedia.org/wiki/Man_or_boy_test
+  See https://en.wikipedia.org/wiki/Man_or_boy_test
 
 ]]
 
diff --git a/test/lua-Harness-tests/203-lexico.t b/test/lua-Harness-tests/203-lexico.t
index 396a167f..ef6f9212 100755
--- a/test/lua-Harness-tests/203-lexico.t
+++ b/test/lua-Harness-tests/203-lexico.t
@@ -19,7 +19,7 @@
 =head2 Description
 
 See "Lua 5.3 Reference Manual", section 3.1 "Lexical Conventions",
-L<http://www.lua.org/manual/5.3/manual.html#3.1>.
+L<https://www.lua.org/manual/5.3/manual.html#3.1>.
 
 See section "Lexical Conventions"
 L<https://www.lua.org/manual/5.1/manual.html#2.1>,
diff --git a/test/lua-Harness-tests/241-standalone.t b/test/lua-Harness-tests/241-standalone.t
index e4cf83b5..afbcf5b8 100755
--- a/test/lua-Harness-tests/241-standalone.t
+++ b/test/lua-Harness-tests/241-standalone.t
@@ -45,6 +45,7 @@ end
 
 local lua = _retrieve_progname()
 local luac = jit and lua or (lua .. 'c')
+local exists_luac = io.open(luac, 'r')
 
 if not pcall(io.popen, lua .. [[ -e "a=1"]]) then
     skip_all "io.popen not supported"
@@ -78,7 +79,7 @@ else
 end
 f:close()
 
-if has_bytecode then
+if has_bytecode and exists_luac then
     if jit then
         os.execute(lua .. " -b hello-241.lua hello-241.luac")
     else
diff --git a/test/lua-Harness-tests/242-luac.t b/test/lua-Harness-tests/242-luac.t
index 526b31fe..c15c9a54 100755
--- a/test/lua-Harness-tests/242-luac.t
+++ b/test/lua-Harness-tests/242-luac.t
@@ -41,6 +41,10 @@ end
 local lua = _retrieve_progname()
 local luac = lua .. 'c'
 
+if not io.open(luac, 'r') then
+    skip_all "no luac"
+end
+
 if not pcall(io.popen, lua .. [[ -e "a=1"]]) then
     skip_all "io.popen not supported"
 end
diff --git a/test/lua-Harness-tests/301-basic.t b/test/lua-Harness-tests/301-basic.t
index 01e187d9..4adbb55c 100755
--- a/test/lua-Harness-tests/301-basic.t
+++ b/test/lua-Harness-tests/301-basic.t
@@ -167,7 +167,7 @@ end
     f:close()
     dofile('lib-301.lua')
     local n = norm(3.4, 1.0)
-    matches(twice(n), '^7%.088', "function dofile")
+    near(twice(n), 7.088, 0.001, "function dofile")
 
     os.remove('lib-301.lua') -- clean up
 
diff --git a/test/lua-Harness-tests/304-string.t b/test/lua-Harness-tests/304-string.t
index 82e0408d..ac7e802a 100755
--- a/test/lua-Harness-tests/304-string.t
+++ b/test/lua-Harness-tests/304-string.t
@@ -277,7 +277,7 @@ do -- format
     equals(string.format("%s %d", r, r:len()), r .. " 200")
 
     error_matches(function () string.format("%s %s", 1) end,
-            "^[^:]+:%d+: bad argument #3 to 'format' %(.-no value%)",
+            "^[^:]+:%d+: bad argument #3 to 'format' %(.-value.-%)",
             "function format (too few arg)")
 
     error_matches(function () string.format('%d', 'toto') end,
diff --git a/test/lua-Harness-tests/307-math.t b/test/lua-Harness-tests/307-math.t
index 08b1e5ec..757637f8 100755
--- a/test/lua-Harness-tests/307-math.t
+++ b/test/lua-Harness-tests/307-math.t
@@ -56,20 +56,20 @@ do -- abs
 end
 
 do -- acos
-    matches(math.acos(0.5), '^1%.047', "function acos")
+    near(math.acos(0.5), 1.047, 0.001, "function acos")
 end
 
 do -- asin
-    matches(math.asin(0.5), '^0%.523', "function asin")
+    near(math.asin(0.5), 0.523, 0.001, "function asin")
 end
 
 do -- atan
-    matches(math.atan(0.5), '^0%.463', "function atan")
+    near(math.atan(0.5), 0.463, 0.001, "function atan")
 end
 
 -- atan2
 if has_mathx then
-    matches(math.atan2(1.0, 2.0), '^0%.463', "function atan2")
+    near(math.atan2(1.0, 2.0), 0.463, 0.001, "function atan2")
 else
     is_nil(math.atan2, "function atan2 (removed)")
 end
@@ -84,12 +84,12 @@ do -- ceil
 end
 
 do -- cos
-    matches(math.cos(1.0), '^0%.540', "function cos")
+    near(math.cos(1.0), 0.540, 0.001, "function cos")
 end
 
 -- cosh
 if has_mathx then
-    matches(math.cosh(1.0), '^1%.543', "function cosh")
+    near(math.cosh(1.0), 1.543, 0.001, "function cosh")
 else
     is_nil(math.cosh, "function cosh (removed)")
 end
@@ -99,7 +99,7 @@ do -- deg
 end
 
 do -- exp
-    matches(math.exp(1.0), '^2%.718', "function exp")
+    near(math.exp(1.0), 2.718, 0.001, "function exp")
 end
 
 do -- floor
@@ -112,9 +112,9 @@ do -- floor
 end
 
 do -- fmod
-    matches(math.fmod(7.0001, 0.3), '^0%.100', "function fmod (float)")
-    matches(math.fmod(-7.0001, 0.3), '^-0%.100')
-    matches(math.fmod(-7.0001, -0.3), '^-0%.100')
+    near(math.fmod(7.0001, 0.3), 0.100, 0.001, "function fmod (float)")
+    near(math.fmod(-7.0001, 0.3), -0.100, 0.001)
+    near(math.fmod(-7.0001, -0.3), -0.100, 0.001)
     if math.type then
         equals(math.type(math.fmod(7.0, 0.3)), 'float')
     end
@@ -155,17 +155,17 @@ else
 end
 
 do -- log
-    matches(math.log(47), '^3%.85', "function log")
+    near(math.log(47), 3.85, 0.01, "function log")
     if has_log_with_base then
-        matches(math.log(47, math.exp(1)), '^3%.85', "function log (base e)")
-        matches(math.log(47, 2), '^5%.554', "function log (base 2)")
-        matches(math.log(47, 10), '^1%.672', "function log (base 10)")
+        near(math.log(47, math.exp(1)), 3.85, 0.01, "function log (base e)")
+        near(math.log(47, 2), 5.554, 0.001, "function log (base 2)")
+        near(math.log(47, 10), 1.672, 0.001, "function log (base 10)")
     end
 end
 
 -- log10
 if has_log10 then
-    matches(math.log10(47.0), '^1%.672', "function log10")
+    near(math.log10(47.0), 1.672, 0.001, "function log10")
 else
     is_nil(math.log10, "function log10 (removed)")
 end
@@ -223,7 +223,7 @@ do -- modf
 end
 
 do -- pi
-    matches(tostring(math.pi), '^3%.14', "variable pi")
+    near(math.pi, 3.14, 0.01, "variable pi")
 end
 
 -- pow
@@ -234,7 +234,7 @@ else
 end
 
 do -- rad
-    matches(math.rad(180), '^3%.14', "function rad")
+    near(math.rad(180), 3.14, 0.01, "function rad")
 end
 
 do -- random
@@ -291,27 +291,27 @@ do -- randomseed
 end
 
 do -- sin
-    matches(math.sin(1.0), '^0%.841', "function sin")
+    near(math.sin(1.0), 0.841, 0.001, "function sin")
 end
 
 -- sinh
 if has_mathx then
-    matches(math.sinh(1), '^1%.175', "function sinh")
+    near(math.sinh(1), 1.175, 0.001, "function sinh")
 else
     is_nil(math.sinh, "function sinh (removed)")
 end
 
 do -- sqrt
-    matches(math.sqrt(2), '^1%.414', "function sqrt")
+    near(math.sqrt(2), 1.414, 0.001, "function sqrt")
 end
 
 do -- tan
-    matches(math.tan(1.0), '^1%.557', "function tan")
+    near(math.tan(1.0), 1.557, 0.001, "function tan")
 end
 
 -- tanh
 if has_mathx then
-    matches(math.tanh(1), '^0%.761', "function tanh")
+    near(math.tanh(1), 0.761, 0.001, "function tanh")
 else
     is_nil(math.tanh, "function tanh (removed)")
 end
diff --git a/test/lua-Harness-tests/310-debug.t b/test/lua-Harness-tests/310-debug.t
index f8338d1f..a75047f2 100755
--- a/test/lua-Harness-tests/310-debug.t
+++ b/test/lua-Harness-tests/310-debug.t
@@ -42,8 +42,6 @@ local has_setmetatable52 = _VERSION >= 'Lua 5.2' or (profile.luajit_compat52 and
 local has_upvalueid = _VERSION >= 'Lua 5.2' or jit
 local has_upvaluejoin = _VERSION >= 'Lua 5.2' or jit
 
-local debug = require 'debug'
-
 if not debug then
     skip_all("no debug")
 end
diff --git a/test/lua-Harness-tests/320-stdin.t b/test/lua-Harness-tests/320-stdin.t
index f4de97fd..cc867309 100755
--- a/test/lua-Harness-tests/320-stdin.t
+++ b/test/lua-Harness-tests/320-stdin.t
@@ -32,7 +32,7 @@ if not pcall(io.popen, lua .. [[ -e "a=1"]]) then
     skip_all "io.popen not supported"
 end
 
-plan(12)
+plan'no_plan'
 
 do
     local f = io.open('lib-320.lua', 'w')
@@ -49,7 +49,7 @@ end
 
     local cmd = lua .. [[ -e "dofile(); n = norm(3.4, 1.0); print(twice(n))" < lib-320.lua]]
     f = io.popen(cmd)
-    matches(f:read'*l', '^7%.088', "function dofile (stdin)")
+    near(f:read'*n', 7.088, 0.001, "function dofile (stdin)")
     f:close()
 
     os.remove('lib-320.lua') -- clean up
@@ -102,14 +102,14 @@ do
 
     local cmd = lua .. [[ -e "while true do local n1, n2, n3 = io.read('*number', '*number', '*number'); if not n1 then break end; print(math.max(n1, n2, n3)) end" < number-320.txt]]
     f = io.popen(cmd)
-    matches(f:read'*l', '15000%.?', "function io:read *number")
-    equals(f:read'*l', '1000001')
+    equals(f:read'*n', 15000, "function io:read *number")
+    equals(f:read'*n', 1000001)
     f:close()
 
     os.remove('number-320.txt') -- clean up
 end
 
-do
+if debug then
     local f = io.open('dbg-320.txt', 'w')
     f:write("print 'ok'\n")
     f:write("error 'dbg'\n")
@@ -123,8 +123,12 @@ do
     f:close()
 
     os.remove('dbg-320.txt') -- clean up
+else
+    diag("no debug")
 end
 
+done_testing()
+
 -- Local Variables:
 --   mode: lua
 --   lua-indent-level: 4
diff --git a/test/lua-Harness-tests/401-bitop.t b/test/lua-Harness-tests/401-bitop.t
index 84259cd3..66a99eb2 100755
--- a/test/lua-Harness-tests/401-bitop.t
+++ b/test/lua-Harness-tests/401-bitop.t
@@ -18,7 +18,7 @@
 
 =head2 Description
 
-See L<http://bitop.luajit.org/>.
+See L<https://bitop.luajit.org/>.
 
 =cut
 
diff --git a/test/lua-Harness-tests/402-ffi.t b/test/lua-Harness-tests/402-ffi.t
index 48ae8c20..22d47aec 100755
--- a/test/lua-Harness-tests/402-ffi.t
+++ b/test/lua-Harness-tests/402-ffi.t
@@ -18,7 +18,7 @@
 
 =head2 Description
 
-See L<http://luajit.org/ext_ffi.html>.
+See L<https://luajit.org/ext_ffi.html>.
 
 =cut
 
diff --git a/test/lua-Harness-tests/403-jit.t b/test/lua-Harness-tests/403-jit.t
index 1724dfd1..0f986da9 100755
--- a/test/lua-Harness-tests/403-jit.t
+++ b/test/lua-Harness-tests/403-jit.t
@@ -18,7 +18,7 @@
 
 =head2 Description
 
-See L<http://luajit.org/ext_jit.html>.
+See L<https://luajit.org/ext_jit.html>.
 
 =cut
 
diff --git a/test/lua-Harness-tests/404-ext.t b/test/lua-Harness-tests/404-ext.t
index 45701671..c3b8370d 100755
--- a/test/lua-Harness-tests/404-ext.t
+++ b/test/lua-Harness-tests/404-ext.t
@@ -18,7 +18,7 @@
 
 =head2 Description
 
-See L<http://luajit.org/ext_jit.html>.
+See L<https://luajit.org/ext_jit.html>.
 
 =cut
 
diff --git a/test/lua-Harness-tests/411-luajit.t b/test/lua-Harness-tests/411-luajit.t
index da1af9ce..3a9a7b8f 100755
--- a/test/lua-Harness-tests/411-luajit.t
+++ b/test/lua-Harness-tests/411-luajit.t
@@ -18,7 +18,7 @@
 
 =head2 Description
 
-See L<http://luajit.org/running.html>
+See L<https://luajit.org/running.html>
 
 =cut
 
diff --git a/test/lua-Harness-tests/profile_ravi.lua b/test/lua-Harness-tests/profile_ravi.lua
index 8cd2464e..fcee5cb1 100644
--- a/test/lua-Harness-tests/profile_ravi.lua
+++ b/test/lua-Harness-tests/profile_ravi.lua
@@ -31,7 +31,7 @@ local profile = {
 --]]
 
     nocvtn2s = false,
-    nocvts2n = false,
+    nocvts2n = true,
 
     compat53 = false,
 --[[
@@ -51,7 +51,7 @@ package.loaded.profile = profile        -- prevents loading of default profile
 return profile
 
 --
--- Copyright (c) 2018-2019 Francois Perrad
+-- Copyright (c) 2018-2021 Francois Perrad
 --
 -- This library is licensed under the terms of the MIT/X11 license,
 -- like Lua itself.
diff --git a/test/lua-Harness-tests/test_assertion.lua b/test/lua-Harness-tests/test_assertion.lua
index 67cf37f9..a4a9c6ca 100644
--- a/test/lua-Harness-tests/test_assertion.lua
+++ b/test/lua-Harness-tests/test_assertion.lua
@@ -94,6 +94,15 @@ function not_equals (got, not_expected, name)
     end
 end
 
+function near (got, expected, tolerance, name)
+    local pass = got >= (expected - tolerance) and got <= (expected + tolerance)
+    truthy(pass, name)
+    if not pass then
+        diag("         got: " .. tostring(got))
+        diag("    expected: " .. tostring(expected) .. " +/- " .. tostring(tolerance))
+    end
+end
+
 function matches (got, pattern, name)
     local pass = tostring(got):match(pattern)
     truthy(pass, name)
-- 
2.32.0



More information about the Tarantool-patches mailing list