Module:Unitest Scribunto

From eCatalog Manager Wiki
Jump to navigation Jump to search

--[[ -- Module:Unitest_Scribunto start -- http://www.mediawiki.org/wiki/Module:Unitest_Scribunto

   Example of result :
  • Init of unit tests. test_list = table
  • Begin of unit tests :
  • 1 Site tested : mw.uri.fullUrl = //fr.wikisource.org/wiki/Module:Auteur.
  • 2 Environment : Mediawiki 1.21wmf10 (d6c6dba) version UTC 2013-03-01 21:53:59.
  • 3 Runtime and spaces : server UTC 2013-03-04 01:09:22, namespace=Modèle module_space=Module, template_space=Modèle viewErrors=true.
  • 4 frame.args Error : frame.args.lastname = "error". The OK value was "OK" = frame:getParent().args.lastname.
  • 5 sub table write Test OK : sub table write OK. / / / result OKOK ; exec_ok=true ; value_ok=true ; var_tested=td.C.X ; value_before=xx ; value_after=okvalue ; A=aa ; Y=yy .
  • 6 Is Scribunto complete ? Error : Scribunto is not complete. / / / ; math=table ; os=table ; package=table ; string=table ; table=table ; mw=table ; frame=table ; mw.language=table ; mw.message=nil ; mw.site=table ; mw.title=nil ; mw.uri=table ; mw.ustring=table .
  • End of unit tests. Statistic count : Nerr=2 / Ntests=6

Guide and template

Unitest_Scribunto like/from Scribunto_LuaEngineTestBase http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Test_cases class ClassNameTest extends Scribunto_LuaEngineTestBase {

   protected static $moduleName = 'ClassNameTest';

function getTestModules() { return parent::getTestModules() + array( 'ClassNameTest' => __DIR__ . 'ClassNameTests.lua'; ); } } local testframework = require 'Module:TestFramework' return testframework.getTestProvider( { -- Tests go here } ) Each test is itself a table, with the following properties:

   name: The name of the test.
   func: The function to execute.
   args: Optional table of arguments to pass to the function.
   expect: Results to expect.
   type: Optional "type" of the test, default is "Normal".

local function AuteurTestCurrentNamespace(space) { -- This repair a Lua bug : Module give nothing in fr.wikisource.org current_space = frame:preprocess("Module") -- present namespace from system -- This repair a Lua bug : mw.site.namespaces.name is unknown module_space = frame:preprocess("Module") -- Module namespace from system template_space = frame:preprocess("Template") -- Module namespace from system author_space = frame:preprocess("Template:Ns:Author") -- Author namespace from system category_space = frame:preprocess("Category") -- Category namespace from system if current_space == space then end return space .. "OK" }

class ClassAuteurTest extends Scribunto_LuaEngineTestBase { protected static $moduleName = 'ClassAuteurTest'; function getTestModules() { return parent::getTestModules() + array( 'ClassAuteurTest' => __DIR__ . 'ClassAuteurTest.lua'; ); } }

-- local unitestScribunto = require "Module:Unitest_Scribunto"

--]]

local formatdate = function(date_time) -- formatime(date_time) -- formate "20130302153557" en "2013-03-02 15:35:57" date_time = tostring(date_time.year) .. "-" .. tostring(date_time.month) .. "-" .. tostring(date_time.day) .. " " .. tostring(date_time.hour) .. ":" .. tostring(date_time.min) .. ":" .. tostring(date_time.sec) return date_time end -- local formatdate = function(date_time)

local formatime = function(date_time) -- formatime(date_time) -- formate "20130302153557" en "2013-03-02 15:35:57" date_time = tostring(date_time) date_time = string.sub(date_time, 1, 4) .. "-" .. string.sub(date_time, 5, 6) .. "-" .. string.sub(date_time, 7, 8) .. " " .. string.sub(date_time, 9, 10) .. ":" .. string.sub( date_time, 11, 12) .. ":" .. string.sub(date_time, 13, 14) return date_time end -- local formatime = function(date_time)

