Mercurial > vim
annotate src/testdir/test_writefile.vim @ 20823:9c648a5f2eda
Added tag v8.2.0963 for changeset 8e5f991db3b4cdb844776b77887ab56eca7b8ba8
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 12 Jun 2020 20:30:05 +0200 |
parents | d8628d75c47a |
children | 1725bb56178a |
rev | line source |
---|---|
18386
105c6cf8b266
patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents:
16869
diff
changeset
|
1 " Tests for the writefile() function and some :write commands. |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
19277
1b02482e6a61
patch 8.2.0197: some Ex commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19231
diff
changeset
|
3 source check.vim |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
4 source term_util.vim |
19277
1b02482e6a61
patch 8.2.0197: some Ex commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19231
diff
changeset
|
5 |
11519
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
6 func Test_writefile() |
10068
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 let f = tempname() |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 call writefile(["over","written"], f, "b") |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 call writefile(["hello","world"], f, "b") |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 call writefile(["!", "good"], f, "a") |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 call writefile(["morning"], f, "ab") |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 call writefile(["", "vimmers"], f, "ab") |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 let l = readfile(f) |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 call assert_equal("hello", l[0]) |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 call assert_equal("world!", l[1]) |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 call assert_equal("good", l[2]) |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 call assert_equal("morning", l[3]) |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 call assert_equal("vimmers", l[4]) |
c577c6a2e88b
commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 call delete(f) |
19695
1697a25328fd
patch 8.2.0404: writefile() error does not give a hint
Bram Moolenaar <Bram@vim.org>
parents:
19425
diff
changeset
|
20 |
1697a25328fd
patch 8.2.0404: writefile() error does not give a hint
Bram Moolenaar <Bram@vim.org>
parents:
19425
diff
changeset
|
21 call assert_fails('call writefile("text", "Xfile")', 'E475: Invalid argument: writefile() first argument must be a List or a Blob') |
11519
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
22 endfunc |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
23 |
18386
105c6cf8b266
patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents:
16869
diff
changeset
|
24 func Test_writefile_ignore_regexp_error() |
105c6cf8b266
patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents:
16869
diff
changeset
|
25 write Xt[z-a]est.txt |
105c6cf8b266
patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents:
16869
diff
changeset
|
26 call delete('Xt[z-a]est.txt') |
105c6cf8b266
patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents:
16869
diff
changeset
|
27 endfunc |
105c6cf8b266
patch 8.1.2187: error for bad regexp even though regexp is not used
Bram Moolenaar <Bram@vim.org>
parents:
16869
diff
changeset
|
28 |
11519
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
29 func Test_writefile_fails_gently() |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
30 call assert_fails('call writefile(["test"], "Xfile", [])', 'E730:') |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
31 call assert_false(filereadable("Xfile")) |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
32 call delete("Xfile") |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
33 |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
34 call assert_fails('call writefile(["test", [], [], [], "tset"], "Xfile")', 'E730:') |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
35 call assert_false(filereadable("Xfile")) |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
36 call delete("Xfile") |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
37 |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
38 call assert_fails('call writefile([], "Xfile", [])', 'E730:') |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
39 call assert_false(filereadable("Xfile")) |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
40 call delete("Xfile") |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
41 |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
42 call assert_fails('call writefile([], [])', 'E730:') |
4a1f7849fe86
patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents:
10068
diff
changeset
|
43 endfunc |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
44 |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
45 func Test_writefile_fails_conversion() |
15677
772e72b046a3
patch 8.1.0846: not easy to recognize the system Vim runs on
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
46 if !has('iconv') || has('sun') |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
47 return |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
48 endif |
16694
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
49 " Without a backup file the write won't happen if there is a conversion |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
50 " error. |
16869
e264d45f268a
patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents:
16694
diff
changeset
|
51 set nobackup nowritebackup backupdir=. backupskip= |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
52 new |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
53 let contents = ["line one", "line two"] |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
54 call writefile(contents, 'Xfile') |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
55 edit Xfile |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
56 call setline(1, ["first line", "cannot convert \u010b", "third line"]) |
16694
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
57 call assert_fails('write ++enc=cp932', 'E513:') |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
58 call assert_equal(contents, readfile('Xfile')) |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
59 |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
60 call delete('Xfile') |
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
61 bwipe! |
16869
e264d45f268a
patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents:
16694
diff
changeset
|
62 set backup& writebackup& backupdir&vim backupskip&vim |
11605
16ccaedce025
patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents:
11519
diff
changeset
|
63 endfunc |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
64 |
16694
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
65 func Test_writefile_fails_conversion2() |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
66 if !has('iconv') || has('sun') |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
67 return |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
68 endif |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
69 " With a backup file the write happens even if there is a conversion error, |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
70 " but then the backup file must remain |
16869
e264d45f268a
patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents:
16694
diff
changeset
|
71 set nobackup writebackup backupdir=. backupskip= |
16694
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
72 let contents = ["line one", "line two"] |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
73 call writefile(contents, 'Xfile_conversion_err') |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
74 edit Xfile_conversion_err |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
75 call setline(1, ["first line", "cannot convert \u010b", "third line"]) |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
76 set fileencoding=latin1 |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
77 let output = execute('write') |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
78 call assert_match('CONVERSION ERROR', output) |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
79 call assert_equal(contents, readfile('Xfile_conversion_err~')) |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
80 |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
81 call delete('Xfile_conversion_err') |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
82 call delete('Xfile_conversion_err~') |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
83 bwipe! |
16869
e264d45f268a
patch 8.1.1436: writefile test fails when run under /tmp
Bram Moolenaar <Bram@vim.org>
parents:
16694
diff
changeset
|
84 set backup& writebackup& backupdir&vim backupskip&vim |
16694
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
85 endfunc |
ed9b15758241
patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents:
15677
diff
changeset
|
86 |
12624
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
87 func SetFlag(timer) |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
88 let g:flag = 1 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
89 endfunc |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
90 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
91 func Test_write_quit_split() |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
92 " Prevent exiting by splitting window on file write. |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
93 augroup testgroup |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
94 autocmd BufWritePre * split |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
95 augroup END |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
96 e! Xfile |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
97 call setline(1, 'nothing') |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
98 wq |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
99 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
100 if has('timers') |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
101 " timer will not run if "exiting" is still set |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
102 let g:flag = 0 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
103 call timer_start(1, 'SetFlag') |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
104 sleep 50m |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
105 call assert_equal(1, g:flag) |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
106 unlet g:flag |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
107 endif |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
108 au! testgroup |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
109 bwipe Xfile |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
110 call delete('Xfile') |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
111 endfunc |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
112 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
113 func Test_nowrite_quit_split() |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
114 " Prevent exiting by opening a help window. |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
115 e! Xfile |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
116 help |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
117 wincmd w |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
118 exe winnr() . 'q' |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
119 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
120 if has('timers') |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
121 " timer will not run if "exiting" is still set |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
122 let g:flag = 0 |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
123 call timer_start(1, 'SetFlag') |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
124 sleep 50m |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
125 call assert_equal(1, g:flag) |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
126 unlet g:flag |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
127 endif |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
128 bwipe Xfile |
ae2802b6bf7d
patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents:
11605
diff
changeset
|
129 endfunc |
12857
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
130 |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
131 func Test_writefile_sync_arg() |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
132 " This doesn't check if fsync() works, only that the argument is accepted. |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
133 call writefile(['one'], 'Xtest', 's') |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
134 call writefile(['two'], 'Xtest', 'S') |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
135 call delete('Xtest') |
ffdf2e4b5d9a
patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents:
12624
diff
changeset
|
136 endfunc |
12926
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
137 |
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
138 func Test_writefile_sync_dev_stdout() |
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
139 if !has('unix') |
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
140 return |
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
141 endif |
13744
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
142 if filewritable('/dev/stdout') |
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
143 " Just check that this doesn't cause an error. |
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
144 call writefile(['one'], '/dev/stdout') |
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
145 else |
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
146 throw 'Skipped: /dev/stdout is not writable' |
d6553cde1292
patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents:
12926
diff
changeset
|
147 endif |
12926
98503d690368
patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents:
12857
diff
changeset
|
148 endfunc |
14642
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
149 |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
150 func Test_writefile_autowrite() |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
151 set autowrite |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
152 new |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
153 next Xa Xb Xc |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
154 call setline(1, 'aaa') |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
155 next |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
156 call assert_equal(['aaa'], readfile('Xa')) |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
157 call setline(1, 'bbb') |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
158 call assert_fails('edit XX') |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
159 call assert_false(filereadable('Xb')) |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
160 |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
161 set autowriteall |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
162 edit XX |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
163 call assert_equal(['bbb'], readfile('Xb')) |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
164 |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
165 bwipe! |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
166 call delete('Xa') |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
167 call delete('Xb') |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
168 set noautowrite |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
169 endfunc |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
170 |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
171 func Test_writefile_autowrite_nowrite() |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
172 set autowrite |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
173 new |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
174 next Xa Xb Xc |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
175 set buftype=nowrite |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
176 call setline(1, 'aaa') |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
177 let buf = bufnr('%') |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
178 " buffer contents silently lost |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
179 edit XX |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
180 call assert_false(filereadable('Xa')) |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
181 rewind |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
182 call assert_equal('', getline(1)) |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
183 |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
184 bwipe! |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
185 set noautowrite |
96858d612aff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents:
13744
diff
changeset
|
186 endfunc |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
187 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
188 " Test for ':w !<cmd>' to pipe lines from the current buffer to an external |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
189 " command. |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
190 func Test_write_pipe_to_cmd() |
19277
1b02482e6a61
patch 8.2.0197: some Ex commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
19231
diff
changeset
|
191 CheckUnix |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
192 new |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
193 call setline(1, ['L1', 'L2', 'L3', 'L4']) |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
194 2,3w !cat > Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
195 call assert_equal(['L2', 'L3'], readfile('Xfile')) |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
196 close! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
197 call delete('Xfile') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
198 endfunc |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
199 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
200 " Test for :saveas |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
201 func Test_saveas() |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
202 call assert_fails('saveas', 'E471:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
203 call writefile(['L1'], 'Xfile') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
204 new Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
205 new |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
206 call setline(1, ['L1']) |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
207 call assert_fails('saveas Xfile', 'E139:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
208 close! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
209 enew | only |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
210 call delete('Xfile') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
211 endfunc |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
212 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
213 func Test_write_errors() |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
214 " Test for writing partial buffer |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
215 call writefile(['L1', 'L2', 'L3'], 'Xfile') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
216 new Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
217 call assert_fails('1,2write', 'E140:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
218 close! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
219 |
19384
6c944fee0d7e
patch 8.2.0250: test_clear_search_pat() is unused
Bram Moolenaar <Bram@vim.org>
parents:
19277
diff
changeset
|
220 call assert_fails('w > Xtest', 'E494:') |
19425
67fbe280a502
patch 8.2.0270: some code not covered by tests
Bram Moolenaar <Bram@vim.org>
parents:
19384
diff
changeset
|
221 |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
222 " Try to overwrite a directory |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
223 if has('unix') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
224 call mkdir('Xdir1') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
225 call assert_fails('write Xdir1', 'E17:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
226 call delete('Xdir1', 'd') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
227 endif |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
228 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
229 " Test for :wall for a buffer with no name |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
230 enew | only |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
231 call setline(1, ['L1']) |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
232 call assert_fails('wall', 'E141:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
233 enew! |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
234 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
235 " Test for writing a 'readonly' file |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
236 new Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
237 set readonly |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
238 call assert_fails('write', 'E45:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
239 close |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
240 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
241 " Test for writing to a read-only file |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
242 new Xfile |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
243 call setfperm('Xfile', 'r--r--r--') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
244 call assert_fails('write', 'E505:') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
245 call setfperm('Xfile', 'rw-rw-rw-') |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
246 close |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
247 |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
248 call delete('Xfile') |
20178
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
249 |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
250 call writefile(test_null_list(), 'Xfile') |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
251 call assert_false(filereadable('Xfile')) |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
252 call writefile(test_null_blob(), 'Xfile') |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
253 call assert_false(filereadable('Xfile')) |
2fb397573541
patch 8.2.0644: insufficient testing for invalid function arguments
Bram Moolenaar <Bram@vim.org>
parents:
19695
diff
changeset
|
254 call assert_fails('call writefile([], "")', 'E482:') |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
255 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
256 " very long file name |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
257 let long_fname = repeat('n', 5000) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
258 call assert_fails('exe "w " .. long_fname', 'E75:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
259 call assert_fails('call writefile([], long_fname)', 'E482:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
260 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
261 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
262 " Test for writing to a file which is modified after Vim read it |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
263 func Test_write_file_mtime() |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
264 CheckEnglish |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
265 CheckRunVimInTerminal |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
266 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
267 " First read the file into a buffer |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
268 call writefile(["Line1", "Line2"], 'Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
269 let old_ftime = getftime('Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
270 let buf = RunVimInTerminal('Xfile', #{rows : 10}) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
271 call term_wait(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
272 call term_sendkeys(buf, ":set noswapfile\<CR>") |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
273 call term_wait(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
274 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
275 " Modify the file directly. Make sure the file modification time is |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
276 " different. Note that on Linux/Unix, the file is considered modified |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
277 " outside, only if the difference is 2 seconds or more |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
278 sleep 1 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
279 call writefile(["Line3", "Line4"], 'Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
280 let new_ftime = getftime('Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
281 while new_ftime - old_ftime < 2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
282 sleep 100m |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
283 call writefile(["Line3", "Line4"], 'Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
284 let new_ftime = getftime('Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
285 endwhile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
286 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
287 " Try to overwrite the file and check for the prompt |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
288 call term_sendkeys(buf, ":w\<CR>") |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
289 call term_wait(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
290 call WaitForAssert({-> assert_equal("WARNING: The file has been changed since reading it!!!", term_getline(buf, 9))}) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
291 call assert_equal("Do you really want to write to it (y/n)?", |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
292 \ term_getline(buf, 10)) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
293 call term_sendkeys(buf, "n\<CR>") |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
294 call term_wait(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
295 call assert_equal(new_ftime, getftime('Xfile')) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
296 call term_sendkeys(buf, ":w\<CR>") |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
297 call term_wait(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
298 call term_sendkeys(buf, "y\<CR>") |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
299 call term_wait(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
300 call WaitForAssert({-> assert_equal('Line2', readfile('Xfile')[1])}) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
301 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
302 " clean up |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
303 call StopVimInTerminal(buf) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
304 call delete('Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
305 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
306 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
307 " Test for an autocmd unloading a buffer during a write command |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
308 func Test_write_autocmd_unloadbuf_lockmark() |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
309 augroup WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
310 autocmd BufWritePre Xfile enew | write |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
311 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
312 e Xfile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
313 call assert_fails('lockmarks write', 'E203:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
314 augroup WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
315 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
316 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
317 augroup! WriteTest |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
318 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
319 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
320 " Test for writing a buffer with 'acwrite' but without autocmds |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
321 func Test_write_acwrite_error() |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
322 new Xfile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
323 call setline(1, ['line1', 'line2', 'line3']) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
324 set buftype=acwrite |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
325 call assert_fails('write', 'E676:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
326 call assert_fails('1,2write!', 'E676:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
327 call assert_fails('w >>', 'E676:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
328 close! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
329 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
330 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
331 " Test for adding and removing lines from an autocmd when writing a buffer |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
332 func Test_write_autocmd_add_remove_lines() |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
333 new Xfile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
334 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
335 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
336 " Autocmd deleting lines from the file when writing a partial file |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
337 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
338 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
339 autocmd FileWritePre Xfile 1,2d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
340 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
341 call assert_fails('2,3w!', 'E204:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
342 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
343 " Autocmd adding lines to a file when writing a partial file |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
344 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
345 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
346 autocmd FileWritePre Xfile call append(0, ['xxx', 'yyy']) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
347 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
348 %d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
349 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
350 1,2w! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
351 call assert_equal(['xxx', 'yyy', 'aaa', 'bbb'], readfile('Xfile')) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
352 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
353 " Autocmd deleting lines from the file when writing the whole file |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
354 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
355 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
356 autocmd BufWritePre Xfile 1,2d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
357 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
358 %d |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
359 call setline(1, ['aaa', 'bbb', 'ccc', 'ddd']) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
360 w |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
361 call assert_equal(['ccc', 'ddd'], readfile('Xfile')) |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
362 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
363 augroup WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
364 au! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
365 augroup END |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
366 augroup! WriteTest2 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
367 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
368 close! |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
369 call delete('Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
370 endfunc |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
371 |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
372 " Test for writing to a readonly file |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
373 func Test_write_readonly() |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
374 " In Cirrus-CI, the freebsd tests are run under a root account. So this test |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
375 " doesn't fail. |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
376 CheckNotBSD |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
377 call writefile([], 'Xfile') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
378 call setfperm('Xfile', "r--------") |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
379 edit Xfile |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
380 set noreadonly |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
381 call assert_fails('write', 'E505:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
382 let save_cpo = &cpo |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
383 set cpo+=W |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
384 call assert_fails('write!', 'E504:') |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
385 let &cpo = save_cpo |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
386 call setline(1, ['line1']) |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
387 write! |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
388 call assert_equal(['line1'], readfile('Xfile')) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20178
diff
changeset
|
389 call delete('Xfile') |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
390 endfunc |
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
391 |
20812
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
392 " Test for 'patchmode' |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
393 func Test_patchmode() |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
394 CheckNotBSD |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
395 call writefile(['one'], 'Xfile') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
396 set patchmode=.orig nobackup writebackup |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
397 new Xfile |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
398 call setline(1, 'two') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
399 " first write should create the .orig file |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
400 write |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
401 " TODO: Xfile.orig is not created in Cirrus FreeBSD CI test |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
402 call assert_equal(['one'], readfile('Xfile.orig')) |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
403 call setline(1, 'three') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
404 " subsequent writes should not create/modify the .orig file |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
405 write |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
406 call assert_equal(['one'], readfile('Xfile.orig')) |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
407 set patchmode& backup& writebackup& |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
408 call delete('Xfile') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
409 call delete('Xfile.orig') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
410 endfunc |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
411 |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
412 " Test for writing to a file in a readonly directory |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
413 func Test_write_readonly_dir() |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
414 if !has('unix') || has('bsd') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
415 " On MS-Windows, modifying files in a read-only directory is allowed. |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
416 " In Cirrus-CI for Freebsd, tests are run under a root account where |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
417 " modifying files in a read-only directory are allowed. |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
418 return |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
419 endif |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
420 call mkdir('Xdir') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
421 call writefile(['one'], 'Xdir/Xfile1') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
422 call setfperm('Xdir', 'r-xr--r--') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
423 " try to create a new file in the directory |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
424 new Xdir/Xfile2 |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
425 call setline(1, 'two') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
426 call assert_fails('write', 'E212:') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
427 " try to create a backup file in the directory |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
428 edit! Xdir/Xfile1 |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
429 set backupdir=./Xdir |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
430 set patchmode=.orig |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
431 call assert_fails('write', 'E509:') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
432 call setfperm('Xdir', 'rwxr--r--') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
433 call delete('Xdir', 'rf') |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
434 set backupdir& patchmode& |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
435 endfunc |
d8628d75c47a
patch 8.2.0958: not sufficient testing for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20625
diff
changeset
|
436 |
19231
b8fd7364befd
patch 8.2.0174: various commands not completely tested
Bram Moolenaar <Bram@vim.org>
parents:
18386
diff
changeset
|
437 " vim: shiftwidth=2 sts=2 expandtab |