From 459904381bc7dcb295b48fd7bcfa23a134293eca Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 25 Jun 2015 15:34:45 -0400 Subject: [PATCH] Use :.RunTests to run test under cursor Closes #223. --- doc/fireplace.txt | 9 +++++++-- plugin/fireplace.vim | 30 ++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/doc/fireplace.txt b/doc/fireplace.txt index 67fd95f..c941b15 100644 --- a/doc/fireplace.txt +++ b/doc/fireplace.txt @@ -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}. diff --git a/plugin/fireplace.vim b/plugin/fireplace.vim index 6364460..eb70e70 100644 --- a/plugin/fireplace.vim +++ b/plugin/fireplace.vim @@ -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