aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir/test_stat.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/testdir/test_stat.vim')
-rw-r--r--src/nvim/testdir/test_stat.vim54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/nvim/testdir/test_stat.vim b/src/nvim/testdir/test_stat.vim
index c276df0a92..253f74c2ad 100644
--- a/src/nvim/testdir/test_stat.vim
+++ b/src/nvim/testdir/test_stat.vim
@@ -1,31 +1,33 @@
" Tests for stat functions and checktime
func CheckFileTime(doSleep)
- let fname = 'Xtest.tmp'
+ let fnames = ['Xtest1.tmp', 'Xtest2.tmp', 'Xtest3.tmp']
+ let times = []
let result = 0
- let ts = localtime()
- if a:doSleep
- sleep 1
- endif
+ " Use three files istead of localtim(), with a network filesystem the file
+ " times may differ at bit
let fl = ['Hello World!']
- call writefile(fl, fname)
- let tf = getftime(fname)
- if a:doSleep
- sleep 1
- endif
- let te = localtime()
+ for fname in fnames
+ call writefile(fl, fname)
+ call add(times, getftime(fname))
+ if a:doSleep
+ sleep 1
+ endif
+ endfor
- let time_correct = (ts <= tf && tf <= te)
+ let time_correct = (times[0] <= times[1] && times[1] <= times[2])
if a:doSleep || time_correct
- call assert_true(time_correct)
- call assert_equal(strlen(fl[0] . "\n"), getfsize(fname))
- call assert_equal('file', getftype(fname))
- call assert_equal('rw-', getfperm(fname)[0:2])
+ call assert_true(time_correct, printf('Expected %s <= %s <= %s', times[0], times[1], times[2]))
+ call assert_equal(strlen(fl[0] . "\n"), getfsize(fnames[0]))
+ call assert_equal('file', getftype(fnames[0]))
+ call assert_equal('rw-', getfperm(fnames[0])[0:2])
let result = 1
endif
- call delete(fname)
+ for fname in fnames
+ call delete(fname)
+ endfor
return result
endfunc
@@ -141,17 +143,29 @@ func Test_getftype()
endif
for cdevfile in systemlist('find /dev -type c -maxdepth 2 2>/dev/null')
- call assert_equal('cdev', getftype(cdevfile))
+ let type = getftype(cdevfile)
+ " ignore empty result, can happen if the file disappeared
+ if type != ''
+ call assert_equal('cdev', type)
+ endif
endfor
for bdevfile in systemlist('find /dev -type b -maxdepth 2 2>/dev/null')
- call assert_equal('bdev', getftype(bdevfile))
+ let type = getftype(bdevfile)
+ " ignore empty result, can happen if the file disappeared
+ if type != ''
+ call assert_equal('bdev', type)
+ endif
endfor
" The /run/ directory typically contains socket files.
" If it does not, test won't fail but will not test socket files.
for socketfile in systemlist('find /run -type s -maxdepth 2 2>/dev/null')
- call assert_equal('socket', getftype(socketfile))
+ let type = getftype(socketfile)
+ " ignore empty result, can happen if the file disappeared
+ if type != ''
+ call assert_equal('socket', type)
+ endif
endfor
" TODO: file type 'other' is not tested. How can we test it?