diff --git a/README.md b/README.md index 975b3a5e..235acafd 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ * `(doc ...)` lookup. * [Omnicomplete](#omnicomplete) through [Compliment][]. * Go to definition (will work more consistently when [#18](https://github.com/Olical/conjure/issues/18) is done). + * Running tests in the current namespace. ### Upcoming @@ -20,7 +21,6 @@ * Changed namespace reloading via `tools.namespace`. ([#10](https://github.com/Olical/conjure/issues/10)) * Configuration. ([#7](https://github.com/Olical/conjure/issues/7)) * Polished documentation and README. ([#6](https://github.com/Olical/conjure/issues/6)) - * Running tests with a keybinding. ([#20](https://github.com/Olical/conjure/issues/20)) [![asciicast](https://asciinema.org/a/RjojeOrKcF5zczweI7q3qiMgw.svg)](https://asciinema.org/a/RjojeOrKcF5zczweI7q3qiMgw) @@ -53,6 +53,8 @@ You can disable these and define your own with `let g:conjure_default_mappings = * `rs` - `ConjureStatus` * `rl` - `ConjureOpenLog` * `rq` - `ConjureCloseLog` + * `rt` - `ConjureRunTests` + * `rT` - `ConjureRunAllTests` * `K` - `ConjureDoc` * `gd` - `ConjureDefinition` @@ -72,6 +74,8 @@ You can disable these and define your own with `let g:conjure_default_mappings = * `ConjureDefinition` - go to the source of the given symbol, providing we can find it - falls back to vanilla `gd`. * `ConjureOpenLog` - open and focus the log buffer in a wide window. * `ConjureCloseLog` - close the log window if it's open in this tab. + * `ConjureRunTests` - run tests in the current namespace. + * `ConjureRunAllTests` - run all tests. `ConjureAdd` takes a map that conforms to the following spec. diff --git a/autoload/conjure.vim b/autoload/conjure.vim index 426ad53b..b30cf0d4 100644 --- a/autoload/conjure.vim +++ b/autoload/conjure.vim @@ -24,6 +24,8 @@ command! -nargs=1 ConjureDefinition call rpcnotify(s:jobid, "definition", ) command! -nargs=0 ConjureOpenLog call rpcnotify(s:jobid, "open_log") command! -nargs=0 ConjureCloseLog call rpcnotify(s:jobid, "close_log") +command! -nargs=0 ConjureRunTests call rpcnotify(s:jobid, "run_tests") +command! -nargs=0 ConjureRunAllTests call rpcnotify(s:jobid, "run_all_tests") " Default mappings if not disabled. if !exists("g:conjure_default_mappings") || g:conjure_default_mappings @@ -38,6 +40,8 @@ if !exists("g:conjure_default_mappings") || g:conjure_default_mappings autocmd FileType clojure nnoremap rs :ConjureStatus autocmd FileType clojure nnoremap rl :ConjureOpenLog autocmd FileType clojure nnoremap rq :ConjureCloseLog + autocmd FileType clojure nnoremap rt :ConjureRunTests + autocmd FileType clojure nnoremap rT :ConjureRunAllTests autocmd FileType clojure nnoremap K :ConjureDoc autocmd FileType clojure nnoremap gd :ConjureDefinition autocmd FileType clojure setlocal omnifunc=conjure#omnicomplete diff --git a/src/conjure/action.clj b/src/conjure/action.clj index d27d67e1..73ea5a3f 100644 --- a/src/conjure/action.clj +++ b/src/conjure/action.clj @@ -227,3 +227,9 @@ [(nvim/command-output (str "edit " file)) (nvim/win-set-cursor (:win ctx) {:row row, :col col})]) (nvim/call (nvim/command-output "normal! gd"))))) + +(defn run-tests [] + (eval* (code/run-tests-str))) + +(defn run-all-tests [] + (eval* (code/run-all-tests-str))) diff --git a/src/conjure/code.clj b/src/conjure/code.clj index cb986f93..becefda2 100644 --- a/src/conjure/code.clj +++ b/src/conjure/code.clj @@ -31,9 +31,11 @@ :clj "(do (require 'clojure.repl 'clojure.string - 'clojure.java.io) + 'clojure.java.io + 'clojure.test) (try (require 'compliment.core) (catch Exception _)))" - :cljs "(require 'cljs.repl)")) + :cljs "(require 'cljs.repl + 'clojure.test)")) ;; The read-string/eval wrapper can go away with Clojure 1.11. ;; https://dev.clojure.org/jira/browse/CLJ-2453 @@ -111,3 +113,9 @@ (clojure.string/replace #\"\\.jar!/\" \".jar::\")))))) (update 2 dec)))) ")) + +(defn run-tests-str [] + "(clojure.test/run-tests)") + +(defn run-all-tests-str [] + "(clojure.test/run-all-tests)") diff --git a/src/conjure/main.clj b/src/conjure/main.clj index 94263606..5e7c712a 100644 --- a/src/conjure/main.clj +++ b/src/conjure/main.clj @@ -78,3 +78,9 @@ (defmethod rpc/handle-notify :definition [{:keys [params]}] (action/definition (first params))) + +(defmethod rpc/handle-notify :run-tests [_] + (action/run-tests)) + +(defmethod rpc/handle-notify :run-all-tests [_] + (action/run-all-tests)) diff --git a/test/example.cljc b/test/example.cljc index cf1af796..d5324863 100644 --- a/test/example.cljc +++ b/test/example.cljc @@ -1,6 +1,7 @@ ;; Some example code to test Conjure with. -(ns test.example) +(ns test.example + (:require [clojure.test :as t])) (defn henlo [name] (println (str "Henlo, " name "!")) @@ -15,3 +16,7 @@ (comment (this-will-error)) + +(t/deftest something-simple + (t/testing "hmm" + (t/is (= 10 10))))