annotate src/testdir/test_stat.vim @ 13810:cad480bac9e1 v8.0.1777

patch 8.0.1777: cannot cleanup before loading another colorscheme commit https://github.com/vim/vim/commit/60a68362aa73f4a6cb534688978f9dc2b16e60fe Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 30 15:40:48 2018 +0200 patch 8.0.1777: cannot cleanup before loading another colorscheme Problem: Cannot cleanup before loading another colorscheme. Solution: Add the ColorSchemePre autocommand event.
author Christian Brabandt <cb@256bit.org>
date Mon, 30 Apr 2018 15:45:07 +0200
parents 709b898e2119
children 977cab3d5474
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for stat functions and checktime
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
12150
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
3 func CheckFileTime(doSleep)
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
4 let fname = 'Xtest.tmp'
12150
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
5 let result = 0
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
7 let ts = localtime()
12150
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
8 if a:doSleep
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
9 sleep 1
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
10 endif
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
11 let fl = ['Hello World!']
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 call writefile(fl, fname)
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
13 let tf = getftime(fname)
12150
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
14 if a:doSleep
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
15 sleep 1
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
16 endif
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
17 let te = localtime()
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18
12150
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
19 let time_correct = (ts <= tf && tf <= te)
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
20 if a:doSleep || time_correct
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
21 call assert_true(time_correct)
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
22 call assert_equal(strlen(fl[0] . "\n"), getfsize(fname))
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
23 call assert_equal('file', getftype(fname))
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
24 call assert_equal('rw-', getfperm(fname)[0:2])
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
25 let result = 1
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
26 endif
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
27
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
28 call delete(fname)
12150
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
29 return result
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
30 endfunc
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
31
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
32 func Test_existent_file()
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
33 " On some systems the file timestamp is rounded to a multiple of 2 seconds.
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
34 " We need to sleep to handle that, but that makes the test slow. First try
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
35 " without the sleep, and if it fails try again with the sleep.
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
36 if CheckFileTime(0) == 0
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
37 call CheckFileTime(1)
709b898e2119 patch 8.0.0955: Test_existent_file() fails on some file systems
Christian Brabandt <cb@256bit.org>
parents: 10805
diff changeset
38 endif
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 endfunc
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 func Test_existent_directory()
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
42 let dname = '.'
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 call assert_equal(0, getfsize(dname))
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 call assert_equal('dir', getftype(dname))
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 call assert_equal('rwx', getfperm(dname)[0:2])
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 endfunc
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 func Test_checktime()
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
50 let fname = 'Xtest.tmp'
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
52 let fl = ['Hello World!']
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 call writefile(fl, fname)
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 set autoread
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 exec 'e' fname
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
56 " FAT has a granularity of 2 seconds, otherwise it's usually 1 second
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
57 if has('win32')
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
58 sleep 2
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
59 else
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
60 sleep 1
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
61 endif
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
62 let fl = readfile(fname)
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 let fl[0] .= ' - checktime'
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call writefile(fl, fname)
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 checktime
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call assert_equal(fl[0], getline(1))
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
67
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
68 call delete(fname)
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 endfunc
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 func Test_nonexistent_file()
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
72 let fname = 'Xtest.tmp'
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 call delete(fname)
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 call assert_equal(-1, getftime(fname))
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 call assert_equal(-1, getfsize(fname))
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 call assert_equal('', getftype(fname))
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 call assert_equal('', getfperm(fname))
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 endfunc
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 func Test_win32_symlink_dir()
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 " On Windows, non-admin users cannot create symlinks.
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 " So we use an existing symlink for this test.
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 if has('win32')
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 " Check if 'C:\Users\All Users' is a symlink to a directory.
10805
750779134e67 patch 8.0.0292: the stat test is a bit slow
Christian Brabandt <cb@256bit.org>
parents: 9387
diff changeset
86 let res = system('dir C:\Users /a')
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 if match(res, '\C<SYMLINKD> *All Users') >= 0
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 " Get the filetype of the symlink.
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 call assert_equal('dir', getftype('C:\Users\All Users'))
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 endif
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 endif
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 endfunc