aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-10-17 13:36:40 +0100
committerMatthew Wild <mwild1@gmail.com>2009-10-17 13:36:40 +0100
commitc2161ee15e90da91201a5c4dee584eac4337f5ae (patch)
treefe9a8463c974dae55b8a439913c021b700988b89 /tests/test.lua
parentb33e93f19be03c056c533e651385b67000e804cc (diff)
downloadprosody-c2161ee15e90da91201a5c4dee584eac4337f5ae.tar.gz
prosody-c2161ee15e90da91201a5c4dee584eac4337f5ae.zip
tests: More environment magic to help get stuff working in a sandbox
Diffstat (limited to 'tests/test.lua')
-rw-r--r--tests/test.lua13
1 files changed, 8 insertions, 5 deletions
diff --git a/tests/test.lua b/tests/test.lua
index 4f41cd1d..f5976a02 100644
--- a/tests/test.lua
+++ b/tests/test.lua
@@ -30,9 +30,11 @@ else
package.cpath = package.cpath..";../?.so";
end
+local _realG = _G;
+
require "util.import"
-local env_mt = { __index = function (t,k) return rawget(_G, k) or print("WARNING: Attempt to access nil global '"..tostring(k).."'"); end };
+local env_mt = { __index = function (t,k) return rawget(_realG, k) or print("WARNING: Attempt to access nil global '"..tostring(k).."'"); end };
function testlib_new_env(t)
return setmetatable(t or {}, env_mt);
end
@@ -66,7 +68,7 @@ end
function dosingletest(testname, fname)
- local tests = setmetatable({}, { __index = _G });
+ local tests = setmetatable({}, { __index = _realG });
tests.__unit = testname;
tests.__test = fname;
local chunk, err = loadfile(testname);
@@ -104,7 +106,7 @@ function dosingletest(testname, fname)
end
function dotest(unitname)
- local tests = setmetatable({}, { __index = _G });
+ local tests = setmetatable({}, { __index = _realG });
tests.__unit = unitname;
local chunk, err = loadfile("test_"..unitname:gsub("%.", "_")..".lua");
if not chunk then
@@ -119,8 +121,9 @@ function dotest(unitname)
return;
end
- local unit = setmetatable({}, { __index = setmetatable({ module = function () _M = getfenv(2); end }, { __index = _G }) });
-
+ if tests.env then setmetatable(tests.env, { __index = _realG }); end
+ local unit = setmetatable({}, { __index = setmetatable({ _G = tests.env or _G }, { __index = tests.env or _G }) });
+ unit._G = unit; _realG._G = unit;
local fn = "../"..unitname:gsub("%.", "/")..".lua";
local chunk, err = loadfile(fn);
if not chunk then