Skip to content

Commit da9f089

Browse files
committed
fixup! Add stricter check for print() vs. tostring() shortcut.
1 parent 4375c46 commit da9f089

File tree

2 files changed

+41
-45
lines changed

2 files changed

+41
-45
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
local utils = require('utils')
2+
3+
local cases = {
4+
{typename = 'nil', value = 'nil'},
5+
{typename = 'boolean', value = 'true'},
6+
{typename = 'number', value = '42'},
7+
-- FIXME: This test case is disabled, because __tostring
8+
-- metamethod isn't checked for string base metatable.
9+
-- See also https://github.com/tarantool/tarantool/issues/6746.
10+
-- {'string', '"teststr"'},
11+
{typename = 'table', value = '{}'},
12+
{typename = 'function', value = 'function() end'},
13+
{typename = 'userdata', value = 'newproxy()'},
14+
{typename = 'thread', value = 'coroutine.create(function() end)'},
15+
{typename = 'cdata', value = '1ULL'}
16+
}
17+
18+
local checks = {}
19+
20+
for i, case in pairs(cases) do
21+
checks[i] = {
22+
arg = {('"%s"'):format(case.value), case.typename},
23+
msg = ('%s'):format(case.typename),
24+
res = ('__tostring is reloaded for %s'):format(case.typename),
25+
test = 'is',
26+
}
27+
end
28+
29+
utils.selfrun(arg, checks)
30+
31+
----- Test payload. ----------------------------------------------
32+
33+
local test = [[
34+
local testvar = %s
35+
debug.setmetatable(testvar, {__tostring = function(o)
36+
return ('__tostring is reloaded for %s'):format(type(o))
37+
end})
38+
print(testvar)
39+
]]
40+
41+
pcall(load(test:format(unpack(arg))))

test/tarantool-tests/print-tostring-number.test.lua

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)