aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-06-25 02:08:21 +0200
committerGitHub <noreply@github.com>2018-06-25 02:08:21 +0200
commite475476d1041a6632cfb9d3fff48051fcef0fbf5 (patch)
treec53a6e657d6d49080548df8a9d824fdca0e490c0 /src
parent7892192751cc9c1f4d344eab101e531378568041 (diff)
parent14b3741ec5410c4dc1b71950d1994f24c7a9744a (diff)
downloadrneovim-e475476d1041a6632cfb9d3fff48051fcef0fbf5.tar.gz
rneovim-e475476d1041a6632cfb9d3fff48051fcef0fbf5.tar.bz2
rneovim-e475476d1041a6632cfb9d3fff48051fcef0fbf5.zip
Merge #8621 from janlazo/vim-8.0.0642
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c11
-rw-r--r--src/nvim/testdir/test_writefile.vim21
2 files changed, 27 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 86ed9052aa..8d45863d6f 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -17675,7 +17675,7 @@ static void f_wordcount(typval_T *argvars, typval_T *rettv, FunPtr fptr)
/// "writefile()" function
static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
- rettv->vval.v_number = 0; // Assuming success.
+ rettv->vval.v_number = -1;
if (check_restricted() || check_secure()) {
return;
@@ -17685,6 +17685,12 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
EMSG2(_(e_listarg), "writefile()");
return;
}
+ const list_T *const list = argvars[0].vval.v_list;
+ TV_LIST_ITER_CONST(list, li, {
+ if (!tv_check_str_or_nr(TV_LIST_ITEM_TV(li))) {
+ return;
+ }
+ });
bool binary = false;
bool append = false;
@@ -17716,7 +17722,6 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
}
FileDescriptor fp;
int error;
- rettv->vval.v_number = -1;
if (*fname == NUL) {
EMSG(_("E482: Can't open file with an empty name"));
} else if ((error = file_open(&fp, fname,
@@ -17725,7 +17730,7 @@ static void f_writefile(typval_T *argvars, typval_T *rettv, FunPtr fptr)
emsgf(_("E482: Can't open file %s for writing: %s"),
fname, os_strerror(error));
} else {
- if (write_list(&fp, argvars[0].vval.v_list, binary)) {
+ if (write_list(&fp, list, binary)) {
rettv->vval.v_number = 0;
}
if ((error = file_close(&fp, do_fsync)) != 0) {
diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim
index d820c580ac..8b031646b5 100644
--- a/src/nvim/testdir/test_writefile.vim
+++ b/src/nvim/testdir/test_writefile.vim
@@ -1,5 +1,6 @@
+" Tests for the writefile() function.
-function! Test_WriteFile()
+func Test_writefile()
let f = tempname()
call writefile(["over","written"], f, "b")
call writefile(["hello","world"], f, "b")
@@ -13,4 +14,20 @@ function! Test_WriteFile()
call assert_equal("morning", l[3])
call assert_equal("vimmers", l[4])
call delete(f)
-endfunction
+endfunc
+
+func Test_writefile_fails_gently()
+ call assert_fails('call writefile(["test"], "Xfile", [])', 'E730:')
+ call assert_false(filereadable("Xfile"))
+ call delete("Xfile")
+
+ call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E745:')
+ call assert_false(filereadable("Xfile"))
+ call delete("Xfile")
+
+ call assert_fails('call writefile([], "Xfile", [])', 'E730:')
+ call assert_false(filereadable("Xfile"))
+ call delete("Xfile")
+
+ call assert_fails('call writefile([], [])', 'E730:')
+endfunc