From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 44030469711 for ; Wed, 10 Jun 2020 12:44:10 +0300 (MSK) From: Olga Arkhangelskaia Date: Wed, 10 Jun 2020 12:43:54 +0300 Message-Id: <20200610094354.31831-3-arkholga@tarantool.org> In-Reply-To: <20200610094354.31831-1-arkholga@tarantool.org> References: <20200610094354.31831-1-arkholga@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/2] console: add line carrying backslash List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org Cc: alexander.turenko@tarantool.org When using interactive console(stdin) instead of \set delimiter with "\", "\" in the end if line can be used. Closes #4317 --- src/box/lua/console.lua | 18 ++++++++----- test/app-tap/gh-4317.test.lua | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 test/app-tap/gh-4317.test.lua diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 17e2c91b2..4c2c7a132 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -573,14 +573,20 @@ local function local_read(self) break end if delim == "" then - local lang = box.session.language - if not lang or lang == 'lua' then - -- stop once a complete Lua statement is entered - if local_check_lua(buf) then + -- if no delim is set and line ends with the backslash + -- continue reading + if buf:sub(-1, -1) == '\\' then + buf = buf:sub(0, #buf - 1) + else + local lang = box.session.language + if not lang or lang == 'lua' then + -- stop once a complete Lua statement is entered + if local_check_lua(buf) then + break + end + else break end - else - break end elseif #buf >= #delim and buf:sub(#buf - #delim + 1) == delim then buf = buf:sub(0, #buf - #delim) diff --git a/test/app-tap/gh-4317.test.lua b/test/app-tap/gh-4317.test.lua new file mode 100755 index 000000000..d7a5063e7 --- /dev/null +++ b/test/app-tap/gh-4317.test.lua @@ -0,0 +1,51 @@ +#!/usr/bin/env tarantool + +local tap = require('tap') +local console = require('console') +local fio = require('fio') + +-- The following cases use LD_PRELOAD, so will not work under +-- Mac OS X. +if jit.os == 'OSX' then + os.exit(0) +end + +test = tap.test("console") +test:plan(1) + +-- Allow to run the test from the repository root without +-- test-run: +-- +-- $ ./src/tarantool test/app-tap/gh-4317.test.lua +-- +-- It works at least for in-source build. +local is_under_test_run = pcall(require, 'test_run') +local isatty_lib_dir = is_under_test_run and '../..' or 'test' +local isatty_lib_path = fio.pathjoin(isatty_lib_dir, 'libisatty.so') +local saved_path = os.getenv('PATH') +if not is_under_test_run then + os.setenv('PATH', './src:', saved_path) +end + +local tarantool_command = "local a = 0 \\\nfor i = 1, 10 do\na = a + i\nend \\\nprint(a)" +local result_str = [[tarantool> local a = 0 \ + > for i = 1, 10 do + > a = a + i + > end \ + > print(a) +55 +--- +... + +tarantool> ]] +local cmd = ([[printf '%s\n' | LD_PRELOAD='%s' tarantool ]] .. +[[2>/dev/null]]):format(tarantool_command, isatty_lib_path) +local fh = io.popen(cmd, 'r') +-- Readline on CentOS 7 produces \e[?1034h escape +-- sequence before tarantool> prompt, remove it. +local result = fh:read('*a'):gsub('\x1b%[%?1034h', '') +fh:close() +test:is(result, result_str, "Backslash") + +test:check() +os.exit(0) -- 2.20.1 (Apple Git-117)