|
1 | 1 | " Tests for stat functions and checktime |
2 | 2 |
|
3 | 3 | func CheckFileTime(doSleep) |
4 | | - let fname = 'Xtest.tmp' |
| 4 | + let fnames = ['Xtest1.tmp', 'Xtest2.tmp', 'Xtest3.tmp'] |
| 5 | + let times = [] |
5 | 6 | let result = 0 |
6 | 7 |
|
7 | | - let ts = localtime() |
8 | | - if a:doSleep |
9 | | - sleep 1 |
10 | | - endif |
| 8 | + " Use three files istead of localtim(), with a network filesystem the file |
| 9 | + " times may differ at bit |
11 | 10 | let fl = ['Hello World!'] |
12 | | - call writefile(fl, fname) |
13 | | - let tf = getftime(fname) |
14 | | - if a:doSleep |
15 | | - sleep 1 |
16 | | - endif |
17 | | - let te = localtime() |
| 11 | + for fname in fnames |
| 12 | + call writefile(fl, fname) |
| 13 | + call add(times, getftime(fname)) |
| 14 | + if a:doSleep |
| 15 | + sleep 1 |
| 16 | + endif |
| 17 | + endfor |
18 | 18 |
|
19 | | - let time_correct = (ts <= tf && tf <= te) |
| 19 | + let time_correct = (times[0] <= times[1] && times[1] <= times[2]) |
20 | 20 | if a:doSleep || time_correct |
21 | | - call assert_true(time_correct) |
22 | | - call assert_equal(strlen(fl[0] . "\n"), getfsize(fname)) |
23 | | - call assert_equal('file', getftype(fname)) |
24 | | - call assert_equal('rw-', getfperm(fname)[0:2]) |
| 21 | + call assert_true(time_correct, printf('Expected %s <= %s <= %s', times[0], times[1], times[2])) |
| 22 | + call assert_equal(strlen(fl[0] . "\n"), getfsize(fnames[0])) |
| 23 | + call assert_equal('file', getftype(fnames[0])) |
| 24 | + call assert_equal('rw-', getfperm(fnames[0])[0:2]) |
25 | 25 | let result = 1 |
26 | 26 | endif |
27 | 27 |
|
28 | | - call delete(fname) |
| 28 | + for fname in fnames |
| 29 | + call delete(fname) |
| 30 | + endfor |
29 | 31 | return result |
30 | 32 | endfunc |
31 | 33 |
|
|
0 commit comments