Use :.RunTests to run test under cursor

Closes #223.
This commit is contained in:
Tim Pope 2015-06-25 15:34:45 -04:00
parent 69bf9ef519
commit 459904381b
2 changed files with 33 additions and 6 deletions

View File

@ -123,8 +123,13 @@ stack trace is loaded into the |location-list|. Use |:lopen| to view it.
:RunTests [ns] [...] Call clojure.test/run-tests on the given namespaces
and load the results into the quickfix list.
:RunAllTests [pattern] Call clojure.test/run-all-tests with the given pattern
:0RunTests [pattern] and load the results into the quickfix list.
:[range]RunTests Call clojure.test/test-var on the var defined at or
above the specicied line and load the results into the
quickfix list. Typically invoked as :.RunTests to run
the test under the cursor.
:0RunTests [pattern] Call clojure.test/run-all-tests with the given pattern
and load the results into the quickfix list.
*fireplace-cp*
cp{motion} Eval/print the code indicated by {motion}.

View File

@ -1596,11 +1596,33 @@ function! s:RunTests(bang, count, ...) abort
let expr = '(clojure.test/run-all-tests)'
endif
else
let reqs = map(copy(a:000), '"''".v:val')
let pre = '(clojure.core/require '.join(empty(a:000) ? ["'".fireplace#ns()] : reqs, ' ').' :reload) '
let expr = join(['(clojure.test/run-tests'] + reqs, ' ').')'
if a:0 && a:000 !=# [fireplace#ns()]
let args = a:000
else
let args = [fireplace#ns()]
if a:count
let pattern = '^\s*(def\k*\s\+\zs\h\k*'
let line = search(pattern, 'bWn')
if line
let args[0] .= '/' . matchstr(getline(line), pattern)
endif
endif
endif
let reqs = map(copy(args), '"''".v:val')
let pre = '(clojure.core/require '.substitute(join(reqs, ' '), '/\k\+', '', 'g').' :reload) '
let expr = []
let vars = filter(copy(reqs), 'v:val =~# "/"')
let nses = filter(copy(reqs), 'v:val !~# "/"')
if len(vars) == 1
call add(expr, '(clojure.test/test-var #' . vars[0] . ')')
elseif !empty(vars)
call add(expr, join(['(clojure.test/test-vars'] + map(vars, '"#".v:val'), ' ').')')
endif
if !empty(nses)
call add(expr, join(['(clojure.test/run-tests'] + nses, ' ').')')
endif
endif
call fireplace#capture_test_run(expr, pre)
call fireplace#capture_test_run(join(expr, ' '), pre)
echo expr
endfunction