"=====[ Run a Perl module's test suite ]========================= let g:PerlTests_program = 'perltests' " ...What to call let g:PerlTests_search_height = 5 " ...How far up to search let g:PerlTests_test_dir = '/t' " ...Where to look for tests augroup Perl_Tests autocmd! autocmd BufEnter *.p[lm] nmap ;t :call RunPerlTests() autocmd BufEnter *.t nmap ;t :call RunPerlTests() augroup END function! RunPerlTests () " Start in the current directory... let dir = expand('%:h') " Walk up through parent directories, looking for a test directory... for n in range(g:PerlTests_search_height) " When found... if isdirectory(dir . g:PerlTests_test_dir) " Go there... silent exec 'cd ' . dir " Run the tests... exec ':!' . g:PerlTests_program " Return to the previous directory... silent cd - return endif " Otherwise, keep looking up the directory tree... let dir = dir . '/..' endfor " If not found, report the failure... echohl WarningMsg echomsg "Couldn't find a suitable" g:PerlTests_test_dir '(tried' g:PerlTests_search_height 'levels up)' echohl None endfunction