Skip to content

Commit

Permalink
Add simple test bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Apr 10, 2019
1 parent 85a34f7 commit 6c3416a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -53,6 +53,8 @@ You can disable these and define your own with `let g:conjure_default_mappings =
* `<localleader>rs` - `ConjureStatus`
* `<localleader>rl` - `ConjureOpenLog`
* `<localleader>rq` - `ConjureCloseLog`
* `<localleader>rt` - `ConjureRunTests`
* `<localleader>rT` - `ConjureRunAllTests`
* `K` - `ConjureDoc`
* `gd` - `ConjureDefinition`

Expand All @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions autoload/conjure.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ command! -nargs=1 ConjureDefinition call rpcnotify(s:jobid, "definition", <q-arg
command! -nargs=1 ConjureDoc call rpcnotify(s:jobid, "doc", <q-args>)
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
Expand All @@ -38,6 +40,8 @@ if !exists("g:conjure_default_mappings") || g:conjure_default_mappings
autocmd FileType clojure nnoremap <buffer> <localleader>rs :ConjureStatus<cr>
autocmd FileType clojure nnoremap <buffer> <localleader>rl :ConjureOpenLog<cr>
autocmd FileType clojure nnoremap <buffer> <localleader>rq :ConjureCloseLog<cr>
autocmd FileType clojure nnoremap <buffer> <localleader>rt :ConjureRunTests<cr>
autocmd FileType clojure nnoremap <buffer> <localleader>rT :ConjureRunAllTests<cr>
autocmd FileType clojure nnoremap <buffer> K :ConjureDoc <c-r><c-w><cr>
autocmd FileType clojure nnoremap <buffer> gd :ConjureDefinition <c-r><c-w><cr>
autocmd FileType clojure setlocal omnifunc=conjure#omnicomplete
Expand Down
6 changes: 6 additions & 0 deletions src/conjure/action.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
12 changes: 10 additions & 2 deletions src/conjure/code.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)")
6 changes: 6 additions & 0 deletions src/conjure/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))
7 changes: 6 additions & 1 deletion test/example.cljc
Original file line number Diff line number Diff line change
@@ -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 "!"))
Expand All @@ -15,3 +16,7 @@

(comment
(this-will-error))

(t/deftest something-simple
(t/testing "hmm"
(t/is (= 10 10))))

0 comments on commit 6c3416a

Please sign in to comment.