* [Tarantool-patches] [PATCH] console: add line carrying backslash
@ 2020-04-14 12:35 Olga Arkhangelskaia
2020-05-26 12:11 ` Igor Munkin
0 siblings, 1 reply; 2+ messages in thread
From: Olga Arkhangelskaia @ 2020-04-14 12:35 UTC (permalink / raw)
To: tarantool-patches
When using interactive console(stdin) instead of \set delimiter <delimiter>
with "\", "\" in the end if line can be used.
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.
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)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Tarantool-patches] [PATCH] console: add line carrying backslash
2020-04-14 12:35 [Tarantool-patches] [PATCH] console: add line carrying backslash Olga Arkhangelskaia
@ 2020-05-26 12:11 ` Igor Munkin
0 siblings, 0 replies; 2+ messages in thread
From: Igor Munkin @ 2020-05-26 12:11 UTC (permalink / raw)
To: Olga Arkhangelskaia; +Cc: tarantool-patches, alexander.turenko
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-05-26 12:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14 12:35 [Tarantool-patches] [PATCH] console: add line carrying backslash Olga Arkhangelskaia
2020-05-26 12:11 ` Igor Munkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox