Diff

tests/test.lua @ 7051:ecfa474ff570

tests/test.lua: Fix fake module() function to prevent _M from being _G (test.lua's environment), which caused modules to break the sandbox when they set _M.*
author Matthew Wild <mwild1@gmail.com>
date Wed, 06 Jan 2016 00:24:06 +0000
parent 6594:fa6eb6fb4a80
child 7061:eda0feeaf759
line wrap: on
line diff
--- a/tests/test.lua	Wed Dec 23 12:07:03 2015 +0100
+++ b/tests/test.lua	Wed Jan 06 00:24:06 2016 +0000
@@ -137,7 +137,10 @@
 	end
 	
 	local oldmodule, old_M = _fakeG.module, _fakeG._M;
-	_fakeG.module = function () _M = _G end
+	_fakeG.module = function ()
+		setmetatable(unit, nil);
+		unit._M = unit;
+	end
 	setfenv(chunk, unit);
 	local success, err = pcall(chunk);
 	_fakeG.module, _fakeG._M = oldmodule, old_M;