Provide :RunTests

:RunTests! currently calls (run-all-tests), but if we find a more useful
semantic for ! that might change.

Closes #59.
This commit is contained in:
Tim Pope 2014-04-03 23:54:20 -04:00
parent 73f9a3adf4
commit 092ab0f70e
3 changed files with 77 additions and 5 deletions

View File

@ -68,11 +68,14 @@ cursor. `cqc` gives you a blank line in insert mode.
Standard stuff here. `:Eval` evaluates a range (`:%Eval` gets the whole Standard stuff here. `:Eval` evaluates a range (`:%Eval` gets the whole
file), `:Require` requires a namespace with `:reload` (`:Require!` does file), `:Require` requires a namespace with `:reload` (`:Require!` does
`:reload-all`), either the current buffer or a given argument. There's a `cp` `:reload-all`), either the current buffer or a given argument. `:RunTests`
operator that evaluates a given motion (`cpp` for the outermost form under the kicks off `(clojure.test/run-tests)` and loads the results into the quickfix
cursor). `cm` and `c1m` are similar, but they only run list.
`clojure.walk/macroexpand-all` and `macroexpand-1` instead of evaluating the
form entirely. There's a `cp` operator that evaluates a given motion (`cpp` for the
outermost form under the cursor). `cm` and `c1m` are similar, but they only
run `clojure.walk/macroexpand-all` and `macroexpand-1` instead of evaluating
the form entirely.
Any failed evaluation loads the stack trace into the location list, which Any failed evaluation loads the stack trace into the location list, which
can be easily accessed with `:lopen`. can be easily accessed with `:lopen`.

View File

@ -140,6 +140,13 @@ stack trace is loaded into the |location-list|. Use |:lopen| to view it.
:[range]Eval! {expr} Eval the given expression and insert it after :[range]Eval! {expr} Eval the given expression and insert it after
the given range or current line. the given range or current line.
*fireplace-:RunTests*
:RunTests [ns] [...] Call clojure.test/run-tests on the given namespaces
and load the results into the quickfix list.
:RunTests! [pattern] Call clojure.test/run-all-tests with the given pattern
and load the results into the quickfix list.
*fireplace-cp* *fireplace-cp*
cp{motion} Eval/print the code indicated by {motion}. cp{motion} Eval/print the code indicated by {motion}.

View File

@ -1297,6 +1297,68 @@ augroup fireplace_doc
autocmd FileType clojure command! -buffer -bar -nargs=1 -complete=customlist,fireplace#eval_complete Source :exe s:Lookup('clojure.repl', 'source', <q-args>) autocmd FileType clojure command! -buffer -bar -nargs=1 -complete=customlist,fireplace#eval_complete Source :exe s:Lookup('clojure.repl', 'source', <q-args>)
augroup END augroup END
" }}}1
" Tests {{{1
function! fireplace#capture_test_run(expr) abort
let expr = '(require ''clojure.test) '
\ . '(binding [clojure.test/report (fn [m]'
\ . ' (case (:type m)'
\ . ' (:fail :error)'
\ . ' (let [{file :file test :name} (meta (last clojure.test/*testing-vars*))]'
\ . ' (clojure.test/with-test-out'
\ . ' (println (clojure.string/join "\t" [file (:line m) (name (:type m)) test]))'
\ . ' (when (seq clojure.test/*testing-contexts*) (println (clojure.test/testing-contexts-str)))'
\ . ' (when-let [message (:message m)] (println message))'
\ . ' (println "expected:" (pr-str (:expected m)))'
\ . ' (println " actual:" (pr-str (:actual m)))))'
\ . ' ((.getRawRoot #''clojure.test/report) m)))]'
\ . ' ' . a:expr . ')'
let qflist = []
let response = s:eval(expr, {'session': 0})
if !has_key(response, 'out')
return s:output_response(response)
endif
for line in split(response.out, "\n")
let entry = {'text': line}
if line =~# '\t.*\t.*\t'
let [resource, lnum, type, name] = split(line, "\t", 1)
let entry.lnum = lnum
let entry.type = (type ==# 'fail' ? 'W' : 'E')
let entry.text = name
if resource ==# 'NO_SOURCE_FILE'
let resource = ''
let entry.lnum = 0
endif
let entry.filename = fireplace#findresource(resource, fireplace#path())
if empty(entry.filename)
let entry.lnum = 0
endif
endif
call add(qflist, entry)
endfor
call setqflist(qflist)
cwindow
endfunction
function! s:RunTests(bang, ...) abort
if a:bang && a:0
let expr = '(clojure.test/run-all-tests #"'.join(a:000, '|').'")'
elseif a:bang
let expr = '(clojure.test/run-all-tests)'
else
let expr = '(' .join(['clojure.test/run-tests'] + map(copy(a:000), '"''".v:val'), ' ').')'
endif
call fireplace#capture_test_run(expr)
cwindow
echo expr
endfunction
augroup fireplace_command
autocmd!
autocmd FileType clojure command! -buffer -bar -bang -nargs=* -complete=customlist,fireplace#ns_complete RunTests call s:RunTests(<bang>0, <f-args>)
augroup END
" }}}1 " }}}1
" Alternate {{{1 " Alternate {{{1