[Tarantool-patches] [PATCH] console: add line carrying backslash

Igor Munkin imun at tarantool.org
Tue May 26 15:11:44 MSK 2020


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


More information about the Tarantool-patches mailing list