Add test for combination of print() and tostring(), test case when tostring is changed in global environment.
This commit is contained in:
@@ -112,6 +112,10 @@ public class CompatibiltyTest extends ScriptDrivenTest {
|
||||
runTest("pcalls");
|
||||
}
|
||||
|
||||
public void testPrint() throws IOException, InterruptedException {
|
||||
runTest("print");
|
||||
}
|
||||
|
||||
public void testRequire() throws IOException, InterruptedException {
|
||||
runTest("require");
|
||||
}
|
||||
|
||||
26
src/test/res/print.lua
Normal file
26
src/test/res/print.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
-- print uses tostring under-the-hood!
|
||||
|
||||
local function f()
|
||||
print()
|
||||
print('abc')
|
||||
print(123)
|
||||
print(true)
|
||||
print('abc',123,true)
|
||||
end
|
||||
|
||||
local function g()
|
||||
local fenv = {tostring=function(x)
|
||||
return '*'..type(x)..'*'
|
||||
end}
|
||||
package.seeall(fenv)
|
||||
f()
|
||||
print('setfenv', pcall(setfenv, 0, fenv), {}, f )
|
||||
f()
|
||||
end
|
||||
|
||||
local s,c = pcall( coroutine.create, g )
|
||||
print('create', s, s and type(c) or c)
|
||||
print('resume', pcall( coroutine.resume, c ) )
|
||||
f()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user