Skip to content

Commit

Permalink
Make Clojure testing tools configurable #188
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Mar 29, 2021
1 parent fd01b01 commit 66b8a1b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 16 deletions.
29 changes: 29 additions & 0 deletions doc/conjure-client-clojure-nrepl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,35 @@ All configuration can be set as described in |conjure-configuration|.
current root form is a test that should be ran.
Default: `["deftest"]`

`g:conjure#client#clojure#nrepl#test#runner_namespace`
Namespace used for test running. Prefixes the test runner function
names and will be required when you perform testing actions
through Conjure.
Default: `"clojure.test"`

`g:conjure#client#clojure#nrepl#test#all_fn`
Function to call when executing all tests. This function will come
from the `runner_namespace`.
Default: `"run-all-tests"`

`g:conjure#client#clojure#nrepl#test#ns_fn`
Function to call when executing all tests in a namespace. This
function will come from the `runner_namespace`.
Default: `"run-tests"`

`g:conjure#client#clojure#nrepl#test#var_fn`
Function to call when executing a specific test. This function
will come from the `runner_namespace`.
Default: `"test-vars"`

`g:conjure#client#clojure#nrepl#test#var_prefix`
String that comes before the var symbol when testing a single var.
Default: `"["`

`g:conjure#client#clojure#nrepl#test#var_suffix`
String that comes after the var symbol when testing a single var.
Default: `"]"`

`g:conjure#client#clojure#nrepl#mapping#disconnect`
Disconnect from the current nREPL server.
Default: `cd`
Expand Down
32 changes: 24 additions & 8 deletions fnl/conjure/client/clojure/nrepl/action.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,26 @@
(server.assume-session (a.get sessions n))
(log.append ["; Invalid session number."])))))))))))

(defn- require-test-runner []
(require-ns (cfg [:test :runner_namespace])))

(defn- test-runner-code [fn-config-name ...]
(..
"("
(str.join
" "
[(.. (cfg [:test :runner_namespace]) "/"
(cfg [:test (.. fn-config-name "_fn")]))
...])
")"))