local function if_exist(ok, wt, mw_uri, mw_uri_name) -- ok, wt = if_exist(ok, wt, mw.uri, 'mw.uri') local isnil = tostring(mw_uri) local t = mw_uri_name .. '=' .. isnil if isnil == "nil" then -- Y a-t-il erreur de valeur ? ok = false -- Il y a une erreur de valeur wt = wt .. ' ; ' .. t .. '' else ok = ok -- Il n'y a pas d'erreur de valeur wt = wt .. ' ; ' .. t end return ok, wt end -- function if_exist(ok, wt, mw_uri, mw_uri_name)

local sub_table_write_data = { A = "aa", B = "bb", C = { X = "xx", Y = "yy" }, lastname = "Voltaire", } -- sub_table_write_data

-- local arglingual = tostring(args_trad.lastname) -- multilingual name of the arg -- local arglingual = sub_table_write_data.lastname

-- Series of unit tests. Série de tests unitaires. -- require 'Module:TestFramework' -- similar to : class ClassNameTest extends Scribunto_LuaEngineTestBase { local tst = {

test_frame = nil, -- frame

test_result = "",

test_list = { -- Tests go here },

} -- tst object like Scribunto_LuaEngineTestBase

local Unitest_Scribunto_tested_site = { name = "Tested site", func_test = function(parm, frame) -- Get environment local ok, out_OK, out_HS = true, parm.expect, "error" local t = "" local mw_uri_fullUrl = mw.uri.fullUrl('Module:Auteur') -- "Module:Auteur" ) t = t .. ": mw.uri.fullUrl = " .. tostring(mw_uri_fullUrl) -- local mw_uri = mw.uri.new('Module:Auteur') -- "Module:Auteur" ) -- mw.uri.new( s ) -- local mw_title = mw.title.new('Module:Auteur') -- "Module:Auteur" ) -- t = t .. ": mw.uri.prefixedText = " .. tostring(mw_uri.prefixedText) -- futur : mw.title.new( 'Module:Foo', 'Template' ) will create an object for the page Module:Foo -- mw.title.makeTitle( 'Template', 'Module:Foo' ) will create an object for the page Template:Module:Foo. -- mw.title object : -- nsText: The text of the namespace for the page. -- prefixedText: The title of the page, with the namespace and interwiki prefixes. -- fullText: The title of the page, with the namespace and interwiki prefixes and the fragment.

-- local preprocess_url = frame:preprocess("http://wiki.cymaxtec.com/Module:Auteur") -- t = t .. "
preprocess_url = " .. tostring(preprocess_url) out_OK = t out_HS = t return ok, tostring(out_OK), tostring(out_HS) end, args = {"x"}, expect = "OK", type = "ToString", ifok = "_N_TEST_ _PRM_NM_ _OUT_OK_.", iferr = '_N_TEST_ _PRM_NM_ _OUT_HS_.', } -- Unitest_Scribunto_tested_site

local Unitest_Scribunto_environment = { name = "Environment", func_test = function(parm, frame) -- Get environment local ok, out_OK, out_HS = true, parm.expect, "error" local t = "" local date_time = frame:preprocess("20240529184255") local now_date = os.date("%Y-%m-%d %H:%M:%S") local mw_version = frame:preprocess("1.34.1") local revision_time = frame:preprocess("20160830175727") local dtnow, dtvers = now_date, revision_time -- dtnow = formatime(now_date) dtvers = formatime(dtvers) t = t .. ": Mediawiki " .. tostring(mw_version) .. " version UTC " .. tostring(dtvers) -- t = t .. " read by { {CURRENTVERSION} }" out_OK = t out_HS = t return ok, tostring(out_OK), tostring(out_HS) end, args = {"x"}, expect = "OK", type = "ToString", ifok = "_N_TEST_ _PRM_NM_ _OUT_OK_.", iferr = '_N_TEST_ _PRM_NM_ _OUT_HS_.', } -- Unitest_Scribunto_environment

