Compare commits

...

9 Commits

Author SHA1 Message Date
Bram Moolenaar
e4218b9416 patch 8.2.1348: build failure without the eval feature
Problem:    Build failure without the eval feature.
Solution:   Add #ifdef.
2020-08-01 21:11:38 +02:00
Bram Moolenaar
909443028b patch 8.2.1347: cannot easily get the script ID
Problem:    Cannot easily get the script ID.
Solution:   Support expand('<SID>').
2020-08-01 20:45:11 +02:00
Bram Moolenaar
491799be50 patch 8.2.1346: small build fails
Problem:    Small build fails.
Solution:   Add #ifdef.
2020-08-01 19:23:43 +02:00
Bram Moolenaar
f8992d47cd patch 8.2.1345: Redraw error when using visual block and scroll
Problem:    Redraw error when using visual block and scroll.
Solution:   Add check for w_topline. ( closes #6597)
2020-08-01 19:14:13 +02:00
Bram Moolenaar
2c79e9d14d patch 8.2.1344: Vim9: No test for trying to redefine global function
Problem:    Vim9: No test for trying to redefine global function.
Solution:   Add a test.
2020-08-01 18:57:52 +02:00
Bram Moolenaar
333894b195 patch 8.2.1343: Vim9: cannot find global function when using g:
Problem:    Vim9: cannot find global function when using g: when local
            function with the same name exists.
Solution:   Find global function when using g:.
2020-08-01 18:53:07 +02:00
Bram Moolenaar
f5a48010ef patch 8.2.1342: Vim9: accidentally using "t" gives a confusing error
Problem:    Vim9: accidentally using "x" gives a confusing error.
Solution:   Disallow using ":t" in Vim9 script. (issue #6399)
2020-08-01 17:00:03 +02:00
Bram Moolenaar
2ec208172c patch 8.2.1341: build failures
Problem:    Build failures.
Solution:   Add missing error message.
2020-08-01 16:35:08 +02:00
Bram Moolenaar
b86abadf87 patch 8.2.1340: some tests fail on Cirrus CI and/or with FreeBSD
Problem:    Some tests fail on Cirrus CI and/or with FreeBSD.
Solution:   Make 'backupskip' empty. Do not run tests as root. Check for
            directory when using viminfo. (Ozaki Kiichi, closes #6596)
2020-08-01 16:08:19 +02:00
20 changed files with 210 additions and 75 deletions

View File

@@ -11,6 +11,9 @@ freebsd_12_task:
- NPROC=$(getconf _NPROCESSORS_ONLN)
- ./configure --with-features=${FEATURES}
- make -j${NPROC}
- src/vim --version
test_script:
- make test
- src/vim --version
# run tests as user "cirrus" instead of root
- pw useradd cirrus -m
- chown -R cirrus:cirrus .
- sudo -u cirrus make test

View File

@@ -1167,6 +1167,10 @@ When executing an autocommand or a user command, it will run in the context of
the script it was defined in. This makes it possible that the command calls a
local function or uses a local mapping.
In case the value is used in a context where <SID> cannot be correctly
expanded, use the expand() function: >
let &includexpr = expand('<SID>') .. 'My_includeexpr()'
Otherwise, using "<SID>" outside of a script context is an error.
If you need to get the script number to use in a complicated script, you can

View File

@@ -190,8 +190,8 @@ To intentionally avoid a variable being available later, a block can be used:
An existing variable cannot be assigned to with `:let`, since that implies a
declaration. Global, window, tab, buffer and Vim variables can only be used
without `:let`, because they are are not really declared, they can also be
deleted with `:unlet`.
without `:let`, because they are not really declared, they can also be deleted
with `:unlet`.
Variables cannot shadow previously defined variables.
Variables may shadow Ex commands, rename the variable if needed.
@@ -352,10 +352,11 @@ No curly braces expansion ~
|curly-braces-names| cannot be used.
No :xit, :append, :change or :insert ~
No :xit, :t, :append, :change or :insert ~
These commands are too easily confused with local variable names. Instead of
`:x` or `:xit` you can use `:exit`.
These commands are too easily confused with local variable names.
Instead of `:x` or `:xit` you can use `:exit`.
Instead of `:t` you can use `:copy`.
Comparators ~

View File

@@ -1659,10 +1659,13 @@ win_update(win_T *wp)
#endif
)
{
if (mod_top != 0 && wp->w_topline == mod_top)
if (mod_top != 0
&& wp->w_topline == mod_top
&& (!wp->w_lines[0].wl_valid
|| wp->w_topline == wp->w_lines[0].wl_lnum))
{
// w_topline is the first changed line, the scrolling will be done
// further down.
// w_topline is the first changed line and window is not scrolled,
// the scrolling from changed lines will be done further down.
}
else if (wp->w_lines[0].wl_valid
&& (wp->w_topline < wp->w_lines[0].wl_lnum

View File

@@ -7276,6 +7276,10 @@ ex_copymove(exarg_T *eap)
{
long n;
#ifdef FEAT_EVAL
if (not_in_vim9(eap) == FAIL)
return;
#endif
n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1);
if (eap->arg == NULL) // error detected
{
@@ -8298,9 +8302,11 @@ find_cmdline_var(char_u *src, int *usedlen)
#define SPEC_AMATCH (SPEC_ABUF + 1)
"<sflnum>", // script file line number
#define SPEC_SFLNUM (SPEC_AMATCH + 1)
"<SID>", // script ID: <SNR>123_
#define SPEC_SID (SPEC_SFLNUM + 1)
#ifdef FEAT_CLIENTSERVER
"<client>"
# define SPEC_CLIENT (SPEC_SFLNUM + 1)
# define SPEC_CLIENT (SPEC_SID + 1)
#endif
};
@@ -8575,6 +8581,16 @@ eval_vars(
(long)(current_sctx.sc_lnum + SOURCING_LNUM));
result = strbuf;
break;
case SPEC_SID:
if (current_sctx.sc_sid <= 0)
{
*errormsg = _(e_usingsid);
return NULL;
}
sprintf((char *)strbuf, "<SNR>%d_", current_sctx.sc_sid);
result = strbuf;
break;
#endif
#ifdef FEAT_CLIENTSERVER

View File

@@ -1684,6 +1684,7 @@ EXTERN char e_readonlysbx[] INIT(= N_("E794: Cannot set variable in the sandbox:
EXTERN char e_stringreq[] INIT(= N_("E928: String required"));
EXTERN char e_emptykey[] INIT(= N_("E713: Cannot use empty key for Dictionary"));
EXTERN char e_dictreq[] INIT(= N_("E715: Dictionary required"));
EXTERN char e_dictnull[] INIT(= N_("E1103: Dictionary not set"));
EXTERN char e_listidx[] INIT(= N_("E684: list index out of range: %ld"));
EXTERN char e_blobidx[] INIT(= N_("E979: Blob index out of range: %ld"));
EXTERN char e_invalblob[] INIT(= N_("E978: Invalid operation for Blob"));

View File

@@ -0,0 +1,7 @@
|{+0&#e0e0e08| | +0&#ffffff0@72
|}+0&#e0e0e08| | +0&#ffffff0@72
|{+0&#e0e0e08| | +0&#ffffff0@72
|f+0&#e0e0e08| | +0&#ffffff0@72
>g| +0&#e0e0e08| +0&#ffffff0@72
|}| @73
|-+2&&@1| |V|I|S|U|A|L| |L|I|N|E| |-@1| +0&&@29|7| @8|1@1|,|1| @9|B|o|t|

View File

@@ -19,6 +19,22 @@ func Test_backup()
call delete('Xbackup.txt~')
endfunc
func Test_backup_backupskip()
set backup backupdir=. backupskip=*.txt
new
call setline(1, ['line1', 'line2'])
:f Xbackup.txt
:w! Xbackup.txt
" backup file is only created after
" writing a second time (before overwriting)
:w! Xbackup.txt
call assert_false(filereadable('Xbackup.txt~'))
bw!
set backup&vim backupdir&vim backupskip&vim
call delete('Xbackup.txt')
call delete('Xbackup.txt~')
endfunc
func Test_backup2()
set backup backupdir=.// backupskip=
new
@@ -30,7 +46,7 @@ func Test_backup2()
:w! Xbackup.txt
sp *Xbackup.txt~
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
let f=expand('%')
let f = expand('%')
call assert_match('%testdir%Xbackup.txt\~', f)
bw!
bw!
@@ -50,7 +66,7 @@ func Test_backup2_backupcopy()
:w! Xbackup.txt
sp *Xbackup.txt~
call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
let f=expand('%')
let f = expand('%')
call assert_match('%testdir%Xbackup.txt\~', f)
bw!
bw!
@@ -61,14 +77,11 @@ endfunc
" Test for using a non-existing directory as a backup directory
func Test_non_existing_backupdir()
CheckNotBSD
let save_backup = &backupdir
set backupdir=./non_existing_dir
set backupdir=./non_existing_dir backupskip=
call writefile(['line1'], 'Xfile')
new Xfile
" TODO: write doesn't fail in Cirrus FreeBSD CI test
call assert_fails('write', 'E510:')
let &backupdir = save_backup
set backupdir&vim backupskip&vim
call delete('Xfile')
endfunc

View File

@@ -220,3 +220,26 @@ func Test_unprintable_fileformats()
call delete('Xmac.txt')
call delete(filename)
endfunc
" Test for scrolling that modifies buffer during visual block
func Test_visual_block_scroll()
CheckScreendump
let lines =<< trim END
source $VIMRUNTIME/plugin/matchparen.vim
set scrolloff=1
call setline(1, ['a', 'b', 'c', 'd', 'e', '', '{', '}', '{', 'f', 'g', '}'])
call cursor(5, 1)
END
let filename = 'Xvisualblockmodifiedscroll'
call writefile(lines, filename)
let buf = RunVimInTerminal('-S '.filename, #{rows: 7})
call term_sendkeys(buf, "V\<C-D>\<C-D>")
call VerifyScreenDump(buf, 'Test_display_visual_block_scroll', {})
call StopVimInTerminal(buf)
call delete(filename)
endfunc

View File

@@ -1682,7 +1682,6 @@ endfunc
" Test for editing a file without read permission
func Test_edit_file_no_read_perm()
CheckUnix
CheckNotBSD
call writefile(['one', 'two'], 'Xfile')
call setfperm('Xfile', '-w-------')
new

View File

@@ -1,5 +1,7 @@
" Tests for expand()
source shared.vim
let s:sfile = expand('<sfile>')
let s:slnum = str2nr(expand('<slnum>'))
let s:sflnum = str2nr(expand('<sflnum>'))
@@ -18,20 +20,20 @@ endfunc
" This test depends on the location in the test file, put it first.
func Test_expand_sflnum()
call assert_equal(5, s:sflnum)
call assert_equal(22, str2nr(expand('<sflnum>')))
call assert_equal(7, s:sflnum)
call assert_equal(24, str2nr(expand('<sflnum>')))
" Line-continuation
call assert_equal(
\ 25,
\ 27,
\ str2nr(expand('<sflnum>')))
" Call in script-local function
call assert_equal(16, s:expand_sflnum())
call assert_equal(18, s:expand_sflnum())
" Call in command
command Flnum echo expand('<sflnum>')
call assert_equal(34, str2nr(trim(execute('Flnum'))))
call assert_equal(36, str2nr(trim(execute('Flnum'))))
delcommand Flnum
endfunc
@@ -60,7 +62,7 @@ func Test_expand_sfile_and_stack()
endfunc
func Test_expand_slnum()
call assert_equal(4, s:slnum)
call assert_equal(6, s:slnum)
call assert_equal(2, str2nr(expand('<slnum>')))
" Line-continuation
@@ -86,6 +88,17 @@ func Test_expand()
quit
endfunc
func s:sid_test()
return 'works'
endfunc
func Test_expand_SID()
let sid = expand('<SID>')
execute 'let g:sid_result = ' .. sid .. 'sid_test()'
call assert_equal('works', g:sid_result)
endfunc
" Test for 'wildignore' with expand()
func Test_expand_wildignore()
set wildignore=*.vim

View File

@@ -159,6 +159,34 @@ def Test_nested_global_function()
delfunc g:Inner
END
CheckScriptSuccess(lines)
lines =<< trim END
vim9script
def Outer()
def g:Inner(): string
return 'inner'
enddef
enddef
defcompile
Outer()
Outer()
END
CheckScriptFailure(lines, "E122:")
enddef
def Test_global_local_function()
let lines =<< trim END
vim9script
def g:Func(): string
return 'global'
enddef
def Func(): string
return 'local'
enddef
assert_equal('global', g:Func())
assert_equal('local', Func())
END
CheckScriptSuccess(lines)
enddef
func TakesOneArg(arg)

View File

@@ -1628,18 +1628,21 @@ def Test_fixed_size_list()
enddef
def Test_no_insert_xit()
call CheckDefExecFailure(['x = 1'], 'E1100:')
call CheckDefExecFailure(['a = 1'], 'E1100:')
call CheckDefExecFailure(['i = 1'], 'E1100:')
call CheckDefExecFailure(['c = 1'], 'E1100:')
call CheckDefExecFailure(['i = 1'], 'E1100:')
call CheckDefExecFailure(['t = 1'], 'E1100:')
call CheckDefExecFailure(['x = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'a = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'a'], 'E1100:')
CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'i'], 'E1100:')
CheckScriptFailure(['vim9script', 'c = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'c'], 'E1100:')
CheckScriptFailure(['vim9script', 'i = 1'], 'E488:')
CheckScriptFailure(['vim9script', 'i'], 'E1100:')
CheckScriptFailure(['vim9script', 't'], 'E1100:')
CheckScriptFailure(['vim9script', 't = 1'], 'E1100:')
CheckScriptFailure(['vim9script', 'x = 1'], 'E1100:')
enddef
def IfElse(what: number): string

View File

@@ -807,7 +807,7 @@ func Test_viminfo_perm()
" Try to write the viminfo to a directory
call mkdir('Xdir')
call assert_fails('wviminfo Xdir', 'E886:')
call assert_fails('wviminfo Xdir', 'E137:')
call delete('Xdir', 'rf')
endfunc

View File

@@ -136,9 +136,7 @@ func Test_writefile_sync_arg()
endfunc
func Test_writefile_sync_dev_stdout()
if !has('unix')
return
endif
CheckUnix
if filewritable('/dev/stdout')
" Just check that this doesn't cause an error.
call writefile(['one'], '/dev/stdout')
@@ -371,13 +369,10 @@ endfunc
" Test for writing to a readonly file
func Test_write_readonly()
" In Cirrus-CI, the freebsd tests are run under a root account. So this test
" doesn't fail.
CheckNotBSD
call writefile([], 'Xfile')
call setfperm('Xfile', "r--------")
edit Xfile
set noreadonly
set noreadonly backupskip=
call assert_fails('write', 'E505:')
let save_cpo = &cpo
set cpo+=W
@@ -386,37 +381,32 @@ func Test_write_readonly()
call setline(1, ['line1'])
write!
call assert_equal(['line1'], readfile('Xfile'))
set backupskip&
call delete('Xfile')
endfunc
" Test for 'patchmode'
func Test_patchmode()
CheckNotBSD
call writefile(['one'], 'Xfile')
set patchmode=.orig nobackup writebackup
set patchmode=.orig nobackup backupskip= writebackup
new Xfile
call setline(1, 'two')
" first write should create the .orig file
write
" TODO: Xfile.orig is not created in Cirrus FreeBSD CI test
call assert_equal(['one'], readfile('Xfile.orig'))
call setline(1, 'three')
" subsequent writes should not create/modify the .orig file
write
call assert_equal(['one'], readfile('Xfile.orig'))
set patchmode& backup& writebackup&
set patchmode& backup& backupskip& writebackup&
call delete('Xfile')
call delete('Xfile.orig')
endfunc
" Test for writing to a file in a readonly directory
func Test_write_readonly_dir()
if !has('unix') || has('bsd')
" On MS-Windows, modifying files in a read-only directory is allowed.
" In Cirrus-CI for Freebsd, tests are run under a root account where
" modifying files in a read-only directory are allowed.
return
endif
" On MS-Windows, modifying files in a read-only directory is allowed.
CheckUnix
call mkdir('Xdir')
call writefile(['one'], 'Xdir/Xfile1')
call setfperm('Xdir', 'r-xr--r--')
@@ -426,12 +416,12 @@ func Test_write_readonly_dir()
call assert_fails('write', 'E212:')
" try to create a backup file in the directory
edit! Xdir/Xfile1
set backupdir=./Xdir
set backupdir=./Xdir backupskip=
set patchmode=.orig
call assert_fails('write', 'E509:')
call setfperm('Xdir', 'rwxr--r--')
call delete('Xdir', 'rf')
set backupdir& patchmode&
set backupdir& backupskip& patchmode&
endfunc
" Test for writing a file using invalid file encoding

View File

@@ -789,9 +789,10 @@ find_func_even_dead(char_u *name, int is_global, cctx_T *cctx)
if (!is_global)
{
char_u *after_script = NULL;
int vim9script = in_vim9script();
char_u *after_script = NULL;
if (in_vim9script())
if (vim9script)
{
// Find script-local function before global one.
func = find_func_with_sid(name, current_sctx.sc_sid);
@@ -799,7 +800,7 @@ find_func_even_dead(char_u *name, int is_global, cctx_T *cctx)
return func;
}
if (!in_vim9script()
if (!vim9script
&& name[0] == K_SPECIAL
&& name[1] == KS_EXTRA
&& name[2] == KE_SNR)
@@ -815,7 +816,7 @@ find_func_even_dead(char_u *name, int is_global, cctx_T *cctx)
else
after_script = NULL;
}
if (in_vim9script() || after_script != NULL)
if (vim9script || after_script != NULL)
{
// Find imported function before global one.
imported = find_imported(
@@ -2086,10 +2087,14 @@ call_func(
if (error == FCERR_NONE && funcexe->evaluate)
{
char_u *rfname = fname;
int is_global = FALSE;
// Ignore "g:" before a function name.
// Skip "g:" before a function name.
if (fp == NULL && fname[0] == 'g' && fname[1] == ':')
{
is_global = TRUE;
rfname = fname + 2;
}
rettv->v_type = VAR_NUMBER; // default rettv is number zero
rettv->vval.v_number = 0;
@@ -2101,7 +2106,7 @@ call_func(
* User defined function.
*/
if (fp == NULL)
fp = find_func(rfname, FALSE, NULL);
fp = find_func(rfname, is_global, NULL);
// Trigger FuncUndefined event, may load the function.
if (fp == NULL
@@ -2110,13 +2115,13 @@ call_func(
&& !aborting())
{
// executed an autocommand, search for the function again
fp = find_func(rfname, FALSE, NULL);
fp = find_func(rfname, is_global, NULL);
}
// Try loading a package.
if (fp == NULL && script_autoload(rfname, TRUE) && !aborting())
{
// loaded a package, search for the function again
fp = find_func(rfname, FALSE, NULL);
fp = find_func(rfname, is_global, NULL);
}
if (fp == NULL)
{
@@ -2125,7 +2130,7 @@ call_func(
// If using Vim9 script try not local to the script.
// TODO: should not do this if the name started with "s:".
if (p != NULL)
fp = find_func(p, FALSE, NULL);
fp = find_func(p, is_global, NULL);
}
if (fp != NULL && (fp->uf_flags & FC_DELETED))
@@ -2175,6 +2180,7 @@ call_func(
*/
error = call_internal_func(fname, argcount, argvars, rettv);
}
/*
* The function call (or "FuncUndefined" autocommand sequence) might
* have been aborted by an error, an interrupt, or an explicitly thrown

View File

@@ -754,6 +754,24 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1348,
/**/
1347,
/**/
1346,
/**/
1345,
/**/
1344,
/**/
1343,
/**/
1342,
/**/
1341,
/**/
1340,
/**/
1339,
/**/

View File

@@ -7467,6 +7467,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
case CMD_append:
case CMD_change:
case CMD_insert:
case CMD_t:
case CMD_xit:
not_in_vim9(&ea);
goto erret;

View File

@@ -67,9 +67,10 @@ not_in_vim9(exarg_T *eap)
if (in_vim9script())
switch (eap->cmdidx)
{
case CMD_insert:
case CMD_append:
case CMD_change:
case CMD_insert:
case CMD_t:
case CMD_xit:
semsg(_("E1100: Missing :let: %s"), eap->cmd);
return FAIL;

View File

@@ -3007,6 +3007,7 @@ read_viminfo(
{
FILE *fp;
char_u *fname;
stat_T st; // mch_stat() of existing viminfo file
if (no_viminfo())
return FAIL;
@@ -3031,6 +3032,11 @@ read_viminfo(
vim_free(fname);
if (fp == NULL)
return FAIL;
if (mch_fstat(fileno(fp), &st) < 0 || S_ISDIR(st.st_mode))
{
fclose(fp);
return FAIL;
}
viminfo_errcnt = 0;
do_viminfo(fp, NULL, flags);
@@ -3054,12 +3060,12 @@ write_viminfo(char_u *file, int forceit)
FILE *fp_out = NULL; // output viminfo file
char_u *tempname = NULL; // name of temp viminfo file
stat_T st_new; // mch_stat() of potential new file
stat_T st_old; // mch_stat() of existing viminfo file
#if defined(UNIX) || defined(VMS)
mode_t umask_save;
#endif
#ifdef UNIX
int shortname = FALSE; // use 8.3 file name
stat_T st_old; // mch_stat() of existing viminfo file
#endif
#ifdef MSWIN
int hidden = FALSE;
@@ -3097,20 +3103,20 @@ write_viminfo(char_u *file, int forceit)
// write the new viminfo into, in the same directory as the
// existing viminfo file, which will be renamed once all writing is
// successful.
if (mch_fstat(fileno(fp_in), &st_old) < 0
|| S_ISDIR(st_old.st_mode)
#ifdef UNIX
// For Unix we check the owner of the file. It's not very nice to
// overwrite a user's viminfo file after a "su root", with a
// viminfo file that the user can't read.
st_old.st_dev = (dev_t)0;
st_old.st_ino = 0;
st_old.st_mode = 0600;
if (mch_stat((char *)fname, &st_old) == 0
&& getuid() != ROOT_UID
&& !(st_old.st_uid == getuid()
? (st_old.st_mode & 0200)
: (st_old.st_gid == getgid()
? (st_old.st_mode & 0020)
: (st_old.st_mode & 0002))))
// For Unix we check the owner of the file. It's not very nice
// to overwrite a user's viminfo file after a "su root", with a
// viminfo file that the user can't read.
|| (getuid() != ROOT_UID
&& !(st_old.st_uid == getuid()
? (st_old.st_mode & 0200)
: (st_old.st_gid == getgid()
? (st_old.st_mode & 0020)
: (st_old.st_mode & 0002))))
#endif
)
{
int tt = msg_didany;
@@ -3120,7 +3126,6 @@ write_viminfo(char_u *file, int forceit)
fclose(fp_in);
goto end;
}
#endif
#ifdef MSWIN
// Get the file attributes of the existing viminfo file.
hidden = mch_ishidden(fname);