(defn run-all-tests []
(try-ensure-conn
(fn []
(log.append ["; run-all-tests"] {:break? true})
(require-ns "clojure.test")
(require-test-runner)
(server.eval
{:code "(clojure.test/run-all-tests)"}
{:code (test-runner-code :all)}
#(ui.display-result
$1
{:simple-out? true
Expand All @@ -385,9 +398,9 @@
(when ns
(log.append [(.. "; run-ns-tests: " ns)]
{:break? true})
(require-ns "clojure.test")
(require-test-runner)
(server.eval
{:code (.. "(clojure.test/run-tests '" ns ")")}
{:code (test-runner-code :ns (.. "'" ns))}
#(ui.display-result
$1
{:simple-out? true
Expand Down Expand Up @@ -428,11 +441,14 @@
(when test-name
(log.append [(.. "; run-current-test: " test-name)]
{:break? true})
(require-ns "clojure.test")
(require-test-runner)
(server.eval
{:code (.. "(clojure.test/test-vars"
" [(doto (resolve '" test-name ")"
" (assert \"" test-name " is not a var\"))])")
{:code (test-runner-code
:var
(.. (cfg [:test :var_prefix])
"#'"
test-name
(cfg [:test :var_suffix])))
:context (extract.context)}
(nrepl.with-all-msgs-fn
(fn [msgs]
Expand Down
8 changes: 7 additions & 1 deletion fnl/conjure/client/clojure/nrepl/init.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@
:dirs nil}

:test
{:current_form_names ["deftest"]}
{:current_form_names ["deftest"]
:runner_namespace "clojure.test"
:all_fn "run-all-tests"
:ns_fn "run-tests"
:var_fn "test-vars"
:var_prefix "["
:var_suffix "]"}

:mapping
{:disconnect "cd"
Expand Down
34 changes: 28 additions & 6 deletions lua/conjure/client/clojure/nrepl/action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,28 @@ do
t_0_["select-session-interactive"] = v_0_
select_session_interactive = v_0_
end
local require_test_runner = nil
do
local v_0_ = nil
local function require_test_runner0()
return require_ns(cfg({"test", "runner_namespace"}))
end
v_0_ = require_test_runner0
local t_0_ = (_0_0)["aniseed/locals"]
t_0_["require-test-runner"] = v_0_
require_test_runner = v_0_
end
local test_runner_code = nil
do
local v_0_ = nil
local function test_runner_code0(fn_config_name, ...)
return ("(" .. str.join(" ", {(cfg({"test", "runner_namespace"}) .. "/" .. cfg({"test", (fn_config_name .. "_fn")})), ...}) .. ")")
end
v_0_ = test_runner_code0
local t_0_ = (_0_0)["aniseed/locals"]
t_0_["test-runner-code"] = v_0_
test_runner_code = v_0_
end
local run_all_tests = nil
do
local v_0_ = nil
Expand All @@ -797,11 +819,11 @@ do
local function run_all_tests0()
local function _2_()
log.append({"; run-all-tests"}, {["break?"] = true})
require_ns("clojure.test")
require_test_runner()
local function _3_(_241)
return ui["display-result"](_241, {["ignore-nil?"] = true, ["simple-out?"] = true})
end
return server.eval({code = "(clojure.test/run-all-tests)"}, _3_)
return server.eval({code = test_runner_code("all")}, _3_)
end
return try_ensure_conn(_2_)
end
Expand All @@ -820,11 +842,11 @@ do
local function _2_()
if ns then
log.append({("; run-ns-tests: " .. ns)}, {["break?"] = true})
require_ns("clojure.test")
require_test_runner()
local function _3_(_241)
return ui["display-result"](_241, {["ignore-nil?"] = true, ["simple-out?"] = true})
end
return server.eval({code = ("(clojure.test/run-tests '" .. ns .. ")")}, _3_)
return server.eval({code = test_runner_code("ns", ("'" .. ns))}, _3_)
end
end
return try_ensure_conn(_2_)
Expand Down Expand Up @@ -914,7 +936,7 @@ do
local test_name = extract_test_name_from_form(form.content)
if test_name then
log.append({("; run-current-test: " .. test_name)}, {["break?"] = true})
require_ns("clojure.test")
require_test_runner()
local function _3_(msgs)
if ((2 == a.count(msgs)) and ("nil" == a.get(a.first(msgs), "value"))) then
return log.append({"; Success!"})
Expand All @@ -925,7 +947,7 @@ do
return a["run!"](_4_, msgs)
end
end
return server.eval({code = ("(clojure.test/test-vars" .. " [(doto (resolve '" .. test_name .. ")" .. " (assert \"" .. test_name .. " is not a var\"))])"), context = extract.context()}, nrepl["with-all-msgs-fn"](_3_))
return server.eval({code = test_runner_code("var", (cfg({"test", "var_prefix"}) .. "#'" .. test_name .. cfg({"test", "var_suffix"}))), context = extract.context()}, nrepl["with-all-msgs-fn"](_3_))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/conjure/client/clojure/nrepl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ do
t_0_["cfg"] = v_0_
cfg = v_0_
end
config.merge({client = {clojure = {nrepl = {completion = {cljs = {use_suitable = true}, with_context = false}, connection = {default_host = "localhost", port_files = {".nrepl-port", ".shadow-cljs/nrepl.port"}}, eval = {auto_require = true, pretty_print = true, print_function = "conjure.internal/pprint", print_options = {length = 500, level = 50}, print_quota = nil}, interrupt = {sample_limit = 0.3}, mapping = {connect_port_file = "cf", disconnect = "cd", interrupt = "ei", last_exception = "ve", refresh_all = "ra", refresh_changed = "rr", refresh_clear = "rc", result_1 = "v1", result_2 = "v2", result_3 = "v3", run_all_tests = "ta", run_alternate_ns_tests = "tN", run_current_ns_tests = "tn", run_current_test = "tc", session_clone = "sc", session_close = "sq", session_close_all = "sQ", session_fresh = "sf", session_list = "sl", session_next = "sn", session_prev = "sp", session_select = "ss", view_source = "vs"}, refresh = {after = nil, before = nil, dirs = nil}, test = {current_form_names = {"deftest"}}}}}})
config.merge({client = {clojure = {nrepl = {completion = {cljs = {use_suitable = true}, with_context = false}, connection = {default_host = "localhost", port_files = {".nrepl-port", ".shadow-cljs/nrepl.port"}}, eval = {auto_require = true, pretty_print = true, print_function = "conjure.internal/pprint", print_options = {length = 500, level = 50}, print_quota = nil}, interrupt = {sample_limit = 0.3}, mapping = {connect_port_file = "cf", disconnect = "cd", interrupt = "ei", last_exception = "ve", refresh_all = "ra", refresh_changed = "rr", refresh_clear = "rc", result_1 = "v1", result_2 = "v2", result_3 = "v3", run_all_tests = "ta", run_alternate_ns_tests = "tN", run_current_ns_tests = "tn", run_current_test = "tc", session_clone = "sc", session_close = "sq", session_close_all = "sQ", session_fresh = "sf", session_list = "sl", session_next = "sn", session_prev = "sp", session_select = "ss", view_source = "vs"}, refresh = {after = nil, before = nil, dirs = nil}, test = {all_fn = "run-all-tests", current_form_names = {"deftest"}, ns_fn = "run-tests", runner_namespace = "clojure.test", var_fn = "test-vars", var_prefix = "[", var_suffix = "]"}}}}})
local context = nil
do
local v_0_ = nil
Expand Down

0 comments on commit 66b8a1b

Please sign in to comment.