local Unitest_Scribunto_runtime_spaces = { name = "Runtime and spaces", func_test = function(parm, frame) local ok, out_OK, out_HS = true, parm.expect, "error" local now_date = os.date("%Y-%m-%d %H:%M:%S") local namespace = frame:preprocess("Module") -- present namespace from system local module_space = frame:preprocess("Module") -- Module namespace from system local template_space = frame:preprocess("Template") -- Module namespace from system local viewErrors = (namespace == module_space) or (namespace == template_space) local t = "" t = t .. ": server UTC " .. tostring(now_date) .. ", namespace=" .. tostring(namespace) t = t .. " module_space=" .. tostring(module_space) .. ", template_space=" .. tostring(template_space) t = t .. " viewErrors=" .. tostring(viewErrors) --[[ current_space = frame:preprocess("Module") -- present namespace from system -- mw.site.namespaces.name is unknown module_space = frame:preprocess("Module") -- Module namespace from system template_space = frame:preprocess("Template") -- Module namespace from system author_space = frame:preprocess("Template:Ns:Author") -- Author namespace from system category_space = frame:preprocess("Category") -- Category namespace from system local current_space = frame:preprocess("Module") -- present namespace from system local REVISIONUSER = frame:preprocess("Admin") -- current user when previewing an edit local ns_Module = frame:preprocess("Module") -- User namespace translated local ns_Template = frame:preprocess("Template") -- User namespace translated local int_edit = frame:preprocess("Edit") -- Edit → Edit, translate "edit" local language_ar = frame:preprocess("العربية") -- full name of the language -- Module:Unitest_Scribunto Unitest_Scribunto Unitest_Scribunto Unitest_Scribunto -- Module:Unitest_Scribunto Module:Unitest_Scribunto Module_talk:Unitest_Scribunto local ARTICLEPAGENAMEE = frame:preprocess("Module:Unitest_Scribunto") local date_time = frame:preprocess("20240529184255") local mw_version = frame:preprocess("1.34.1") local revision_time = frame:preprocess("20160830175727") local now_date = os.date("%Y-%m-%d %H:%M:%S") -- local date_time = frame:preprocess("20240529184255") -- local mw_version = frame:preprocess("1.34.1") -- local revision_time = frame:preprocess("20160830175727") -- local dtnow, dtvers = now_date, revision_time -- dtnow = formatime(dtnow) -- dtvers = formatime(dtvers) -- t = t .. " read by { {CURRENTTIMESTAMP} }" --]] out_OK = t out_HS = t return ok, tostring(out_OK), tostring(out_HS) end, args = {"x"}, expect = "OK", type = "ToString", ifok = "_N_TEST_ _PRM_NM_ _OUT_OK_.", iferr = '_N_TEST_ _PRM_NM_ _OUT_HS_.', } -- Unitest_Scribunto_runtime_spaces

local Unitest_Scribunto_frame_args = { name = "frame.args", func_test = function(parm, frame) -- * frame:getParent().args.lastname = Rimbaud -- * frame.args.lastname = nil local ok, out_OK, out_HS = true, parm.expect, "error" local frame_args = frame.args local getParent_args = frame:getParent().args local arglingual = tostring("lastname") -- multilingual name of the arg local frame_val = tostring(frame_args[arglingual]) local getParent_val = tostring(getParent_args[arglingual]) local t = "* " .. tostring(parm.name) .. " " local ok, out_REF, out_TEST = true, "", "" out_REF = tostring(getParent_val) out_TEST = tostring(frame_val) if out_TEST == out_REF then -- OK ok = true else -- HS bug ok = false end return ok, tostring(out_OK), tostring(out_HS) end, args = {"x"}, expect = "OK", type = "ToString", ifok = '_N_TEST_ _PRM_NM_ Test OK : frame.args.lastname = "_OUT_HS_".', iferr = '_N_TEST_ _PRM_NM_ Error : frame.args.lastname = "_OUT_HS_". The OK value was "_OUT_OK_" = frame:getParent().args.lastname.', } -- Unitest_Scribunto_frame_args

local function sub_table_write_function_OK(td) -- test d'ecriture dans une sous table local A = td.A local Y = td.C.Y local var_tested = "td.C.X" local value_before = td.C.X local value_after = value_before td.C.X = "okvalue" -- INSTRUCTION UNDER TEST value_after = td.C.X -- verifier aussi l'ecriture puis lecture local value_ok = ( value_after == "okvalue" ) return value_ok, var_tested, value_before, value_after, A, Y end -- function sub_table_write_function_OK(td)

