bluebird75 / luaunit

LuaUnit is a popular unit-testing framework for Lua, with an interface typical of xUnit libraries (Python unittest, Junit, NUnit, ...). It supports several output formats (Text, TAP, JUnit, ...) to be used directly or work with Continuous Integration platforms (Jenkins, Maven, ...).
Other
565 stars 136 forks source link

can i search test_xxx from _ENV #147

Closed shewer closed 2 years ago

shewer commented 2 years ago

I want to test sub env for example as below. thk,.

local new_env()
   local tab={}
   for k,v in ipairs({ math,package,require) do
      tab[k] = _ENV[k] 
   end
   return tab
end
local lut = require 'luaunit'
local _ENV = new_env()
-- now  test_abc in local _ENV 
function test_abc()
end
lut.run()
bluebird75 commented 2 years ago

If I get it correctly, you want to create a kind of restricted environment / sandbox, where you would run your luaunit tests ?

Did you try to run it already ? The only problem I could see is how luaunit discovers tests. Normally, it discovers them from the global namespace. If that does not work, it is possible to run an explicit test function using something like:

runSuiteByInstances( { { 'test_abc', test_abc } } )

shewer commented 2 years ago

thank you a lot, The question has been resolved