Skip to content

Commit 1598f99

Browse files
committed
patch 8.1.0262: not enough testing for getftype()
Problem: Not enough testing for getftype(). Solution: Add a test. (Dominique Pelle, closes #3300)
1 parent 38efd1d commit 1598f99

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/evalfunc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5111,7 +5111,7 @@ f_getftype(typval_T *argvars, typval_T *rettv)
51115111
# endif
51125112
# ifdef S_ISSOCK
51135113
else if (S_ISSOCK(st.st_mode))
5114-
t = "fifo";
5114+
t = "socket";
51155115
# endif
51165116
else
51175117
t = "other";

src/testdir/test_stat.vim

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,41 @@ func Test_nonexistent_file()
122122
call assert_equal('', getfperm(fname))
123123
endfunc
124124

125+
func Test_getftype()
126+
call assert_equal('file', getftype(v:progpath))
127+
call assert_equal('dir', getftype('.'))
128+
129+
if !has('unix')
130+
return
131+
endif
132+
133+
silent !ln -s Xfile Xlink
134+
call assert_equal('link', getftype('Xlink'))
135+
call delete('Xlink')
136+
137+
if executable('mkfifo')
138+
silent !mkfifo Xfifo
139+
call assert_equal('fifo', getftype('Xfifo'))
140+
call delete('Xfifo')
141+
endif
142+
143+
for cdevfile in systemlist('find /dev -type c -maxdepth 2 2>/dev/null')
144+
call assert_equal('cdev', getftype(cdevfile))
145+
endfor
146+
147+
for bdevfile in systemlist('find /dev -type b -maxdepth 2 2>/dev/null')
148+
call assert_equal('bdev', getftype(bdevfile))
149+
endfor
150+
151+
" The /run/ directory typically contains socket files.
152+
" If it does not, test won't fail but will not test socket files.
153+
for socketfile in systemlist('find /run -type s -maxdepth 2 2>/dev/null')
154+
call assert_equal('socket', getftype(socketfile))
155+
endfor
156+
157+
" TODO: file type 'other' is not tested. How can we test it?
158+
endfunc
159+
125160
func Test_win32_symlink_dir()
126161
" On Windows, non-admin users cannot create symlinks.
127162
" So we use an existing symlink for this test.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *(features[]) =
794794

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
262,
797799
/**/
798800
261,
799801
/**/

0 commit comments

Comments
 (0)