summaryrefslogtreecommitdiffstats
path: root/autoload/rust.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2018-12-26 10:41:57 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2018-12-26 10:41:57 +0100
commitd43b70d93987c94d15a352cf0026fb93d3317cc8 (patch)
tree74470b6cc30ddb4ef8ceb2ec557bc32ccccb5ebb /autoload/rust.vim
parentec1c94306953b678bb36572897bd218fe6c76506 (diff)
downloadvim-polyglot-d43b70d93987c94d15a352cf0026fb93d3317cc8.tar.gz
vim-polyglot-d43b70d93987c94d15a352cf0026fb93d3317cc8.zip
Update
Diffstat (limited to 'autoload/rust.vim')
-rw-r--r--autoload/rust.vim39
1 files changed, 31 insertions, 8 deletions
diff --git a/autoload/rust.vim b/autoload/rust.vim
index 77c38b7c..81f8c635 100644
--- a/autoload/rust.vim
+++ b/autoload/rust.vim
@@ -445,12 +445,12 @@ function! s:SearchTestFunctionNameUnderCursor() abort
let cursor_line = line('.')
" Find #[test] attribute
- if search('#\[test]', 'bcW') is 0
+ if search('\m\C#\[test\]', 'bcW') is 0
return ''
endif
" Move to an opening brace of the test function
- let test_func_line = search('^\s*fn\s\+\h\w*\s*(.\+{$', 'eW')
+ let test_func_line = search('\m\C^\s*fn\s\+\h\w*\s*(.\+{$', 'eW')
if test_func_line is 0
return ''
endif
@@ -462,19 +462,36 @@ function! s:SearchTestFunctionNameUnderCursor() abort
return ''
endif
- return matchstr(getline(test_func_line), '^\s*fn\s\+\zs\h\w*')
+ return matchstr(getline(test_func_line), '\m\C^\s*fn\s\+\zs\h\w*')
endfunction
function! rust#Test(all, options) abort
- let pwd = expand('%:p:h')
- if findfile('Cargo.toml', pwd . ';') ==# ''
+ let manifest = findfile('Cargo.toml', expand('%:p:h') . ';')
+ if manifest ==# ''
return rust#Run(1, '--test ' . a:options)
endif
- let pwd = shellescape(pwd)
+ if exists(':terminal')
+ let cmd = 'terminal '
+ else
+ let cmd = '!'
+ let manifest = shellescape(manifest)
+ endif
if a:all
- execute '!cd ' . pwd . ' && cargo test ' . a:options
+ if a:options ==# ''
+ execute cmd . 'cargo test --manifest-path' manifest
+ else
+ execute cmd . 'cargo test --manifest-path' manifest a:options
+ endif
+ return
+ endif
+
+ let mod_name = expand('%:t:r')
+ if mod_name ==# ''
+ echohl ErrorMsg
+ echo 'Cannot extract a module name from file name. Please add ! to command if you want to run all tests'
+ echohl None
return
endif
@@ -487,7 +504,13 @@ function! rust#Test(all, options) abort
echohl None
return
endif
- execute '!cd ' . pwd . ' && cargo test ' . func_name . ' ' . a:options
+ let spec = mod_name . '::' . func_name
+ if a:options ==# ''
+ execute cmd . 'cargo test --manifest-path' manifest spec
+ else
+ execute cmd . 'cargo test --manifest-path' manifest spec a:options
+ endif
+ return
finally
call setpos('.', saved)
endtry