From: Sergey Voinov <sergeiv@tarantool.org> To: tarantool-patches@dev.tarantool.org, Alexander Turenko <alexander.turenko@tarantool.org> Cc: Sergey Voinov <sergeiv@tarantool.org> Subject: [Tarantool-patches] [PATCH] Add console.print() alias for box.session.push() Date: Thu, 5 Dec 2019 18:53:06 +0300 [thread overview] Message-ID: <20191205155306.13157-1-sergeiv@tarantool.org> (raw) Currently, lack of a function like console.print() often confuses users. This change adds such alias. Closes: #4393 --- issue: https://github.com/tarantool/tarantool/issues/4393 branch: https://github.com/tarantool/tarantool/compare/servoin/gh-4393-console_print src/box/lua/console.lua | 11 +++++++++++ test/app-tap/console.test.lua | 25 ++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index d4d8ec984..05f8016c4 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -821,6 +821,16 @@ local function listen(uri) return s end +-- +-- Alias for box.session.push +-- +local function print(message, sync) + if message == nil then + error('Usage: console.print(message, sync)') + end + return box.session.push(message, sync or box.session.sync()) +end + package.loaded['console'] = { start = start; eval = eval; @@ -834,4 +844,5 @@ package.loaded['console'] = { on_start = on_start; on_client_disconnect = on_client_disconnect; completion_handler = internal.completion_handler; + print = print; } diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua index da5c1e71e..e8a4c39d0 100755 --- a/test/app-tap/console.test.lua +++ b/test/app-tap/console.test.lua @@ -21,7 +21,7 @@ local EOL = "\n...\n" test = tap.test("console") -test:plan(73) +test:plan(78) -- Start console and connect to it local server = console.listen(CONSOLE_SOCKET) @@ -306,6 +306,29 @@ local res = yaml.decode(client:read(EOL))[1] test:is_deeply(res, exp_res, 'unknown command') client:close() +-- +-- gh-4393: console.print() alias for box.session.push() +-- +client = socket.tcp_connect("unix/", CONSOLE_SOCKET) + +-- console.print, no arguments. +client:write('console.print()\n') +test:isnt(string.match(client:read(EOL), 'Usage: console%.print%(message, sync%)'), nil, + "error message") + +-- console.print, one argument. +client:write('console.print(200)\n') +test:is(client:read(EOL), '%TAG !push! tag:tarantool.io/push,2018\n--- 200\n...\n', + "pushed message") +test:is(client:read(EOL), '---\n- true\n...\n', "pushed message") + +-- console.print, two arguments. +client:write('console.print(1, 9223372036854775808ULL)\n') +test:is(client:read(EOL), '%TAG !push! tag:tarantool.io/push,2018\n--- 1\n...\n', + "pushed message") +test:is(client:read(EOL), '---\n- true\n...\n', "pushed message") +client:close() + server:close() box.schema.user.drop('test') -- 2.17.1
next reply other threads:[~2019-12-05 15:51 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-12-05 15:53 Sergey Voinov [this message] 2019-12-05 16:16 ` Cyrill Gorcunov 2019-12-16 23:54 ` Alexander Turenko 2019-12-17 14:11 ` Alexander Turenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20191205155306.13157-1-sergeiv@tarantool.org \ --to=sergeiv@tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH] Add console.print() alias for box.session.push()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox