aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/nvim.17
-rw-r--r--src/nvim/buffer.c38
-rw-r--r--src/nvim/buffer_defs.h5
-rw-r--r--src/nvim/ex_cmds.lua12
-rw-r--r--src/nvim/fileio.c1
-rw-r--r--src/nvim/indent_c.c5
-rw-r--r--src/nvim/mbyte.c6
-rw-r--r--src/nvim/message.c21
-rw-r--r--src/nvim/ops.c18
-rw-r--r--src/nvim/os/env.c25
-rw-r--r--src/nvim/os/fs.c1
-rw-r--r--src/nvim/os/input.c10
-rw-r--r--src/nvim/quickfix.c78
-rw-r--r--src/nvim/testdir/test_quickfix.vim56
-rw-r--r--src/nvim/tui/tui.c18
-rw-r--r--src/nvim/version.c12
-rw-r--r--test/functional/api/server_requests_spec.lua8
-rw-r--r--test/functional/core/job_partial_spec.lua30
-rw-r--r--test/functional/core/job_spec.lua162
-rw-r--r--test/functional/eval/timer_spec.lua2
-rw-r--r--test/functional/ex_cmds/ctrl_c_spec.lua6
-rw-r--r--test/functional/helpers.lua6
-rw-r--r--test/functional/ui/output_spec.lua2
-rw-r--r--test/functional/ui/screen.lua110
-rw-r--r--test/functional/ui/screen_basic_spec.lua16
-rw-r--r--test/helpers.lua1
-rw-r--r--test/unit/os/env_spec.lua67
27 files changed, 459 insertions, 264 deletions
diff --git a/man/nvim.1 b/man/nvim.1
index 70bf480f2b..98d97c2d5a 100644
--- a/man/nvim.1
+++ b/man/nvim.1
@@ -372,9 +372,10 @@ Used to set the 'shell' option, which determines the shell used by the
.Ic :terminal
command.
.It Ev NVIM_TUI_ENABLE_CURSOR_SHAPE
-If defined, change the cursor shape to a vertical bar while in insert mode.
-Requires that the host terminal supports the DECSCUSR CSI escape sequence.
-Has no effect in GUIs.
+Set to 0 to prevent Nvim from changing the cursor shape.
+Set to 1 to enable non-blinking mode-sensitive cursor (this is the default).
+Set to 2 to enable blinking mode-sensitive cursor.
+Host terminal must support the DECSCUSR CSI escape sequence.
.Pp
Depending on the terminal emulator, using this option with
.Nm
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 600cf575fc..26dbbe8bb5 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -282,6 +282,27 @@ bool buf_valid(buf_T *buf)
return false;
}
+// Map used to quickly lookup a buffer by its number.
+static PMap(handle_T) *buf_map = NULL;
+
+static void buf_hashtab_add(buf_T *buf)
+ FUNC_ATTR_NONNULL_ALL
+{
+ if (pmap_has(handle_T)(buf_map, buf->handle)) {
+ EMSG(_("E931: Buffer cannot be registered"));
+ } else {
+ pmap_put(handle_T)(buf_map, buf->handle, buf);
+ }
+}
+
+static void buf_hashtab_remove(buf_T *buf)
+ FUNC_ATTR_NONNULL_ALL
+{
+ if (pmap_has(handle_T)(buf_map, buf->handle)) {
+ pmap_del(handle_T)(buf_map, buf->handle);
+ }
+}
+
/// Close the link to a buffer.
///
/// @param win If not NULL, set b_last_cursor.
@@ -585,6 +606,7 @@ static void free_buffer(buf_T *buf)
free_buffer_stuff(buf, TRUE);
unref_var_dict(buf->b_vars);
aubuflocal_remove(buf);
+ buf_hashtab_remove(buf);
dict_unref(buf->additional_data);
clear_fmark(&buf->b_last_cursor);
clear_fmark(&buf->b_last_insert);
@@ -1369,7 +1391,10 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
{
buf_T *buf;
- fname_expand(curbuf, &ffname, &sfname); /* will allocate ffname */
+ if (top_file_num == 1) {
+ buf_map = pmap_new(handle_T)();
+ }
+ fname_expand(curbuf, &ffname, &sfname); // will allocate ffname
/*
* If file name already exists in the list, update the entry.
@@ -1493,6 +1518,7 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
}
top_file_num = 1;
}
+ buf_hashtab_add(buf);
/*
* Always copy the options from the current buffer.
@@ -2002,19 +2028,15 @@ static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case)
return match;
}
-/*
- * find file in buffer list by number
- */
+/// Find a file in the buffer list by buffer number.
buf_T *buflist_findnr(int nr)
{
if (nr == 0) {
nr = curwin->w_alt_fnum;
}
- FOR_ALL_BUFFERS(buf) {
- if (buf->b_fnum == nr) {
- return buf;
- }
+ if (pmap_has(handle_T)(buf_map, (handle_T)nr)) {
+ return pmap_get(handle_T)(buf_map, (handle_T)nr);
}
return NULL;
}
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 2b66a07f48..29f4dfe4fb 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -454,6 +454,9 @@ typedef struct {
} synblock_T;
+#define BUF_HAS_QF_ENTRY 1
+#define BUF_HAS_LL_ENTRY 2
+
/*
* buffer: structure that holds information about one file
*
@@ -611,7 +614,7 @@ struct file_buffer {
int b_p_bomb; ///< 'bomb'
char_u *b_p_bh; ///< 'bufhidden'
char_u *b_p_bt; ///< 'buftype'
- bool b_has_qf_entry; ///< quickfix exists for buffer
+ int b_has_qf_entry; ///< quickfix exists for buffer
int b_p_bl; ///< 'buflisted'
int b_p_cin; ///< 'cindent'
char_u *b_p_cino; ///< 'cinoptions'
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 88095602ba..5f81306fc1 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -462,6 +462,12 @@ return {
func='ex_checktime',
},
{
+ command='chistory',
+ flags=bit.bor(TRLBAR),
+ addr_type=ADDR_LINES,
+ func='qf_history',
+ },
+ {
command='clist',
flags=bit.bor(BANG, EXTRA, TRLBAR, CMDWIN),
addr_type=ADDR_LINES,
@@ -1400,6 +1406,12 @@ return {
func='ex_helpgrep',
},
{
+ command='lhistory',
+ flags=bit.bor(TRLBAR),
+ addr_type=ADDR_LINES,
+ func='qf_history',
+ },
+ {
command='ll',
flags=bit.bor(RANGE, NOTADR, COUNT, TRLBAR, BANG),
addr_type=ADDR_LINES,
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 13329d771b..12206c1680 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -1882,6 +1882,7 @@ failed:
xfree(keep_msg);
keep_msg = NULL;
+ p = NULL;
msg_scrolled_ign = TRUE;
if (!read_stdin && !read_buffer) {
diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c
index 6f03cf6037..7b758b4dac 100644
--- a/src/nvim/indent_c.c
+++ b/src/nvim/indent_c.c
@@ -173,9 +173,8 @@ static char_u *skip_string(char_u *p)
char_u *delim = p + 2;
char_u *paren = vim_strchr(delim, '(');
- if (paren != NULL)
- {
- long delim_len = paren - delim;
+ if (paren != NULL) {
+ ptrdiff_t delim_len = paren - delim;
for (p += 3; *p; ++p)
if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index ec4969d4f6..c855d68605 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1484,6 +1484,9 @@ int utf8_to_utf16(const char *str, WCHAR **strw)
(WCHAR *)pos,
wchar_len);
assert(r == wchar_len);
+ if (r != wchar_len) {
+ EMSG2("MultiByteToWideChar failed: %d", r);
+ }
*strw = (WCHAR *)pos;
return 0;
@@ -1519,6 +1522,9 @@ int utf16_to_utf8(const WCHAR *strw, char **str)
NULL,
NULL);
assert(r == utf8_len);
+ if (r != utf8_len) {
+ EMSG2("WideCharToMultiByte failed: %d", r);
+ }
*str = pos;
return 0;
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 2f8feda6ec..749fa8a706 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -297,8 +297,22 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen)
len += n;
}
- /* Set the middle and copy the last part. */
- if (e + 3 < buflen) {
+ if (i <= e + 3) {
+ // text fits without truncating
+ if (s != buf) {
+ len = STRLEN(s);
+ if (len >= buflen) {
+ len = buflen - 1;
+ }
+ len = len - e + 1;
+ if (len < 1) {
+ buf[e - 1] = NUL;
+ } else {
+ memmove(buf + e, s + e, len);
+ }
+ }
+ } else if (e + 3 < buflen) {
+ // set the middle and copy the last part
memmove(buf + e, "...", (size_t)3);
len = (int)STRLEN(s + i) + 1;
if (len >= buflen - e - 3)
@@ -306,7 +320,8 @@ void trunc_string(char_u *s, char_u *buf, int room, int buflen)
memmove(buf + e + 3, s + i, len);
buf[e + 3 + len - 1] = NUL;
} else {
- buf[e - 1] = NUL; /* make sure it is truncated */
+ // can't fit in the "...", just truncate it
+ buf[e - 1] = NUL;
}
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 645dcc0865..9a01891483 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -2643,8 +2643,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
char command_start_char = non_linewise_vis ? 'c' :
(flags & PUT_LINE ? 'i' : (dir == FORWARD ? 'a' : 'i'));
- // To avoid being the affect of 'autoindent' on linewise puts, we create a
- // new line with `:put _`.
+ // To avoid 'autoindent' on linewise puts, create a new line with `:put _`.
if (flags & PUT_LINE) {
do_put('_', NULL, dir, 1, PUT_LINE);
}
@@ -2668,6 +2667,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
} else {
(void)stuff_inserted(command_start_char, count, false);
}
+
// Putting the text is done later, so can't move the cursor to the next
// character. Simulate it with motion commands after the insert.
if (flags & PUT_CURSEND) {
@@ -2689,17 +2689,15 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
// incremented instead of curwin->w_cursor.col.
char_u *cursor_pos = get_cursor_pos_ptr();
bool one_past_line = (*cursor_pos == NUL);
- bool end_of_line = false;
+ bool eol = false;
if (!one_past_line) {
- end_of_line = (*(cursor_pos + mb_ptr2len(cursor_pos)) == NUL);
+ eol = (*(cursor_pos + mb_ptr2len(cursor_pos)) == NUL);
}
- bool virtualedit_allows = (ve_flags == VE_ALL
- || ve_flags == VE_ONEMORE);
- bool end_of_file = (
- (curbuf->b_ml.ml_line_count == curwin->w_cursor.lnum)
- && one_past_line);
- if (virtualedit_allows || !(end_of_line || end_of_file)) {
+ bool ve_allows = (ve_flags == VE_ALL || ve_flags == VE_ONEMORE);
+ bool eof = curbuf->b_ml.ml_line_count == curwin->w_cursor.lnum
+ && one_past_line;
+ if (ve_allows || !(eol || eof)) {
stuffcharReadbuff('l');
}
}
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 47d541c6a7..109b5c7175 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -226,25 +226,24 @@ char_u *expand_env_save_opt(char_u *src, bool one)
/// "~/" is also expanded, using $HOME. For Unix "~user/" is expanded.
/// Skips over "\ ", "\~" and "\$" (not for Win32 though).
/// If anything fails no expansion is done and dst equals src.
-/// @param src Input string e.g. "$HOME/vim.hlp"
-/// @param dst Where to put the result
-/// @param dstlen Maximum length of the result
+///
+/// @param src Input string e.g. "$HOME/vim.hlp"
+/// @param dst[out] Where to put the result
+/// @param dstlen Maximum length of the result
void expand_env(char_u *src, char_u *dst, int dstlen)
{
expand_env_esc(src, dst, dstlen, false, false, NULL);
}
/// Expand environment variable with path name and escaping.
-/// "~/" is also expanded, using $HOME. For Unix "~user/" is expanded.
-/// Skips over "\ ", "\~" and "\$" (not for Win32 though).
-/// If anything fails no expansion is done and dst equals src.
-/// prefix recognize the start of a new name, for '~' expansion.
-/// @param srcp Input string e.g. "$HOME/vim.hlp"
-/// @param dst Where to put the result
-/// @param dstlen Maximum length of the result
-/// @param esc Should we escape spaces in expanded variables?
-/// @param one Should we expand more than one '~'?
-/// @param prefix Common prefix for paths, can be NULL
+/// @see expand_env
+///
+/// @param srcp Input string e.g. "$HOME/vim.hlp"
+/// @param dst[out] Where to put the result
+/// @param dstlen Maximum length of the result
+/// @param esc Escape spaces in expanded variables
+/// @param one `srcp` is a single filename
+/// @param prefix Start again after this (can be NULL)
void expand_env_esc(char_u *restrict srcp,
char_u *restrict dst,
int dstlen,
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 4aa727733e..30e08ac129 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -939,7 +939,6 @@ char_u * os_resolve_shortcut(char_u *fname)
OLECHAR wsz[MAX_PATH];
char_u *rfname = NULL;
int len;
- int conversion_result;
IShellLinkW *pslw = NULL;
WIN32_FIND_DATAW ffdw;
diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c
index b60a7eed36..f264a26939 100644
--- a/src/nvim/os/input.c
+++ b/src/nvim/os/input.c
@@ -170,12 +170,13 @@ bool os_isatty(int fd)
size_t input_enqueue(String keys)
{
- char *ptr = keys.data, *end = ptr + keys.size;
+ char *ptr = keys.data;
+ char *end = ptr + keys.size;
while (rbuffer_space(input_buffer) >= 6 && ptr < end) {
uint8_t buf[6] = { 0 };
- unsigned int new_size = trans_special((const uint8_t **)&ptr, keys.size,
- buf, true);
+ unsigned int new_size
+ = trans_special((const uint8_t **)&ptr, (size_t)(end - ptr), buf, true);
if (new_size) {
new_size = handle_mouse_event(&ptr, buf, new_size);
@@ -185,8 +186,7 @@ size_t input_enqueue(String keys)
if (*ptr == '<') {
char *old_ptr = ptr;
- // Invalid or incomplete key sequence, skip until the next '>' or until
- // *end
+ // Invalid or incomplete key sequence, skip until the next '>' or *end.
do {
ptr++;
} while (ptr < end && *ptr != '>');
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 33a84660c1..19287ecffb 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -1105,7 +1105,8 @@ static int qf_add_entry(qf_info_T *qi, char_u *dir, char_u *fname, int bufnum,
qfp->qf_fnum = bufnum;
if (buf != NULL) {
- buf->b_has_qf_entry = true;
+ buf->b_has_qf_entry |=
+ (qi == &ql_info) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
}
} else {
qfp->qf_fnum = qf_get_fnum(qi, dir, fname);
@@ -1282,7 +1283,7 @@ void copy_loclist(win_T *from, win_T *to)
to->w_llist->qf_curlist = qi->qf_curlist; /* current list */
}
-// Get buffer number for file "dir.name".
+// Get buffer number for file "directory.fname".
// Also sets the b_has_qf_entry flag.
static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname)
{
@@ -1322,7 +1323,8 @@ static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname)
if (buf == NULL) {
return 0;
}
- buf->b_has_qf_entry = true;
+ buf->b_has_qf_entry =
+ (qi == &ql_info) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
return buf->b_fnum;
}
@@ -2105,6 +2107,31 @@ static void qf_fmt_text(char_u *text, char_u *buf, int bufsize)
buf[i] = NUL;
}
+static void qf_msg(qf_info_T *qi, int which, char *lead)
+{
+ char *title = (char *)qi->qf_lists[which].qf_title;
+ int count = qi->qf_lists[which].qf_count;
+ char_u buf[IOSIZE];
+
+ vim_snprintf((char *)buf, IOSIZE, _("%serror list %d of %d; %d errors "),
+ lead,
+ which + 1,
+ qi->qf_listcount,
+ count);
+
+ if (title != NULL) {
+ size_t len = STRLEN(buf);
+
+ if (len < 34) {
+ memset(buf + len, ' ', 34 - len);
+ buf[34] = NUL;
+ }
+ vim_strcat(buf, (char_u *)title, IOSIZE);
+ }
+ trunc_string(buf, buf, (int)Columns - 1, IOSIZE);
+ msg(buf);
+}
+
/*
* ":colder [count]": Up in the quickfix stack.
* ":cnewer [count]": Down in the quickfix stack.
@@ -2145,15 +2172,26 @@ void qf_age(exarg_T *eap)
++qi->qf_curlist;
}
}
- qf_msg(qi);
+ qf_msg(qi, qi->qf_curlist, "");
+ qf_update_buffer(qi, NULL);
}
-static void qf_msg(qf_info_T *qi)
+void qf_history(exarg_T *eap)
{
- smsg(_("error list %d of %d; %d errors"),
- qi->qf_curlist + 1, qi->qf_listcount,
- qi->qf_lists[qi->qf_curlist].qf_count);
- qf_update_buffer(qi, NULL);
+ qf_info_T *qi = &ql_info;
+ int i;
+
+ if (eap->cmdidx == CMD_lhistory) {
+ qi = GET_LOC_LIST(curwin);
+ }
+ if (qi == NULL || (qi->qf_listcount == 0
+ && qi->qf_lists[qi->qf_curlist].qf_count == 0)) {
+ MSG(_("No entries"));
+ } else {
+ for (i = 0; i < qi->qf_listcount; i++) {
+ qf_msg(qi, i, i == qi->qf_curlist ? "> " : " ");
+ }
+ }
}
/*
@@ -2203,8 +2241,9 @@ void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long
int idx;
qf_info_T *qi = &ql_info;
bool found_one = false;
+ int buf_has_flag = wp == NULL ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
- if (!curbuf->b_has_qf_entry) {
+ if (!(curbuf->b_has_qf_entry & buf_has_flag)) {
return;
}
if (wp != NULL) {
@@ -2231,7 +2270,7 @@ void qf_mark_adjust(win_T *wp, linenr_T line1, linenr_T line2, long amount, long
}
if (!found_one) {
- curbuf->b_has_qf_entry = false;
+ curbuf->b_has_qf_entry &= ~buf_has_flag;
}
}
@@ -3451,10 +3490,13 @@ void ex_vimgrep(exarg_T *eap)
col = 0;
while (vim_regexec_multi(&regmatch, curwin, buf, lnum,
col, NULL) > 0) {
+ // Pass the buffer number so that it gets used even for a
+ // dummy buffer, unless duplicate_name is set, then the
+ // buffer will be wiped out below.
if (qf_add_entry(qi,
NULL, // dir
fname,
- 0,
+ duplicate_name ? 0 : buf->b_fnum,
ml_get_buf(buf,
regmatch.startpos[0].lnum + lnum, false),
regmatch.startpos[0].lnum + lnum,
@@ -3508,17 +3550,23 @@ void ex_vimgrep(exarg_T *eap)
buf = NULL;
} else if (buf != first_match_buf || (flags & VGR_NOJUMP)) {
unload_dummy_buffer(buf, dirname_start);
+ // Keeping the buffer, remove the dummy flag.
+ buf->b_flags &= ~BF_DUMMY;
buf = NULL;
}
}
if (buf != NULL) {
- /* If the buffer is still loaded we need to use the
- * directory we jumped to below. */
+ // Keeping the buffer, remove the dummy flag.
+ buf->b_flags &= ~BF_DUMMY;
+
+ // If the buffer is still loaded we need to use the
+ // directory we jumped to below.
if (buf == first_match_buf
&& target_dir == NULL
- && STRCMP(dirname_start, dirname_now) != 0)
+ && STRCMP(dirname_start, dirname_now) != 0) {
target_dir = vim_strsave(dirname_now);
+ }
/* The buffer is still loaded, the Filetype autocommands
* need to be done now, in that buffer. And the modelines
diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim
index f30902b915..7464a11abd 100644
--- a/src/nvim/testdir/test_quickfix.vim
+++ b/src/nvim/testdir/test_quickfix.vim
@@ -1299,13 +1299,14 @@ function! Xadjust_qflnum(cchar)
enew | only
- call s:create_test_file('Xqftestfile')
- edit Xqftestfile
+ let fname = 'Xqftestfile' . a:cchar
+ call s:create_test_file(fname)
+ exe 'edit ' . fname
- Xgetexpr ['Xqftestfile:5:Line5',
- \ 'Xqftestfile:10:Line10',
- \ 'Xqftestfile:15:Line15',
- \ 'Xqftestfile:20:Line20']
+ Xgetexpr [fname . ':5:Line5',
+ \ fname . ':10:Line10',
+ \ fname . ':15:Line15',
+ \ fname . ':20:Line20']
6,14delete
call append(6, ['Buffer', 'Window'])
@@ -1317,11 +1318,13 @@ function! Xadjust_qflnum(cchar)
call assert_equal(13, l[3].lnum)
enew!
- call delete('Xqftestfile')
+ call delete(fname)
endfunction
function! Test_adjust_lnum()
+ call setloclist(0, [])
call Xadjust_qflnum('c')
+ call setqflist([])
call Xadjust_qflnum('l')
endfunction
@@ -1420,3 +1423,42 @@ function Test_cbottom()
call XbottomTests('c')
call XbottomTests('l')
endfunction
+
+function HistoryTest(cchar)
+ call s:setup_commands(a:cchar)
+
+ call assert_fails(a:cchar . 'older 99', 'E380:')
+ " clear all lists after the first one, then replace the first one.
+ call g:Xsetlist([])
+ Xolder
+ let entry = {'filename': 'foo', 'lnum': 42}
+ call g:Xsetlist([entry], 'r')
+ call g:Xsetlist([entry, entry])
+ call g:Xsetlist([entry, entry, entry])
+ let res = split(execute(a:cchar . 'hist'), "\n")
+ call assert_equal(3, len(res))
+ let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
+ call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
+ call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
+ call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
+endfunc
+
+func Test_history()
+ call HistoryTest('c')
+ call HistoryTest('l')
+endfunc
+
+func Test_duplicate_buf()
+ " make sure we can get the highest buffer number
+ edit DoesNotExist
+ edit DoesNotExist2
+ let last_buffer = bufnr("$")
+
+ " make sure only one buffer is created
+ call writefile(['this one', 'that one'], 'Xgrepthis')
+ vimgrep one Xgrepthis
+ vimgrep one Xgrepthis
+ call assert_equal(last_buffer + 1, bufnr("$"))
+
+ call delete('Xgrepthis')
+endfunc
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index 74187e07c0..342c68818d 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -844,7 +844,7 @@ static void fix_terminfo(TUIData *data)
}
if (STARTS_WITH(term, "xterm") || STARTS_WITH(term, "rxvt")) {
- unibi_set_if_empty(ut, unibi_cursor_normal, "\x1b[?12l\x1b[?25h");
+ unibi_set_if_empty(ut, unibi_cursor_normal, "\x1b[?25h");
unibi_set_if_empty(ut, unibi_cursor_invisible, "\x1b[?25l");
unibi_set_if_empty(ut, unibi_flash_screen, "\x1b[?5h$<100/>\x1b[?5l");
unibi_set_if_empty(ut, unibi_exit_attribute_mode, "\x1b(B\x1b[m");
@@ -877,9 +877,11 @@ static void fix_terminfo(TUIData *data)
unibi_set_str(ut, unibi_set_a_background, XTERM_SETAB);
}
- if (os_getenv("NVIM_TUI_ENABLE_CURSOR_SHAPE") == NULL) {
+ const char * env_cusr_shape = os_getenv("NVIM_TUI_ENABLE_CURSOR_SHAPE");
+ if (env_cusr_shape && strncmp(env_cusr_shape, "0", 1) == 0) {
goto end;
}
+ bool cusr_blink = env_cusr_shape && strncmp(env_cusr_shape, "2", 1) == 0;
#define TMUX_WRAP(seq) (inside_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
// Support changing cursor shape on some popular terminals.
@@ -891,22 +893,22 @@ static void fix_terminfo(TUIData *data)
// Konsole uses a proprietary escape code to set the cursor shape
// and does not support DECSCUSR.
data->unibi_ext.set_cursor_shape_bar = (int)unibi_add_ext_str(ut, NULL,
- TMUX_WRAP("\x1b]50;CursorShape=1;BlinkingCursorEnabled=1\x07"));
+ TMUX_WRAP("\x1b]50;CursorShape=1\x07"));
data->unibi_ext.set_cursor_shape_ul = (int)unibi_add_ext_str(ut, NULL,
- TMUX_WRAP("\x1b]50;CursorShape=2;BlinkingCursorEnabled=1\x07"));
+ TMUX_WRAP("\x1b]50;CursorShape=2\x07"));
data->unibi_ext.set_cursor_shape_block = (int)unibi_add_ext_str(ut, NULL,
- TMUX_WRAP("\x1b]50;CursorShape=0;BlinkingCursorEnabled=0\x07"));
+ TMUX_WRAP("\x1b]50;CursorShape=0\x07"));
} else if (!vte_version || atoi(vte_version) >= 3900) {
// Assume that the terminal supports DECSCUSR unless it is an
// old VTE based terminal. This should not get wrapped for tmux,
// which will handle it via its Ss/Se terminfo extension - usually
// according to its terminal-overrides.
data->unibi_ext.set_cursor_shape_bar =
- (int)unibi_add_ext_str(ut, NULL, "\x1b[5 q");
+ (int)unibi_add_ext_str(ut, NULL, cusr_blink ? "\x1b[5 q" : "\x1b[6 q");
data->unibi_ext.set_cursor_shape_ul =
- (int)unibi_add_ext_str(ut, NULL, "\x1b[3 q");
+ (int)unibi_add_ext_str(ut, NULL, cusr_blink ? "\x1b[3 q" : "\x1b[4 q");
data->unibi_ext.set_cursor_shape_block =
- (int)unibi_add_ext_str(ut, NULL, "\x1b[2 q");
+ (int)unibi_add_ext_str(ut, NULL, cusr_blink ? "\x1b[1 q" : "\x1b[2 q");
}
end:
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 3dfc32fc6d..3d81788a7e 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -359,7 +359,7 @@ static int included_patches[] = {
// 2084,
// 2083,
// 2082,
- // 2081,
+ 2081,
// 2080,
// 2079 NA
// 2078 NA
@@ -373,10 +373,10 @@ static int included_patches[] = {
// 2070 NA
// 2069,
// 2068,
- // 2067,
+ 2067,
2066,
2065,
- // 2064,
+ 2064,
// 2063 NA
2062,
// 2061,
@@ -390,8 +390,8 @@ static int included_patches[] = {
// 2053 NA
// 2052 NA
// 2051,
- // 2050,
- // 2049,
+ 2050,
+ 2049,
// 2048 NA
// 2047,
// 2046,
@@ -404,7 +404,7 @@ static int included_patches[] = {
// 2039 NA
// 2038 NA
// 2037 NA
- // 2036,
+ 2036,
// 2035 NA
// 2034 NA
2033,
diff --git a/test/functional/api/server_requests_spec.lua b/test/functional/api/server_requests_spec.lua
index aa91cd1396..76a335a8f4 100644
--- a/test/functional/api/server_requests_spec.lua
+++ b/test/functional/api/server_requests_spec.lua
@@ -1,11 +1,11 @@
--- Tests for some server->client RPC scenarios. Note that unlike with
--- `rpcnotify`, to evaluate `rpcrequest` calls we need the client event loop to
--- be running.
+-- Test server -> client RPC scenarios. Note: unlike `rpcnotify`, to evaluate
+-- `rpcrequest` calls we need the client event loop to be running.
local helpers = require('test.functional.helpers')(after_each)
local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
local nvim_prog, command, funcs = helpers.nvim_prog, helpers.command, helpers.funcs
local source, next_message = helpers.source, helpers.next_message
+local ok = helpers.ok
local meths = helpers.meths
describe('server -> client', function()
@@ -180,7 +180,7 @@ describe('server -> client', function()
it('returns an error if the request failed', function()
local status, err = pcall(eval, "rpcrequest(vim, 'does-not-exist')")
eq(false, status)
- eq(true, string.match(err, ': (.*)') == 'Failed to evaluate expression')
+ ok(nil ~= string.match(err, 'Failed to evaluate expression'))
end)
end)
diff --git a/test/functional/core/job_partial_spec.lua b/test/functional/core/job_partial_spec.lua
deleted file mode 100644
index 7643b283c4..0000000000
--- a/test/functional/core/job_partial_spec.lua
+++ /dev/null
@@ -1,30 +0,0 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear, eq, next_msg, nvim, source = helpers.clear, helpers.eq,
- helpers.next_message, helpers.nvim, helpers.source
-
-describe('jobs with partials', function()
- local channel
-
- before_each(function()
- clear()
- if helpers.os_name() == 'windows' then
- helpers.set_shell_powershell()
- end
- channel = nvim('get_api_info')[1]
- nvim('set_var', 'channel', channel)
- end)
-
- it('works correctly', function()
- source([[
- function PrintArgs(a1, a2, id, data, event)
- " Windows: Remove ^M char.
- let normalized = map(a:data, 'substitute(v:val, "\r", "", "g")')
- call rpcnotify(g:channel, '1', a:a1, a:a2, normalized, a:event)
- endfunction
- let Callback = function('PrintArgs', ["foo", "bar"])
- let g:job_opts = {'on_stdout': Callback}
- call jobstart('echo "some text"', g:job_opts)
- ]])
- eq({'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, next_msg())
- end)
-end)
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index 48a4689545..6e9633465f 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -7,21 +7,30 @@ local clear, eq, eval, execute, feed, insert, neq, next_msg, nvim,
helpers.write_file, helpers.mkdir, helpers.rmdir
local command = helpers.command
local wait = helpers.wait
+local iswin = helpers.iswin
local Screen = require('test.functional.ui.screen')
-if helpers.pending_win32(pending) then return end
-
describe('jobs', function()
local channel
before_each(function()
clear()
+ if iswin() then
+ helpers.set_shell_powershell()
+ end
channel = nvim('get_api_info')[1]
nvim('set_var', 'channel', channel)
source([[
+ function! Normalize(data) abort
+ " Windows: remove ^M
+ return type([]) == type(a:data)
+ \ ? map(a:data, 'substitute(v:val, "\r", "", "g")')
+ \ : a:data
+ endfunction
function! s:OnEvent(id, data, event) dict
let userdata = get(self, 'user')
- call rpcnotify(g:channel, a:event, userdata, a:data)
+ let data = Normalize(a:data)
+ call rpcnotify(g:channel, a:event, userdata, data)
endfunction
let g:job_opts = {
\ 'on_stdout': function('s:OnEvent'),
@@ -34,15 +43,24 @@ describe('jobs', function()
it('uses &shell and &shellcmdflag if passed a string', function()
nvim('command', "let $VAR = 'abc'")
- nvim('command', "let j = jobstart('echo $VAR', g:job_opts)")
+ if iswin() then
+ nvim('command', "let j = jobstart('echo $env:VAR', g:job_opts)")
+ else
+ nvim('command', "let j = jobstart('echo $VAR', g:job_opts)")
+ end
eq({'notification', 'stdout', {0, {'abc', ''}}}, next_msg())
eq({'notification', 'exit', {0, 0}}, next_msg())
end)
it('changes to given / directory', function()
nvim('command', "let g:job_opts.cwd = '/'")
- nvim('command', "let j = jobstart('pwd', g:job_opts)")
- eq({'notification', 'stdout', {0, {'/', ''}}}, next_msg())
+ if iswin() then
+ nvim('command', "let j = jobstart('pwd|%{$_.Path}', g:job_opts)")
+ else
+ nvim('command', "let j = jobstart('pwd', g:job_opts)")
+ end
+ eq({'notification', 'stdout',
+ {0, {(iswin() and [[C:\]] or '/'), ''}}}, next_msg())
eq({'notification', 'exit', {0, 0}}, next_msg())
end)
@@ -50,7 +68,11 @@ describe('jobs', function()
local dir = eval('resolve(tempname())')
mkdir(dir)
nvim('command', "let g:job_opts.cwd = '" .. dir .. "'")
- nvim('command', "let j = jobstart('pwd', g:job_opts)")
+ if iswin() then
+ nvim('command', "let j = jobstart('pwd|%{$_.Path}', g:job_opts)")
+ else
+ nvim('command', "let j = jobstart('pwd', g:job_opts)")
+ end
eq({'notification', 'stdout', {0, {dir, ''}}}, next_msg())
eq({'notification', 'exit', {0, 0}}, next_msg())
rmdir(dir)
@@ -60,7 +82,11 @@ describe('jobs', function()
local dir = eval('resolve(tempname())."-bogus"')
local _, err = pcall(function()
nvim('command', "let g:job_opts.cwd = '" .. dir .. "'")
- nvim('command', "let j = jobstart('pwd', g:job_opts)")
+ if iswin() then
+ nvim('command', "let j = jobstart('pwd|%{$_.Path}', g:job_opts)")
+ else
+ nvim('command', "let j = jobstart('pwd', g:job_opts)")
+ end
end)
ok(string.find(err, "E475: Invalid argument: expected valid directory$") ~= nil)
end)
@@ -73,7 +99,10 @@ describe('jobs', function()
end)
it('returns -1 when target is not executable #5465', function()
- local function new_job() return eval([[jobstart(['echo', 'foo'])]]) end
+ if helpers.pending_win32(pending) then return end
+ local function new_job()
+ return eval([[jobstart('')]])
+ end
local executable_jobid = new_job()
local nonexecutable_jobid = eval(
"jobstart(['./test/functional/fixtures/non_executable.txt'])")
@@ -85,12 +114,15 @@ describe('jobs', function()
end)
it('invokes callbacks when the job writes and exits', function()
- nvim('command', "call jobstart(['echo'], g:job_opts)")
+ -- TODO: hangs on Windows
+ if helpers.pending_win32(pending) then return end
+ nvim('command', "call jobstart('echo', g:job_opts)")
eq({'notification', 'stdout', {0, {'', ''}}}, next_msg())
eq({'notification', 'exit', {0, 0}}, next_msg())
end)
it('allows interactive commands', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
neq(0, eval('j'))
nvim('command', 'call jobsend(j, "abc\\n")')
@@ -104,6 +136,7 @@ describe('jobs', function()
end)
it('preserves NULs', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
-- Make a file with NULs in it.
local filename = helpers.tmpname()
write_file(filename, "abc\0def\n")
@@ -121,6 +154,7 @@ describe('jobs', function()
end)
it("will not buffer data if it doesn't end in newlines", function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
if os.getenv("TRAVIS") and os.getenv("CC") == "gcc-4.9"
and helpers.os_name() == "osx" then
-- XXX: Hangs Travis macOS since e9061117a5b8f195c3f26a5cb94e18ddd7752d86.
@@ -136,6 +170,7 @@ describe('jobs', function()
end)
it('preserves newlines', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")')
eq({'notification', 'stdout',
@@ -143,6 +178,7 @@ describe('jobs', function()
end)
it('preserves NULs', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])')
eq({'notification', 'stdout', {0, {'\n123\n', 'abc\nxyz\n', ''}}},
@@ -152,6 +188,7 @@ describe('jobs', function()
end)
it('avoids sending final newline', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])')
eq({'notification', 'stdout', {0, {'some data', 'without\nfinal nl'}}},
@@ -161,12 +198,14 @@ describe('jobs', function()
end)
it('closes the job streams with jobclose', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobclose(j, "stdin")')
eq({'notification', 'exit', {0, 0}}, next_msg())
end)
it("disallows jobsend on a job that closed stdin", function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
nvim('command', 'call jobclose(j, "stdin")')
eq(false, pcall(function()
@@ -180,17 +219,20 @@ describe('jobs', function()
end)
it('disallows jobstop twice on the same job', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
neq(0, eval('j'))
eq(true, pcall(eval, "jobstop(j)"))
eq(false, pcall(eval, "jobstop(j)"))
end)
- it('will not cause a memory leak if we leave a job running', function()
+ it('will not leak memory if we leave a job running', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "call jobstart(['cat', '-'], g:job_opts)")
end)
it('can get the pid value using getpid', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)")
local pid = eval('jobpid(j)')
eq(0,os.execute('ps -p '..pid..' > /dev/null'))
@@ -199,19 +241,21 @@ describe('jobs', function()
neq(0,os.execute('ps -p '..pid..' > /dev/null'))
end)
- it("doesn't survive the exit of nvim", function()
+ it("do not survive the exit of nvim", function()
+ if helpers.pending_win32(pending) then return end
-- use sleep, which doesn't die on stdin close
- nvim('command', "let j = jobstart(['sleep', '1000'], g:job_opts)")
- local pid = eval('jobpid(j)')
+ nvim('command', "let g:j = jobstart(['sleep', '1000'], g:job_opts)")
+ local pid = eval('jobpid(g:j)')
eq(0,os.execute('ps -p '..pid..' > /dev/null'))
clear()
neq(0,os.execute('ps -p '..pid..' > /dev/null'))
end)
it('can survive the exit of nvim with "detach"', function()
+ if helpers.pending_win32(pending) then return end
nvim('command', 'let g:job_opts.detach = 1')
- nvim('command', "let j = jobstart(['sleep', '1000'], g:job_opts)")
- local pid = eval('jobpid(j)')
+ nvim('command', "let g:j = jobstart(['sleep', '1000'], g:job_opts)")
+ local pid = eval('jobpid(g:j)')
eq(0,os.execute('ps -p '..pid..' > /dev/null'))
clear()
eq(0,os.execute('ps -p '..pid..' > /dev/null'))
@@ -221,13 +265,14 @@ describe('jobs', function()
it('can pass user data to the callback', function()
nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}')
- nvim('command', "call jobstart(['echo'], g:job_opts)")
+ nvim('command', [[call jobstart('echo "foo"', g:job_opts)]])
local data = {n = 5, s = 'str', l = {1}}
- eq({'notification', 'stdout', {data, {'', ''}}}, next_msg())
+ eq({'notification', 'stdout', {data, {'foo', ''}}}, next_msg())
eq({'notification', 'exit', {data, 0}}, next_msg())
end)
it('can omit options', function()
+ if helpers.pending_win32(pending) then return end
neq(0, nvim('eval', 'delete(".Xtestjob")'))
nvim('command', "call jobstart(['touch', '.Xtestjob'])")
nvim('command', "sleep 100m")
@@ -238,20 +283,20 @@ describe('jobs', function()
nvim('command', 'unlet g:job_opts.on_stdout')
nvim('command', 'unlet g:job_opts.on_stderr')
nvim('command', 'let g:job_opts.user = 5')
- nvim('command', "call jobstart(['echo'], g:job_opts)")
+ nvim('command', [[call jobstart('echo "foo"', g:job_opts)]])
eq({'notification', 'exit', {5, 0}}, next_msg())
end)
it('can omit exit callback', function()
nvim('command', 'unlet g:job_opts.on_exit')
nvim('command', 'let g:job_opts.user = 5')
- nvim('command', "call jobstart(['echo'], g:job_opts)")
- eq({'notification', 'stdout', {5, {'', ''}}}, next_msg())
+ nvim('command', [[call jobstart('echo "foo"', g:job_opts)]])
+ eq({'notification', 'stdout', {5, {'foo', ''}}}, next_msg())
end)
it('will pass return code with the exit event', function()
nvim('command', 'let g:job_opts.user = 5')
- nvim('command', "call jobstart([&sh, '-c', 'exit 55'], g:job_opts)")
+ nvim('command', "call jobstart('exit 55', g:job_opts)")
eq({'notification', 'exit', {5, 55}}, next_msg())
end)
@@ -261,12 +306,13 @@ describe('jobs', function()
function g:dict.on_exit(id, code, event)
call rpcnotify(g:channel, a:event, a:code, self.id)
endfunction
- call jobstart([&sh, '-c', 'exit 45'], g:dict)
+ call jobstart('exit 45', g:dict)
]])
eq({'notification', 'exit', {45, 10}}, next_msg())
end)
it('can redefine callbacks being used by a job', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
local screen = Screen.new()
screen:attach()
screen:set_default_attr_ids({
@@ -298,7 +344,7 @@ describe('jobs', function()
function! s:OnEvent(id, data, event) dict
let g:job_result = get(self, 'user')
endfunction
- let s:job = jobstart(['echo'], {
+ let s:job = jobstart('echo "foo"', {
\ 'on_stdout': 's:OnEvent',
\ 'on_stderr': 's:OnEvent',
\ 'on_exit': 's:OnEvent',
@@ -313,6 +359,7 @@ describe('jobs', function()
end)
it('does not repeat output with slow output handlers', function()
+ if helpers.pending_win32(pending) then return end
source([[
let d = {'data': []}
function! d.on_stdout(job, data, event) dict
@@ -330,14 +377,28 @@ describe('jobs', function()
eq({'notification', 'data', {{{'1', ''}, {'2', ''}, {'3', ''}, {'4', ''}, {'5', ''}}}}, next_msg())
end)
+ it('jobstart() works with partial functions', function()
+ source([[
+ function PrintArgs(a1, a2, id, data, event)
+ " Windows: remove ^M
+ let normalized = map(a:data, 'substitute(v:val, "\r", "", "g")')
+ call rpcnotify(g:channel, '1', a:a1, a:a2, normalized, a:event)
+ endfunction
+ let Callback = function('PrintArgs', ["foo", "bar"])
+ let g:job_opts = {'on_stdout': Callback}
+ call jobstart('echo "some text"', g:job_opts)
+ ]])
+ eq({'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, next_msg())
+ end)
+
describe('jobwait', function()
it('returns a list of status codes', function()
source([[
call rpcnotify(g:channel, 'wait', jobwait([
- \ jobstart([&sh, '-c', 'sleep 0.10; exit 4']),
- \ jobstart([&sh, '-c', 'sleep 0.110; exit 5']),
- \ jobstart([&sh, '-c', 'sleep 0.210; exit 6']),
- \ jobstart([&sh, '-c', 'sleep 0.310; exit 7'])
+ \ jobstart('sleep 0.10; exit 4'),
+ \ jobstart('sleep 0.110; exit 5'),
+ \ jobstart('sleep 0.210; exit 6'),
+ \ jobstart('sleep 0.310; exit 7')
\ ]))
]])
eq({'notification', 'wait', {{4, 5, 6, 7}}}, next_msg())
@@ -354,10 +415,10 @@ describe('jobs', function()
let g:exits += 1
endfunction
call jobwait([
- \ jobstart([&sh, '-c', 'sleep 0.010; exit 5'], g:dict),
- \ jobstart([&sh, '-c', 'sleep 0.030; exit 5'], g:dict),
- \ jobstart([&sh, '-c', 'sleep 0.050; exit 5'], g:dict),
- \ jobstart([&sh, '-c', 'sleep 0.070; exit 5'], g:dict)
+ \ jobstart('sleep 0.010; exit 5', g:dict),
+ \ jobstart('sleep 0.030; exit 5', g:dict),
+ \ jobstart('sleep 0.050; exit 5', g:dict),
+ \ jobstart('sleep 0.070; exit 5', g:dict)
\ ])
call rpcnotify(g:channel, 'wait', g:exits)
]])
@@ -367,10 +428,10 @@ describe('jobs', function()
it('will return status codes in the order of passed ids', function()
source([[
call rpcnotify(g:channel, 'wait', jobwait([
- \ jobstart([&sh, '-c', 'sleep 0.070; exit 4']),
- \ jobstart([&sh, '-c', 'sleep 0.050; exit 5']),
- \ jobstart([&sh, '-c', 'sleep 0.030; exit 6']),
- \ jobstart([&sh, '-c', 'sleep 0.010; exit 7'])
+ \ jobstart('sleep 0.070; exit 4'),
+ \ jobstart('sleep 0.050; exit 5'),
+ \ jobstart('sleep 0.030; exit 6'),
+ \ jobstart('sleep 0.010; exit 7')
\ ]))
]])
eq({'notification', 'wait', {{4, 5, 6, 7}}}, next_msg())
@@ -380,7 +441,7 @@ describe('jobs', function()
source([[
call rpcnotify(g:channel, 'wait', jobwait([
\ -10,
- \ jobstart([&sh, '-c', 'sleep 0.01; exit 5']),
+ \ jobstart('sleep 0.01; exit 5'),
\ ]))
]])
eq({'notification', 'wait', {{-3, 5}}}, next_msg())
@@ -389,13 +450,14 @@ describe('jobs', function()
it('will return -2 when interrupted', function()
execute('call rpcnotify(g:channel, "ready") | '..
'call rpcnotify(g:channel, "wait", '..
- 'jobwait([jobstart([&sh, "-c", "sleep 10; exit 55"])]))')
+ 'jobwait([jobstart("sleep 10; exit 55")]))')
eq({'notification', 'ready', {}}, next_msg())
feed('<c-c>')
eq({'notification', 'wait', {{-2}}}, next_msg())
end)
it('can be called recursively', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
source([[
let g:opts = {}
let g:counter = 0
@@ -426,7 +488,7 @@ describe('jobs', function()
let j.state = 0
let j.counter = g:counter
call jobwait([
- \ jobstart([&sh, '-c', 'echo ready; cat -'], j),
+ \ jobstart('echo ready; cat -', j),
\ ])
endfunction
]])
@@ -442,11 +504,12 @@ describe('jobs', function()
end)
describe('with timeout argument', function()
+ if helpers.pending_win32(pending) then return end
it('will return -1 if the wait timed out', function()
source([[
call rpcnotify(g:channel, 'wait', jobwait([
- \ jobstart([&sh, '-c', 'exit 4']),
- \ jobstart([&sh, '-c', 'sleep 10; exit 5']),
+ \ jobstart('exit 4'),
+ \ jobstart('sleep 10; exit 5'),
\ ], 100))
]])
eq({'notification', 'wait', {{4, -1}}}, next_msg())
@@ -455,8 +518,8 @@ describe('jobs', function()
it('can pass 0 to check if a job exists', function()
source([[
call rpcnotify(g:channel, 'wait', jobwait([
- \ jobstart([&sh, '-c', 'sleep 0.05; exit 4']),
- \ jobstart([&sh, '-c', 'sleep 0.3; exit 5']),
+ \ jobstart('sleep 0.05; exit 4'),
+ \ jobstart('sleep 0.3; exit 5'),
\ ], 0))
]])
eq({'notification', 'wait', {{-1, -1}}}, next_msg())
@@ -475,6 +538,7 @@ describe('jobs', function()
end)
it('cannot have both rpc and pty options', function()
+ if helpers.pending_win32(pending) then return end -- TODO: Need `cat`.
command("let g:job_opts.pty = v:true")
command("let g:job_opts.rpc = v:true")
local _, err = pcall(command, "let j = jobstart(['cat', '-'], g:job_opts)")
@@ -482,6 +546,7 @@ describe('jobs', function()
end)
describe('running tty-test program', function()
+ if helpers.pending_win32(pending) then return end
local function next_chunk()
local rv
while true do
@@ -504,8 +569,14 @@ describe('jobs', function()
end
before_each(function()
- -- the full path to tty-test seems to be required when running on travis.
- insert(nvim_dir .. '/tty-test')
+ -- Redefine Normalize() so that TTY data is not munged.
+ source([[
+ function! Normalize(data) abort
+ return a:data
+ endfunction
+ ]])
+ local ext = iswin() and '.exe' or ''
+ insert(nvim_dir..'/tty-test'..ext) -- Full path to tty-test.
nvim('command', 'let g:job_opts.pty = 1')
nvim('command', 'let exec = [expand("<cfile>:p")]')
nvim('command', "let j = jobstart(exec, g:job_opts)")
@@ -553,6 +624,7 @@ describe("pty process teardown", function()
end)
it("does not prevent/delay exit. #4798 #4900", function()
+ if helpers.pending_win32(pending) then return end
-- Use a nested nvim (in :term) to test without --headless.
execute(":terminal '"..helpers.nvim_prog
-- Use :term again in the _nested_ nvim to get a PTY process.
diff --git a/test/functional/eval/timer_spec.lua b/test/functional/eval/timer_spec.lua
index fba9466b78..4353619ff0 100644
--- a/test/functional/eval/timer_spec.lua
+++ b/test/functional/eval/timer_spec.lua
@@ -81,7 +81,7 @@ describe('timers', function()
run(nil, nil, nil, 300)
feed("c")
local count = eval("g:val")
- ok(count >= 5)
+ ok(count >= 4)
eq(99, eval("g:c"))
end)
diff --git a/test/functional/ex_cmds/ctrl_c_spec.lua b/test/functional/ex_cmds/ctrl_c_spec.lua
index b0acb02000..072fd2ad10 100644
--- a/test/functional/ex_cmds/ctrl_c_spec.lua
+++ b/test/functional/ex_cmds/ctrl_c_spec.lua
@@ -3,17 +3,15 @@ local Screen = require('test.functional.ui.screen')
local clear, feed, source = helpers.clear, helpers.feed, helpers.source
local execute = helpers.execute
-if helpers.pending_win32(pending) then return end
-
describe("CTRL-C (mapped)", function()
before_each(function()
clear()
end)
it("interrupts :global", function()
+ -- Crashes luajit.
if helpers.skip_fragile(pending,
- (os.getenv("TRAVIS") and os.getenv("CLANG_SANITIZER") == "ASAN_UBSAN"))
- then
+ os.getenv("TRAVIS") or os.getenv("APPVEYOR")) then
return
end
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 48ed5c256f..6cae8e6029 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -171,6 +171,10 @@ local os_name = (function()
end)
end)()
+local function iswin()
+ return os_name() == 'windows'
+end
+
-- Executes a VimL function.
-- Fails on VimL error, but does not update v:errmsg.
local function nvim_call(name, ...)
@@ -504,7 +508,6 @@ end
-- Helper to skip tests. Returns true in Windows systems.
-- pending_fn is pending() from busted
local function pending_win32(pending_fn)
- clear()
if uname() == 'Windows' then
if pending_fn ~= nil then
pending_fn('FIXME: Windows', function() end)
@@ -555,6 +558,7 @@ return function(after_each)
source = source,
rawfeed = rawfeed,
insert = insert,
+ iswin = iswin,
feed = feed,
execute = execute,
eval = nvim_eval,
diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua
index d6d8f1c4e5..47b2516188 100644
--- a/test/functional/ui/output_spec.lua
+++ b/test/functional/ui/output_spec.lua
@@ -25,7 +25,7 @@ describe("shell command :!", function()
screen:detach()
end)
- it("displays output even without LF/EOF. #4646 #4569 #3772", function()
+ it("displays output without LF/EOF. #4646 #4569 #3772", function()
-- NOTE: We use a child nvim (within a :term buffer)
-- to avoid triggering a UI flush.
child_session.feed_data(":!printf foo; sleep 200\n")
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 2581b36711..bb82f11a58 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -1,31 +1,17 @@
--- This module contains the Screen class, a complete Nvim screen implementation
--- designed for functional testing. The goal is to provide a simple and
--- intuitive API for verifying screen state after a set of actions.
+-- This module contains the Screen class, a complete Nvim UI implementation
+-- designed for functional testing (verifying screen state, in particular).
--
--- The screen class exposes a single assertion method, "Screen:expect". This
--- method takes a string representing the expected screen state and an optional
--- set of attribute identifiers for checking highlighted characters(more on
--- this later).
---
--- The string passed to "expect" will be processed according to these rules:
---
--- - Each line of the string represents and is matched individually against
--- a screen row.
--- - The entire string is stripped of common indentation
--- - Expected screen rows are stripped of the last character. The last
--- character should be used to write pipes(|) that make clear where the
--- screen ends
--- - The last line is stripped, so the string must have (row count + 1)
--- lines.
+-- Screen:expect() takes a string representing the expected screen state and an
+-- optional set of attribute identifiers for checking highlighted characters.
--
-- Example usage:
--
-- local screen = Screen.new(25, 10)
--- -- attach the screen to the current Nvim instance
+-- -- Attach the screen to the current Nvim instance.
-- screen:attach()
--- --enter insert mode and type some text
+-- -- Enter insert-mode and type some text.
-- feed('ihello screen')
--- -- declare an expectation for the eventual screen state
+-- -- Assert the expected screen state.
-- screen:expect([[
-- hello screen |
-- ~ |
@@ -39,31 +25,19 @@
-- -- INSERT -- |
-- ]]) -- <- Last line is stripped
--
--- Since screen updates are received asynchronously, "expect" is actually
--- specifying the eventual screen state. This is how "expect" works: It will
--- start the event loop with a timeout of 5 seconds. Each time it receives an
--- update the expected state will be checked against the updated state.
---
--- If the expected state matches the current state, the event loop will be
--- stopped and "expect" will return. If the timeout expires, the last match
--- error will be reported and the test will fail.
+-- Since screen updates are received asynchronously, expect() actually specifies
+-- the _eventual_ screen state.
--
--- If the second argument is passed to "expect", the screen rows will be
--- transformed before being matched against the string lines. The
--- transformation rule is simple: Each substring "S" composed with characters
--- having the exact same set of attributes will be substituted by "{K:S}",
--- where K is a key associated the attribute set via the second argument of
--- "expect".
--- If a transformation table is present, unexpected attribute sets in the final
--- state is considered an error. To make testing simpler, a list of attribute
--- sets that should be ignored can be passed as a third argument. Alternatively,
--- this third argument can be "true" to indicate that all unexpected attribute
--- sets should be ignored.
+-- This is how expect() works:
+-- * It starts the event loop with a timeout.
+-- * Each time it receives an update it checks that against the expected state.
+-- * If the expected state matches the current state, the event loop will be
+-- stopped and expect() will return.
+-- * If the timeout expires, the last match error will be reported and the
+-- test will fail.
--
--- To illustrate how this works, let's say that in the above example we wanted
--- to assert that the "-- INSERT --" string is highlighted with the bold
--- attribute(which normally is), here's how the call to "expect" should look
--- like:
+-- Continuing the above example, say we want to assert that "-- INSERT --" is
+-- highlighted with the bold attribute. The expect() call should look like this:
--
-- NonText = Screen.colors.Blue
-- screen:expect([[
@@ -81,29 +55,21 @@
--
-- In this case "b" is a string associated with the set composed of one
-- attribute: bold. Note that since the {b:} markup is not a real part of the
--- screen, the delimiter(|) had to be moved right. Also, the highlighting of the
--- NonText markers (~) is ignored in this test.
+-- screen, the delimiter "|" moved to the right. Also, the highlighting of the
+-- NonText markers "~" is ignored in this test.
+--
+-- Tests will often share a group of attribute sets to expect(). Those can be
+-- defined at the beginning of a test:
--
--- Multiple expect:s will likely share a group of attribute sets to test.
--- Therefore these could be specified at the beginning of a test like this:
-- NonText = Screen.colors.Blue
-- screen:set_default_attr_ids( {
-- [1] = {reverse = true, bold = true},
-- [2] = {reverse = true}
-- })
-- screen:set_default_attr_ignore( {{}, {bold=true, foreground=NonText}} )
--- These can be overridden for a specific expect expression, by passing
--- different sets as parameters.
--
--- To help writing screen tests, there is a utility function
--- "screen:snapshot_util()", that can be placed in a test file at any point an
--- "expect(...)" should be. It will wait a short amount of time and then dump
--- the current state of the screen, in the form of an "expect(..)" expression
--- that would match it exactly. "snapshot_util" optionally also take the
--- transformation and ignore set as parameters, like expect, or uses the default
--- set. It will generate a larger attribute transformation set, if needed.
--- To generate a text-only test without highlight checks,
--- use `screen:snapshot_util({},true)`
+-- To help write screen tests, see Screen:snapshot_util().
+-- To debug screen tests, see Screen:redraw_debug().
local helpers = require('test.functional.helpers')(nil)
local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths
@@ -205,13 +171,22 @@ end
function Screen:try_resize(columns, rows)
uimeths.try_resize(columns, rows)
+ -- Give ourselves a chance to _handle_resize, which requires using
+ -- self.sleep() (for the resize notification) rather than run()
+ self:sleep(0.1)
end
-- Asserts that `expected` eventually matches the screen state.
--
--- expected: Expected screen state (string).
--- attr_ids: Text attribute definitions.
--- attr_ignore: Ignored text attributes.
+-- expected: Expected screen state (string). Each line represents a screen
+-- row. Last character of each row (typically "|") is stripped.
+-- Common indentation is stripped.
+-- attr_ids: Expected text attributes. Screen rows are transformed according
+-- to this table, as follows: each substring S composed of
+-- characters having the same attributes will be substituted by
+-- "{K:S}", where K is a key in `attr_ids`. Any unexpected
+-- attributes in the final state are an error.
+-- attr_ignore: Ignored text attributes, or `true` to ignore all.
-- condition: Function asserting some arbitrary condition.
-- any: true: Succeed if `expected` matches ANY screen line(s).
-- false (default): `expected` must match screen exactly.
@@ -224,6 +199,11 @@ function Screen:expect(expected, attr_ids, attr_ignore, condition, any)
row = row:sub(1, #row - 1)
table.insert(expected_rows, row)
end
+ if not any then
+ assert(self._height == #expected_rows,
+ "Expected screen state's row count(" .. #expected_rows
+ .. ') differs from configured height(' .. self._height .. ') of Screen.')
+ end
local ids = attr_ids or self._default_attr_ids
local ignore = attr_ignore or self._default_attr_ignore
self:wait(function()
@@ -541,8 +521,12 @@ function Screen:_current_screen()
return table.concat(rv, '\n')
end
+-- Generates tests. Call it where Screen:expect() would be. Waits briefly, then
+-- dumps the current screen state in the form of Screen:expect().
+-- Use snapshot_util({},true) to generate a text-only (no attributes) test.
+--
+-- @see Screen:redraw_debug()
function Screen:snapshot_util(attrs, ignore)
- -- util to generate screen test
self:sleep(250)
self:print_snapshot(attrs, ignore)
end
diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua
index d03f98c26f..0824585717 100644
--- a/test/functional/ui/screen_basic_spec.lua
+++ b/test/functional/ui/screen_basic_spec.lua
@@ -4,8 +4,7 @@ local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.cl
local feed, execute = helpers.feed, helpers.execute
local insert = helpers.insert
local eq = helpers.eq
-
-if helpers.pending_win32(pending) then return end
+local eval = helpers.eval
describe('Initial screen', function()
local screen
@@ -563,11 +562,10 @@ describe('Screen', function()
]])
end)
- -- FIXME this has some race conditions that cause it to fail periodically
- pending('has minimum width/height values', function()
+ it('has minimum width/height values', function()
screen:try_resize(1, 1)
screen:expect([[
- -- INS^ERT --|
+ {2:-- INS^ERT --}|
|
]])
feed('<esc>:ls')
@@ -690,4 +688,12 @@ describe('Screen', function()
end)
end)
end)
+
+ it('nvim_ui_attach() handles very large width/height #2180', function()
+ screen:detach()
+ screen = Screen.new(999, 999)
+ screen:attach()
+ eq(999, eval('&lines'))
+ eq(999, eval('&columns'))
+ end)
end)
diff --git a/test/helpers.lua b/test/helpers.lua
index 6f7281db7c..3f7a9c2b74 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -68,6 +68,7 @@ local uname = (function()
local status, f = pcall(io.popen, "uname -s")
if status then
platform = f:read("*l")
+ f:close()
else
platform = 'Windows'
end
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index 9e00a3e8f8..64bbaaa8c2 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -10,19 +10,19 @@ local NULL = helpers.NULL
require('lfs')
-local env = cimport('./src/nvim/os/os.h')
+local cimp = cimport('./src/nvim/os/os.h')
describe('env function', function()
local function os_setenv(name, value, override)
- return env.os_setenv((to_cstr(name)), (to_cstr(value)), override)
+ return cimp.os_setenv((to_cstr(name)), (to_cstr(value)), override)
end
local function os_unsetenv(name, _, _)
- return env.os_unsetenv((to_cstr(name)))
+ return cimp.os_unsetenv((to_cstr(name)))
end
local function os_getenv(name)
- local rval = env.os_getenv((to_cstr(name)))
+ local rval = cimp.os_getenv((to_cstr(name)))
if rval ~= NULL then
return ffi.string(rval)
else
@@ -88,14 +88,14 @@ describe('env function', function()
local i = 0
local names = { }
local found_name = false
- local name = env.os_getenvname_at_index(i)
+ local name = cimp.os_getenvname_at_index(i)
while name ~= NULL do
table.insert(names, ffi.string(name))
if (ffi.string(name)) == test_name then
found_name = true
end
i = i + 1
- name = env.os_getenvname_at_index(i)
+ name = cimp.os_getenvname_at_index(i)
end
eq(true, (table.getn(names)) > 0)
eq(true, found_name)
@@ -104,15 +104,15 @@ describe('env function', function()
it('returns NULL if the index is out of bounds', function()
local huge = ffi.new('size_t', 10000)
local maxuint32 = ffi.new('size_t', 4294967295)
- eq(NULL, env.os_getenvname_at_index(huge))
- eq(NULL, env.os_getenvname_at_index(maxuint32))
+ eq(NULL, cimp.os_getenvname_at_index(huge))
+ eq(NULL, cimp.os_getenvname_at_index(maxuint32))
if ffi.abi('64bit') then
-- couldn't use a bigger number because it gets converted to
-- double somewere, should be big enough anyway
-- maxuint64 = ffi.new 'size_t', 18446744073709551615
local maxuint64 = ffi.new('size_t', 18446744073709000000)
- eq(NULL, env.os_getenvname_at_index(maxuint64))
+ eq(NULL, cimp.os_getenvname_at_index(maxuint64))
end
end)
end)
@@ -124,10 +124,10 @@ describe('env function', function()
local stat_str = stat_file:read('*l')
stat_file:close()
local pid = tonumber((stat_str:match('%d+')))
- eq(pid, tonumber(env.os_get_pid()))
+ eq(pid, tonumber(cimp.os_get_pid()))
else
-- /proc is not available on all systems, test if pid is nonzero.
- eq(true, (env.os_get_pid() > 0))
+ eq(true, (cimp.os_get_pid() > 0))
end
end)
end)
@@ -138,7 +138,7 @@ describe('env function', function()
local hostname = handle:read('*l')
handle:close()
local hostname_buf = cstr(255, '')
- env.os_get_hostname(hostname_buf, 255)
+ cimp.os_get_hostname(hostname_buf, 255)
eq(hostname, (ffi.string(hostname_buf)))
end)
end)
@@ -155,39 +155,52 @@ describe('env function', function()
local output_buff1 = cstr(255, '')
local output_buff2 = cstr(255, '')
local output_expected = 'NEOVIM_UNIT_TEST_EXPAND_ENV_ESCV/test'
- env.expand_env_esc(input1, output_buff1, 255, false, true, NULL)
- env.expand_env_esc(input2, output_buff2, 255, false, true, NULL)
+ cimp.expand_env_esc(input1, output_buff1, 255, false, true, NULL)
+ cimp.expand_env_esc(input2, output_buff2, 255, false, true, NULL)
eq(output_expected, ffi.string(output_buff1))
eq(output_expected, ffi.string(output_buff2))
end)
- it('expands ~ once when one is true', function()
+ it('expands ~ once when `one` is true', function()
local input = '~/foo ~ foo'
local homedir = cstr(255, '')
- env.expand_env_esc(to_cstr('~'), homedir, 255, false, true, NULL)
+ cimp.expand_env_esc(to_cstr('~'), homedir, 255, false, true, NULL)
local output_expected = ffi.string(homedir) .. "/foo ~ foo"
local output = cstr(255, '')
- env.expand_env_esc(to_cstr(input), output, 255, false, true, NULL)
+ cimp.expand_env_esc(to_cstr(input), output, 255, false, true, NULL)
eq(ffi.string(output), ffi.string(output_expected))
end)
- it('expands ~ every time when one is false', function()
+ it('expands ~ every time when `one` is false', function()
local input = to_cstr('~/foo ~ foo')
- local homedir = cstr(255, '')
- env.expand_env_esc(to_cstr('~'), homedir, 255, false, true, NULL)
- homedir = ffi.string(homedir)
+ local dst = cstr(255, '')
+ cimp.expand_env_esc(to_cstr('~'), dst, 255, false, true, NULL)
+ local homedir = ffi.string(dst)
local output_expected = homedir .. "/foo " .. homedir .. " foo"
local output = cstr(255, '')
- env.expand_env_esc(input, output, 255, false, false, NULL)
+ cimp.expand_env_esc(input, output, 255, false, false, NULL)
eq(output_expected, ffi.string(output))
end)
- it('respects the dstlen parameter without expansion', function()
+ it('does not crash #3725', function()
+ local name_out = ffi.new('char[100]')
+ cimp.os_get_user_name(name_out, 100)
+ local curuser = ffi.string(name_out)
+
+ local src = to_cstr("~"..curuser.."/Vcs/django-rest-framework/rest_framework/renderers.py")
+ local dst = cstr(256, "~"..curuser)
+ cimp.expand_env_esc(src, dst, 1024, false, false, NULL)
+ local len = string.len(ffi.string(dst))
+ assert.True(len > 56)
+ assert.True(len < 99)
+ end)
+
+ it('respects `dstlen` without expansion', function()
local input = to_cstr('this is a very long thing that will not fit')
-- The buffer is long enough to actually contain the full input in case the
-- test fails, but we don't tell expand_env_esc that
local output = cstr(255, '')
- env.expand_env_esc(input, output, 5, false, true, NULL)
+ cimp.expand_env_esc(input, output, 5, false, true, NULL)
-- Make sure the first few characters are copied properly and that there is a
-- terminating null character
for i=0,3 do
@@ -196,17 +209,17 @@ describe('env function', function()
eq(0, output[4])
end)
- it('respects the dstlen parameter with expansion', function()
+ it('respects `dstlen` with expansion', function()
local varname = to_cstr('NVIM_UNIT_TEST_EXPAND_ENV_ESC_DSTLENN')
local varval = to_cstr('NVIM_UNIT_TEST_EXPAND_ENV_ESC_DSTLENV')
- env.os_setenv(varname, varval, 1)
+ cimp.os_setenv(varname, varval, 1)
-- TODO(bobtwinkles) This test uses unix-specific environment variable accessing,
-- should have some alternative for windows
local input = to_cstr('$NVIM_UNIT_TEST_EXPAND_ENV_ESC_DSTLENN/even more stuff')
-- The buffer is long enough to actually contain the full input in case the
-- test fails, but we don't tell expand_env_esc that
local output = cstr(255, '')
- env.expand_env_esc(input, output, 5, false, true, NULL)
+ cimp.expand_env_esc(input, output, 5, false, true, NULL)
-- Make sure the first few characters are copied properly and that there is a
-- terminating null character
-- expand_env_esc SHOULD NOT expand the variable if there is not enough space to