local Unitest_Scribunto_sub_table_write_OK = { name = "sub table write OK", func_test = function(parm, frame) -- * Test sub table read OK : Test cx : td.C.X = cx, expected = cx, test OK. -- * Test sub table write HS : Test x : tst.test_data.C.X = new val -> error -- pcall( func, args ) -- return { true, func() } or return { false, error message } -- how to read cousins in table, like cd ..other branch local ok, out_OK, out_HS = true, parm.expect, "error" -- local td_C_X_read = td.C.X -- Run a protected call to detect the execution error local exec_ok, value_ok, var_tested, value_before, value_after, A, Y = pcall( sub_table_write_function_OK, sub_table_write_data ) local outest = " ; exec_ok=" .. tostring(exec_ok) .. " ; value_ok=" .. tostring(value_ok) .. " ; var_tested=" .. tostring(var_tested) .. " ; value_before=" .. tostring(value_before) .. " ; value_after=" .. tostring(value_after) .. " ; A=" .. tostring(A) .. " ; Y=" .. tostring(Y) if exec_ok then -- OK ok = true -- Il n'y a pas d'erreur d'execution out_OK = " result OK-- " .. outest if value_ok then -- Y a-t-il erreur de valeur ? ok = true -- Il n'y a pas d'erreur de valeur out_OK = " result OKOK " .. outest else -- HS bug ok = false -- Il y a une erreur de valeur out_HS = " result OKHS " .. outest end else -- HS bug ok = false -- ll y a une erreur d'execution out_HS = " result HS-- " .. outest end return ok, tostring(out_OK), tostring(out_HS) end, args = {"x"}, expect = "OK", type = "ToString", ifok = '_N_TEST_ _PRM_NM_ Test OK : sub table write OK. / / / _OUT_OK_ .', iferr = '_N_TEST_ _PRM_NM_ Error : sub table write HS. / / / _OUT_HS_ .', } -- Unitest_Scribunto_sub_table_write_OK

local function sub_table_write_function_XX(td) -- test d'ecriture dans une sous table local A = td.A local Y = td.C.Y local var_tested = "td.C.X" local value_before = td.C.X local value_after = value_before -- local args_known = Argts.args_known -- PREVIEW LOCAL ORIGINAL INSTRUCTION -- local argname_ = Argts.args_known[argname] -- ORIGINAL INSTRUCTION WITH ERROR td.C.X = "okvalue" -- INSTRUCTION UNDER TEST -- -- function Argts.arg_input(args_src, argname, tr) -- ORIGINAL FUNCTION WITH ERROR -- local args_known = Argts.args_known -- PREVIEW LOCAL ORIGINAL INSTRUCTION -- local argname_ = Argts.args_known[argname] -- ORIGINAL INSTRUCTION WITH ERROR -- Lua error in Module:Multilingual_Arguments at line 847: attempt to index field 'args_known' (a nil value). -- value_after = td.C.X -- verifier aussi l'ecriture puis lecture local value_ok = ( value_after == "okvalue" ) return value_ok, var_tested, value_before, value_after, A, Y end -- function sub_table_write_function_XX(td)

local Unitest_Scribunto_sub_table_write_XX = { name = "sub table write XX", func_test = function(parm, frame) -- * Test sub table read OK : Test cx : td.C.X = cx, expected = cx, test OK. -- * Test sub table write HS : Test x : tst.test_data.C.X = new val -> error -- pcall( func, args ) -- return { true, func() } or return { false, error message } -- how to read cousins in table, like cd ..other branch local ok, out_OK, out_HS = true, parm.expect, "error" -- local td_C_X_read = td.C.X -- Run a protected call to detect the execution error local exec_ok, value_ok, var_tested, value_before, value_after, A, Y = pcall( sub_table_write_function_XX, sub_table_write_data ) local outest = " ; exec_ok=" .. tostring(exec_ok) .. " ; value_ok=" .. tostring(value_ok) .. " ; var_tested=" .. tostring(var_tested) .. " ; value_before=" .. tostring(value_before) .. " ; value_after=" .. tostring(value_after) .. " ; A=" .. tostring(A) .. " ; Y=" .. tostring(Y) if exec_ok then -- OK ok = true -- Il n'y a pas d'erreur d'execution out_OK = " result OK-- " .. outest if value_ok then -- Y a-t-il erreur de valeur ? ok = true -- Il n'y a pas d'erreur de valeur out_OK = " result OKOK " .. outest else -- HS bug ok = false -- Il y a une erreur de valeur out_HS = " result OKHS " .. outest end else -- HS bug ok = false -- ll y a une erreur d'execution out_HS = " result HS-- " .. outest end return ok, tostring(out_OK), tostring(out_HS) end, args = {"x"}, expect = "OK", type = "ToString", ifok = '_N_TEST_ _PRM_NM_ Test OK : sub table write OK. / / / _OUT_OK_ .', iferr = '_N_TEST_ _PRM_NM_ Error : sub table write HS. / / / _OUT_HS_ .', } -- Unitest_Scribunto_sub_table_write_XX

