diff --git a/README.markdown b/README.markdown index b37bffc..0fe3d7a 100644 --- a/README.markdown +++ b/README.markdown @@ -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 file), `:Require` requires a namespace with `:reload` (`:Require!` does -`:reload-all`), either the current buffer or a given argument. 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. +`:reload-all`), either the current buffer or a given argument. `:RunTests` +kicks off `(clojure.test/run-tests)` and loads the results into the quickfix +list. + +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 can be easily accessed with `:lopen`. diff --git a/doc/fireplace.txt b/doc/fireplace.txt index e7f4e60..720fc03 100644 --- a/doc/fireplace.txt +++ b/doc/fireplace.txt @@ -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 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* cp{motion} Eval/print the code indicated by {motion}. diff --git a/plugin/fireplace.vim b/plugin/fireplace.vim index 8693638..15e4446 100644 --- a/plugin/fireplace.vim +++ b/plugin/fireplace.vim @@ -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', ) 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(0, ) +augroup END + " }}}1 " Alternate {{{1