xref: /vim-8.2.3635/src/testdir/test_stat.vim (revision cb03397a)
1" Tests for stat functions and checktime
2
3func Test_existent_file()
4  let fname='Xtest.tmp'
5
6  let ts=localtime()
7  sleep 1
8  let fl=['Hello World!']
9  call writefile(fl, fname)
10  let tf=getftime(fname)
11  sleep 1
12  let te=localtime()
13
14  call assert_true(ts <= tf && tf <= te)
15  call assert_equal(strlen(fl[0] . "\n"), getfsize(fname))
16  call assert_equal('file', getftype(fname))
17  call assert_equal('rw-', getfperm(fname)[0:2])
18endfunc
19
20func Test_existent_directory()
21  let dname='.'
22
23  call assert_equal(0, getfsize(dname))
24  call assert_equal('dir', getftype(dname))
25  call assert_equal('rwx', getfperm(dname)[0:2])
26endfunc
27
28func Test_checktime()
29  let fname='Xtest.tmp'
30
31  let fl=['Hello World!']
32  call writefile(fl, fname)
33  set autoread
34  exec 'e' fname
35  sleep 2
36  let fl=readfile(fname)
37  let fl[0] .= ' - checktime'
38  call writefile(fl, fname)
39  checktime
40  call assert_equal(fl[0], getline(1))
41endfunc
42
43func Test_nonexistent_file()
44  let fname='Xtest.tmp'
45
46  call delete(fname)
47  call assert_equal(-1, getftime(fname))
48  call assert_equal(-1, getfsize(fname))
49  call assert_equal('', getftype(fname))
50  call assert_equal('', getfperm(fname))
51endfunc
52
53func Test_win32_symlink_dir()
54  " On Windows, non-admin users cannot create symlinks.
55  " So we use an existing symlink for this test.
56  if has('win32')
57    " Check if 'C:\Users\All Users' is a symlink to a directory.
58    let res=system('dir C:\Users /a')
59    if match(res, '\C<SYMLINKD> *All Users') >= 0
60      " Get the filetype of the symlink.
61      call assert_equal('dir', getftype('C:\Users\All Users'))
62    endif
63  endif
64endfunc
65