forked from tarantool/tarantool
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
console: add line carrying backslash
When using interactive console(stdin) instead of \set delimiter <delimiter> with "\", "\" in the end if line can be used. Works on both server/client side. Local console is impossible to test with a pipe or tarantool interactive mode. The problem with interactive mode (-i) is that the flag that sets it, does not influence the isatty() check, while startup script is executed (tarantool#5064). To overload this check and test the local console isatty lib was added.
- Loading branch information
Showing
4 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
local t = require('luatest') | ||
local g = t.group() | ||
local console = require('console') | ||
local socket = require('socket') | ||
local tap = require('tap') | ||
local fio = require('fio') | ||
local log = require('log') | ||
|
||
local result_str = [[tarantool> local a = 0 \ | ||
> for i = 1, 10 do | ||
> a = a + i | ||
> end \ | ||
> print(a) | ||
55 | ||
--- | ||
... | ||
tarantool> ]] | ||
|
||
g.test_local_console = function() | ||
t.skip_if(jit.os == 'OSX', "LD_PRELOAD doesn't work on OSX") | ||
|
||
-- libisatty.so provides isatty() that always returns 1. | ||
local binary = arg[-1] | ||
local isatty_lib_path = binary:gsub('tarantool$', '../test/libisatty.so') | ||
assert(isatty_lib_path:match('libisatty.so$'), 'Failed to locate libisatty.so') | ||
local tarantool_command = "local a = 0 \\\nfor i = 1, 10 do\na = a + i\nend \\\nprint(a)" | ||
|
||
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() | ||
t.assert_equals(result, result_str) | ||
end | ||
|
||
g.test_remote_console = function() | ||
-- Suppress console log messages | ||
log.level(4) | ||
local CONSOLE_SOCKET = fio.pathjoin(fio.cwd(), 'tarantool-test-console.sock') | ||
local IPROTO_SOCKET = fio.pathjoin(fio.cwd(), 'tarantool-test-iproto.sock') | ||
local EOL = "\n...\n" | ||
local server = console.listen(CONSOLE_SOCKET) | ||
local client = socket.tcp_connect("unix/", CONSOLE_SOCKET) | ||
local cmd = 'local a = 0 \\\nfor i = 1, 10 do\\\n a = a + i \\\n end \\\n print(a)' | ||
|
||
client = socket.tcp_connect("unix/", CONSOLE_SOCKET) | ||
client:read(128) | ||
client:write(('%s\n'):format(cmd)) | ||
local result = client:read(EOL) | ||
t.assert_not_str_contains(result, 'error') | ||
client:close() | ||
os.remove(CONSOLE_SOCKET) | ||
os.remove(IPROTO_SOCKET) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int | ||
isatty(int fd) | ||
{ | ||
return 1; | ||
} |