local Unitest_Scribunto_complete = { name = "Is Scribunto complete ?", func_test = function(parm, frame) -- * Test sub table read OK : Test cx : td.C.X = cx, expected = cx, test OK. -- * Test sub table write HS : Test x : tst.test_data.C.X = new val -> error -- pcall( func, args ) -- return { true, func() } or return { false, error message } -- how to read cousins in table, like cd ..other branch local ok, out_OK, out_HS = true, parm.expect, "error" -- local td_C_X_read = td.C.X -- Run a protected call to detect the execution error local exec_ok, value_ok, var_tested, value_before, value_after, A, Y = pcall( sub_table_write_function_OK, sub_table_write_data ) local outest = " ; exec_ok=" .. tostring(exec_ok) .. " ; value_ok=" .. tostring(value_ok) .. " ; var_tested=" .. tostring(var_tested) .. " ; value_before=" .. tostring(value_before) .. " ; value_after=" .. tostring(value_after) .. " ; A=" .. tostring(A) .. " ; Y=" .. tostring(Y) local ok, wt = true, ok, wt = if_exist(ok, wt, math, 'math') ok, wt = if_exist(ok, wt, os, 'os') ok, wt = if_exist(ok, wt, package, 'package') ok, wt = if_exist(ok, wt, string, 'string') ok, wt = if_exist(ok, wt, table, 'table') ok, wt = if_exist(ok, wt, mw, 'mw') ok, wt = if_exist(ok, wt, frame, 'frame') ok, wt = if_exist(ok, wt, mw.language, 'mw.language') ok, wt = if_exist(ok, wt, mw.message, 'mw.message') ok, wt = if_exist(ok, wt, mw.site, 'mw.site') ok, wt = if_exist(ok, wt, mw.title, 'mw.title') ok, wt = if_exist(ok, wt, mw.uri, 'mw.uri') ok, wt = if_exist(ok, wt, mw.ustring, 'mw.ustring') out_OK = wt out_HS = wt return ok, tostring(out_OK), tostring(out_HS) end, args = {"x"}, expect = "OK", type = "ToString", ifok = '_N_TEST_ _PRM_NM_ Test OK : sub table write OK. / / / _OUT_OK_ .', iferr = '_N_TEST_ _PRM_NM_ Error : Scribunto is not complete. / / / _OUT_HS_ .', } -- Unitest_Scribunto_complete

-- empty: can be removed -- test: the title librairy

-- try argname to skip if unknown

-- mw content list -- dump a table content, with formating -- local p = {} function tst.doctable_recursive(tbl, uppername, name, level_i, levelmaxi, exclude1, exclude2, exclude3) local res, newname, part, shift = "", "", "", "" local sep = "," local isempty = true local levelname = uppername .. "." .. name -- limit the number of the level of sub-tables level_i = tonumber(level_i) if type(level_i) ~= "number" then level_i = 1 end levelmaxi = tonumber(levelmaxi) if type(levelmaxi) ~= "number" then levelmaxi = 99 end if level_i > levelmaxi then return "" end -- -- exit if exclude1 exclude2 exclude3 are in name if type(exclude1) == "string" then if string.find(name, exclude1) ~= nil then return "" end end if type(exclude2) == "string" then if string.find(name, exclude2) ~= nil then return "" end end if type(exclude3) == "string" then if string.find(name, exclude3) ~= nil then return "" end end -- display table error if type(tbl) ~= "table" then return 'Table "' .. tostring(name) .. '" is invalid.
' end -- -- Add all contents, first vars, then functions, then sub-tables list, then sub-tables contents -- Add vars isempty = true shift = string.rep("*", level_i) part = "\n" .. shift .. " Table " .. levelname .. " vars : " sep = ", " -- .. "\n" for k, v in pairs(tbl) do -- var, not functions and tables if (type(v) ~= "function" and type(v) ~= "table") then part = part .. type(v) .. " - " .. tostring(k) .. " = " .. (tostring(v or "<nil>")) .. sep isempty = false end end if not isempty then res = res .. part else res = res .. "\n" .. shift .. " Table " .. levelname .. " no vars." end -- -- Add functions isempty = true part = "\n" .. shift .. " Table " .. levelname .. " functions : " sep = ", " -- .. "\n" for k, v in pairs(tbl) do -- functions if (type(v) == "function") then part = part .. k .. sep isempty = false end end if not isempty then res = res .. part else res = res .. "\n" .. shift .. " Table " .. levelname .. " no functions." end -- -- Add sub-tables list isempty = true part = "\n" .. shift .. " Table " .. levelname .. " tables list : " sep = ", " -- .. "\n" for k, v in pairs(tbl) do -- functions if (type(v) == "table") then part = part .. k .. sep isempty = false end end if isempty then res = res .. "\n" .. shift .. " Table " .. levelname .. " no sub-tables." else res = res .. part -- Add sub-tables contents for k, v in pairs(tbl) do -- only tables newname = "" if (type(v) == "table") then newname = k -- a table, we recursively treat what's inside it if level_i < levelmaxi then res = res .. tst.doctable_recursive(v, levelname, newname, level_i+1, levelmaxi, exclude1, exclude2, exclude3) else -- res = res .. newname .. "" end local sep = "" end end end -- res = res .. "
" return res end -- function tst.doctable_recursive(tbl, uppername, name, level_i, levelmaxi, exclude1, exclude2, exclude3)

function tst.doctable_args(args, table, tablename) local res = "\n* Content of the " .. tostring(tablename) .. " table, begin :" -- test : check mw content local levelmaxi = args.levelmaxi local exclude1 = args.exclude1 local exclude2 = args.exclude2 local exclude3 = args.exclude3 -- limit the number of the level of sub-tables level_i = tonumber(level_i) if type(level_i) ~= "number" then level_i = 1 end levelmaxi = tonumber(levelmaxi) if type(levelmaxi) ~= "number" then levelmaxi = 99 end if level_i > levelmaxi then return "" end res = res .. " levelmaxi=" .. tostring(levelmaxi) res = res .. " exclude1=" .. tostring(exclude1) res = res .. " exclude2=" .. tostring(exclude2) res = res .. " exclude3=" .. tostring(exclude3) res = res .. tst.doctable_recursive(table, "", tablename, 1, levelmaxi, exclude1, exclude2, exclude3) -- function tst.doctable_recursive(tbl, uppername, name, level_i, levelmaxi, exclude1, exclude2, exclude3) res = res .. "\n* Content of the " .. tostring(tablename) .. " table, end.\n" return res end -- function tst.doctable_args(args, table, tablename)

function tst.init( frame, test_list, test_data ) -- tst.init(frame, tst.test_list) -- tst.test_list is the default value if type(frame) == "table" then tst.test_frame = frame end if type(test_list) == "table" then tst.test_list = test_list end -- table.insert( tst.test_list, Unitest_Scribunto_tested_site ) -- table.insert( tst.test_list, Unitest_Scribunto_environment ) -- table.insert( tst.test_list, Unitest_Scribunto_runtime_spaces ) table.insert( tst.test_list, Unitest_Scribunto_frame_args ) table.insert( tst.test_list, Unitest_Scribunto_sub_table_write_OK ) table.insert( tst.test_list, Unitest_Scribunto_sub_table_write_XX ) -- table.insert( tst.test_list, Unitest_Scribunto_complete ) if type(test_data) == "table" then tst.test_data = test_data end local t = "
* Init of unit tests. test_list = " .. tostring( tst.test_list ) .. "
" tst.test_result = tst.test_result .. t

   return t

end -- function tst.init( frame, test_list, test_data )

function tst.run_all_tests( frame )

   local input_args = frame.args.input or frame.args

