2012-12-19 20:10:01 +00:00
|
|
|
local testframework = require( 'Module:TestFramework' )
|
2012-04-19 07:40:56 +00:00
|
|
|
|
2012-12-19 20:10:01 +00:00
|
|
|
local function setfenv1()
|
|
|
|
local ok, err = pcall( function()
|
|
|
|
setfenv( 2, {} )
|
|
|
|
end )
|
|
|
|
if not ok then
|
|
|
|
err = string.gsub( err, '^%S+:%d+: ', '' )
|
|
|
|
error( err )
|
|
|
|
end
|
2012-04-19 07:40:56 +00:00
|
|
|
end
|
|
|
|
|
2012-12-19 20:10:01 +00:00
|
|
|
local function getfenv1()
|
|
|
|
local env
|
|
|
|
pcall( function()
|
|
|
|
env = getfenv( 2 )
|
|
|
|
end )
|
|
|
|
return env
|
2012-04-19 07:40:56 +00:00
|
|
|
end
|
|
|
|
|
2012-12-19 20:10:01 +00:00
|
|
|
return testframework.getTestProvider( {
|
|
|
|
{ name = 'setfenv on a C function', func = setfenv1,
|
|
|
|
expect = "'setfenv' cannot set the requested environment, it is protected",
|
|
|
|
},
|
|
|
|
{ name = 'getfenv on a C function', func = getfenv1,
|
|
|
|
expect = { nil },
|
|
|
|
},
|
|
|
|
} )
|