Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin <imun@tarantool.org>
To: Olga Arkhangelskaia <arkholga@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org, alexander.turenko@tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] console: add line carrying backslash
Date: Tue, 26 May 2020 15:11:44 +0300	[thread overview]
Message-ID: <20200526121144.GM5455@tarantool.org> (raw)
In-Reply-To: <20200414123504.48100-1-arkholga@tarantool.org>

Olya,

Thanks for the patch! Please consider the comments I left below.

On 14.04.20, Olga Arkhangelskaia wrote:
> When using interactive console(stdin) instead of \set delimiter <delimiter>
> with "\", "\" in the end if line can be used.
> 

It looks like the section below doesn't relate to the commit message.

> The patch enables "\" only for REPL over stdin. I have troubles to write
> tests for stdin input, because in case we attach to the console (remote
> or to self) another read (console_read) is used. And in this case I do
> not think that we need support backslash, because we stop reading
> till "\n" or "\r".
> Another problem that I have faced is testing (I have tried remote instance,
> console over socket and i little bit of popen. However, all this test take
> advantage of console_read and do not touch local_read.
> If you have any ideas how to test interactive
> console within test-run, please share.

I tried the same hack Sasha used here[1]:
| $ echo 'int isatty(int fd) { return 1; }' > isatty.c
| $ gcc isatty.c -fPIC -shared -o libisatty.so

The build without your patch produces the following output:
| $ printf 'local a = 0 \\\nfor i = 1, 10 do\na = a + i\nend \\\nprint(a)\n' \
|   | LD_PRELOAD=./libisatty.so ./src/tarantool
| Tarantool 2.4.0-124-g1f0211b76
| type 'help' for interactive help
| tarantool> local a = 0 \
| ---
| - error: '[string "local a = 0 \"]:1: unexpected symbol near ''\'''
| ...
|
| tarantool> for i = 1, 10 do
|          > a = a + i
|          > end \
| ---
| - error: '[string "for i = 1, 10 do..."]:3: unexpected symbol near ''\'''
| ...
|
| tarantool> print(a)
| ---
| - error: '[string "return print(a)"]:1: variable ''a'' is not declared'
| ...
|
| tarantool>$

After applying your changes no error occurs:
| $ printf 'local a = 0 \\\nfor i = 1, 10 do\na = a + i\nend \\\nprint(a)\n' \
|   | LD_PRELOAD=./libisatty.so ./src/tarantool
| Tarantool 2.4.0-125-g10d7d4b49
| type 'help' for interactive help
| tarantool> local a = 0 \
|          > for i = 1, 10 do
|          > a = a + i
|          > end \
|          > print(a)
| 55
| ---
| ...
|
| tarantool>$

Thereby, you can make the test the similar way Sasha did for his patch.

> 
> Closes #4317
> ---
> Branch:
> OKriw/gh-4317-console-support-line-carrying-with-backslash
>  src/box/lua/console.lua | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
> 
> 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)
> -- 
> 2.20.1 (Apple Git-117)
> 

[1]: https://github.com/tarantool/tarantool/commit/185a7b0175ef264c14e2628ba7f545cb14d81374

-- 
Best regards,
IM

      reply	other threads:[~2020-05-26 12:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-14 12:35 Olga Arkhangelskaia
2020-05-26 12:11 ` Igor Munkin [this message]

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=20200526121144.GM5455@tarantool.org \
    --to=imun@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=arkholga@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] console: add line carrying backslash' \
    /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