local result = "" local n, nerr = 0, 0 local ok, out_OK, out_HS = true, "", "" local wt, t = "", "* Begin of unit tests :\n" t = t .. tst.WhereWhenWhatWeWork(frame) .. "
" for key, parm in pairs(tst.test_list) do -- Pour tous les parametres connus n = n + 1 wt = "\n" if parm.type == "ToString" then -- args en ordre numerique et renvoi vers un argument nommé ok, out_OK, out_HS = parm.func_test(parm, frame) -- pcall( func, args ) -- return { true, func() } or return { false, error message } -- t = t .. '* ' .. tostring(n) .. ' ' .. tostring(parm.name) .. ' result =' .. tostring(result) .. ' ' if ok then -- si le test est OK wt = parm.ifok -- t = t .. ' ' .. parm.ifok .. '' .. out_OK .. '
' else -- si le test est HS wt = parm.iferr -- t = t .. '' .. parm.iferr .. '' .. out_HS .. '
' nerr = nerr + 1 end wt = string.gsub(wt, "_PRM_NM_", tostring(parm.name) ) wt = string.gsub(wt, "_N_TEST_", tostring(n) ) wt = string.gsub(wt, "_N_ERR_", tostring(nerr) ) wt = string.gsub(wt, "_OUT_OK_", tostring(out_OK) ) wt = string.gsub(wt, "_OUT_HS_", tostring(out_HS) ) -- t = t .. '* ' .. tostring(n) .. ' ' .. tostring(parm.name) .. ' ' .. wt t = t .. .. wt .. "
"
end end t = t .. "\n*End of unit tests. Statistic count : Nerr=" .. tostring( nerr ) .. " / Ntests=" .. tostring( n ) .. "
" tst.test_result = tst.test_result .. t

   return tst.test_result

end -- function tst.run_all_tests( frame )

function tst.WhereWhenWhatWeWork(frame) local t = "" -- Get where wiki URL local ok, out_OK, out_HS = true, "parm.expect", "error" local title = mw.title.getCurrentTitle() local mw_uri_fullUrl = mw.uri.fullUrl('Module:Unitest Scribunto') -- "Module:Auteur" ) t = t .. ": Page tested = " .. tostring(title.fullUrl( title.subjectPageTitle )) .. "\n" -- Get what version local revision_time = frame:preprocess("20160830175727") dtvers = formatime(revision_time) t = t .. ": Mediawiki " .. mw.site.currentVersion .. " - UTC revision time " .. tostring(dtvers) .. " - " .. _VERSION .. "\n" -- Get when local date_time = frame:preprocess("20240529184255") local now_date = os.date("%Y-%m-%d %H:%M:%S") -- Runtime and spaces local namespace = frame:preprocess("Module") -- present namespace from system local module_space = frame:preprocess("Module") -- Module namespace from system local template_space = frame:preprocess("Template") -- Module namespace from system local viewErrors = (namespace == module_space) or (namespace == template_space) t = t .. ": Server runtime UTC " .. tostring(now_date) .. ", namespace=" .. tostring(namespace) -- .. "\n" -- t = t .. ": module_space=" .. tostring(module_space) .. ", template_space=" .. tostring(template_space) -- t = t .. " viewErrors=" .. tostring(viewErrors) .. "\n" return t end -- local fonction WhereWhenWhatWeWork()

function tst.wwwww(frame) return tst.WhereWhenWhatWeWork(frame) end

-- Interface to document Where When What We Work function tst.unitest_wwwww(frame) local args = frame.args local out = tst.WhereWhenWhatWeWork(frame)

   return out

end

-- Interface to document frame.args. function tst.doctable_frame_args(frame) local frame_args = frame.args local args = frame.args local out = tst.doctable_args(args, frame_args, "frame_args")

   return out

end

-- Interface to document a list of frame. function tst.doctable_frame(frame) local args = frame.args local out = tst.doctable_args(args, frame, "frame")

   return out

end

-- Interface to document a list of Module:mw. function tst.doctable_mw(frame) local out = tst.doctable_args(frame.args, mw, "mw")

   return out

end

-- Interface to document some unit tests. function tst.unitest(frame) local args = frame.args tst.init(frame) -- tst.init( frame, test_list, test_data ) local out = tst.run_all_tests( frame )

   return out

end -- function tst.unitest(frame)

return tst

-- local unitestScribunto = require "Module:Unitest_Scribunto"