diff --git a/src/lua/net_box.lua b/src/lua/net_box.lua index 5ccd8bc22f222318c7e2428e011debb6eb45ce45..cc7834a04d82710a21051aa59c090f34759ab317 100644 --- a/src/lua/net_box.lua +++ b/src/lua/net_box.lua @@ -1091,6 +1091,9 @@ remote.self = { return result end, eval = function(_box, expr, ...) + if type(_box) ~= 'table' then + box.error(box.error.PROC_LUA, "usage: remote:eval(expr, ...)") + end local proc, errmsg = loadstring(expr) if not proc then proc, errmsg = loadstring("return "..expr) diff --git a/test/box/net.box.result b/test/box/net.box.result index 7c66df2f3502f4aea92082c00d474b99f06858a6..dca0af05100f901a4900735d4c7f6133db0cc1ae 100644 --- a/test/box/net.box.result +++ b/test/box/net.box.result @@ -232,7 +232,7 @@ cn.space.net_box_test_space:insert{234, 1,2,3} ... cn.space.net_box_test_space.insert{234, 1,2,3} --- -- error: 'builtin/net.box.lua:242: Use space:method(...) instead space.method(...)' +- error: 'builtin/net.box.lua:243: Use space:method(...) instead space.method(...)' ... cn.space.net_box_test_space:replace{354, 1,2,3} --- @@ -617,79 +617,50 @@ space:drop() --- ... -- admin console tests -function console_test(...) return { ... } end +cnc = remote:new(os.getenv('ADMIN')) --- ... -function console_test_error(...) error(string.format(...)) end ---- -... -function console_unpack_test(...) return ... end ---- -... -ADMIN = require('uri').parse(os.getenv('ADMIN')) ---- -... -cn = remote:new(LISTEN.host, LISTEN.service) ---- -... -cnc = remote:new(ADMIN.host, ADMIN.service) ---- -... -cnc.console +cnc.console ~= nil --- - true ... -cn:call('console_test', 1, 2, 3, 'string', nil) ---- -- - [1, 2, 3, 'string'] -... -cnc:call('console_test', 1, 2, 3, 'string', nil) ---- -- - [1, 2, 3, 'string'] -... -cn:call('console_test_error', 'error %d', 123) ---- -- error: '[string "function console_test_error(...) error(string..."]:1: error 123' -... -cnc:call('console_test_error', 'error %d', 123) ---- -- error: '[string "function console_test_error(...) error(string..."]:1: error 123' -... -cn:call('console_unpack_test', 1) ---- -- - [1] -... -cnc:call('console_unpack_test', 1) ---- -- - [1] -... -cn:call('123') ---- -- error: Procedure '123' is not defined -... -cnc:call('123') ---- -- error: '[string "123()"]:1: unexpected symbol near ''123''' -... --- gh-649: String escaping doesn't work in remote console -function echo(...) return ... end ---- -... -#cn:call('echo', [[a \[\[ \091\091 b \093\093 c \n d \t e \]\] f ]])[1][1] ---- -- 46 -... -#cnc:call('echo', [[a \[\[ \091\091 b \093\093 c \n d \t e \]\] f ]])[1][1] ---- -- 46 -... -#cn:call('echo', "a [[ \091\091 b \093\093 c \n d \t e ]] f ")[1][1] ---- -- 28 -... -#cnc:call('echo', "a [[ \091\091 b \093\093 c \n d \t e ]] f ")[1][1] ---- -- 28 +cnc:console('return 1, 2, 3, "string", nil') +--- +- '--- + + - 1 + + - 2 + + - 3 + + - string + + - null + + ... + +' +... +cnc:console('error("test")') +--- +- '--- + + - error: test + + ... + +' +... +cnc:console('a = {1, 2, 3, 4}; return a[3]') +--- +- '--- + + - 3 + + ... + +' ... -- #545 user or password is not defined remote:new(LISTEN.host, LISTEN.service, { user = 'test' }) @@ -701,25 +672,31 @@ remote:new(LISTEN.host, LISTEN.service, { password = 'test' }) - error: 'net.box: user is not defined' ... -- #544 usage for remote[point]method -cn:call('console_test') +cn = remote:new(LISTEN.host, LISTEN.service) --- -- - [] ... -cn.call('console_test') +cn:eval('return true') +--- +- true +... +cn.eval('return true') --- -- error: 'usage: remote:call(proc_name, ...)' +- error: 'usage: remote:eval(expr, ...)' ... cn.ping() --- - error: 'usage: remote:ping()' ... -remote.self:call('console_test') +cn:close() --- -- [] ... -remote.self.call('console_test') +remote.self:eval('return true') +--- +- true +... +remote.self.eval('return true') --- -- error: 'usage: remote:call(proc_name, ...)' +- error: 'usage: remote:eval(expr, ...)' ... -- uri as the first argument uri = string.format('%s:%s@%s:%s', 'netbox', 'test', LISTEN.host, LISTEN.service) diff --git a/test/box/net.box.test.lua b/test/box/net.box.test.lua index 7c2d0d5a005b26feabc6a86e754fd74bf0a0f185..47cbda5ba932499de1c3f0f5813424c3d9ec1ef5 100644 --- a/test/box/net.box.test.lua +++ b/test/box/net.box.test.lua @@ -225,52 +225,28 @@ space:drop() -- admin console tests -function console_test(...) return { ... } end -function console_test_error(...) error(string.format(...)) end -function console_unpack_test(...) return ... end - - -ADMIN = require('uri').parse(os.getenv('ADMIN')) - -cn = remote:new(LISTEN.host, LISTEN.service) -cnc = remote:new(ADMIN.host, ADMIN.service) -cnc.console - -cn:call('console_test', 1, 2, 3, 'string', nil) -cnc:call('console_test', 1, 2, 3, 'string', nil) - -cn:call('console_test_error', 'error %d', 123) -cnc:call('console_test_error', 'error %d', 123) - - -cn:call('console_unpack_test', 1) -cnc:call('console_unpack_test', 1) - - - - -cn:call('123') -cnc:call('123') - --- gh-649: String escaping doesn't work in remote console -function echo(...) return ... end -#cn:call('echo', [[a \[\[ \091\091 b \093\093 c \n d \t e \]\] f ]])[1][1] -#cnc:call('echo', [[a \[\[ \091\091 b \093\093 c \n d \t e \]\] f ]])[1][1] -#cn:call('echo', "a [[ \091\091 b \093\093 c \n d \t e ]] f ")[1][1] -#cnc:call('echo', "a [[ \091\091 b \093\093 c \n d \t e ]] f ")[1][1] +cnc = remote:new(os.getenv('ADMIN')) +cnc.console ~= nil +cnc:console('return 1, 2, 3, "string", nil') +cnc:console('error("test")') +cnc:console('a = {1, 2, 3, 4}; return a[3]') -- #545 user or password is not defined remote:new(LISTEN.host, LISTEN.service, { user = 'test' }) remote:new(LISTEN.host, LISTEN.service, { password = 'test' }) -- #544 usage for remote[point]method -cn:call('console_test') -cn.call('console_test') +cn = remote:new(LISTEN.host, LISTEN.service) + +cn:eval('return true') +cn.eval('return true') cn.ping() -remote.self:call('console_test') -remote.self.call('console_test') +cn:close() + +remote.self:eval('return true') +remote.self.eval('return true') -- uri as the first argument