annotate src/testdir/test_writefile.vim @ 16694:ed9b15758241 v8.1.1349

patch 8.1.1349: if writing runs into conversion error backup file is deleted commit https://github.com/vim/vim/commit/cf0bfd9ade5173bcc12563bfc90c21a4db10535d Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 18 18:52:04 2019 +0200 patch 8.1.1349: if writing runs into conversion error backup file is deleted Problem: If writing runs into a conversion error the backup file is deleted. (Arseny Nasokin) Solution: Don't delete the backup file is the file was overwritten and a conversion error occurred. (Christian Brabandt, closes #4387)
author Bram Moolenaar <Bram@vim.org>
date Sat, 18 May 2019 19:00:05 +0200
parents 772e72b046a3
children e264d45f268a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11519
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
1 " Tests for the writefile() function.
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
11519
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
3 func Test_writefile()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 let f = tempname()
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 call writefile(["over","written"], f, "b")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 call writefile(["hello","world"], f, "b")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 call writefile(["!", "good"], f, "a")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 call writefile(["morning"], f, "ab")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 call writefile(["", "vimmers"], f, "ab")
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let l = readfile(f)
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 call assert_equal("hello", l[0])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call assert_equal("world!", l[1])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 call assert_equal("good", l[2])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 call assert_equal("morning", l[3])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal("vimmers", l[4])
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 call delete(f)
11519
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
17 endfunc
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
18
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
19 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
20 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
21 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
22 call delete("Xfile")
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
23
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
24 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
25 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
26 call delete("Xfile")
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
27
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
28 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
29 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
30 call delete("Xfile")
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
31
4a1f7849fe86 patch 8.0.0642: writefile() continues after detecting an error
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
32 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
33 endfunc
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
34
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
35 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
36 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
37 return
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
38 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
39 " 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
40 " error.
11605
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
41 set nobackup nowritebackup
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
42 new
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
43 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
44 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
45 edit Xfile
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
46 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
47 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
48 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
49
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
50 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
51 bwipe!
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
52 set backup& writebackup&
16ccaedce025 patch 8.0.0685: when conversion fails written file may be truncated
Christian Brabandt <cb@256bit.org>
parents: 11519
diff changeset
53 endfunc
12624
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
54
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
55 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
56 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
57 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
58 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
59 " 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
60 " but then the backup file must remain
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
61 set nobackup writebackup
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
62 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
63 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
64 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
65 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
66 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
67 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
68 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
69 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
70
ed9b15758241 patch 8.1.1349: if writing runs into conversion error backup file is deleted
Bram Moolenaar <Bram@vim.org>
parents: 15677
diff changeset
71 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
72 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
73 bwipe!
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 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
75
12624
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
76 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
77 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
78 endfunc
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
79
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
80 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
81 " 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
82 augroup testgroup
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
83 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
84 augroup END
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
85 e! Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
86 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
87 wq
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
88
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
89 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
90 " 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
91 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
92 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
93 sleep 50m
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
94 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
95 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
96 endif
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
97 au! testgroup
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
98 bwipe Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
99 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
100 endfunc
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
101
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
102 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
103 " 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
104 e! Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
105 help
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
106 wincmd w
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
107 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
108
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
109 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
110 " 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
111 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
112 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
113 sleep 50m
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
114 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
115 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
116 endif
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
117 bwipe Xfile
ae2802b6bf7d patch 8.0.1190: unusable after opening new window in BufWritePre event
Christian Brabandt <cb@256bit.org>
parents: 11605
diff changeset
118 endfunc
12857
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
119
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
120 func Test_writefile_sync_arg()
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
121 " 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
122 call writefile(['one'], 'Xtest', 's')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
123 call writefile(['two'], 'Xtest', 'S')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
124 call delete('Xtest')
ffdf2e4b5d9a patch 8.0.1305: writefile() never calls fsync()
Christian Brabandt <cb@256bit.org>
parents: 12624
diff changeset
125 endfunc
12926
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
126
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
127 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
128 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
129 return
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
130 endif
13744
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
131 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
132 " 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
133 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
134 else
d6553cde1292 patch 8.0.1744: on some systems /dev/stdout isn't writable
Christian Brabandt <cb@256bit.org>
parents: 12926
diff changeset
135 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
136 endif
12926
98503d690368 patch 8.0.1339: no test for what 8.0.1335 fixes
Christian Brabandt <cb@256bit.org>
parents: 12857
diff changeset
137 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
138
96858d612aff patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written
Christian Brabandt <cb@256bit.org>
parents: 13744
diff changeset
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 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
147 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
148 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
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 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
151 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
152 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
153
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 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
155 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
156 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
157 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
158 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
159
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 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
161 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
162 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
163 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
164 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
165 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
166 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
167 " 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
168 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
169 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
170 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
171 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
172
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 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
174 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
175 endfunc