Skip to content

Commit 4d6df30

Browse files
committed
[#12] Add option to run a specific test var
1 parent 51218d3 commit 4d6df30

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/rebar3_clojerl_prv_compile.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ compile_clje(Src, Config) ->
168168
catch
169169
_:Reason ->
170170
Stacktrace = erlang:get_stacktrace(),
171-
rebar_api:debug("Stacktrace:~n~s", [clj_utils:stacktrace(Stacktrace)]),
171+
rebar_api:debug( "Stacktrace:~n~s"
172+
, [clj_utils:format_stacktrace(Stacktrace)]
173+
),
172174
rebar_api:abort( "Error while compiling ~s: ~s"
173175
, [Src, clj_rt:str(Reason)]
174176
)

src/rebar3_clojerl_prv_test.erl

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
init(State) ->
1717
Opts = [ {sname, undefined, "sname", string, "Erlang node name."}
1818
, {ns, undefined, "ns", string, "Namespace to test."}
19+
, {var, undefined, "var", string, "Var to test."}
1920
],
2021
Provider = providers:create([ {namespace, ?NAMESPACE}
2122
, {name, ?PROVIDER}
@@ -44,7 +45,9 @@ do(State) ->
4445
[test(AppInfo, Opts) || AppInfo <- Apps]
4546
catch _:Reason ->
4647
Stacktrace = erlang:get_stacktrace(),
47-
rebar_api:debug("Stacktrace:~n~s", [clj_utils:stacktrace(Stacktrace)]),
48+
rebar_api:debug( "Stacktrace:~n~s"
49+
, [clj_utils:format_stacktrace(Stacktrace)]
50+
),
4851
rebar_api:abort( "Error while testing: ~s"
4952
, [clj_rt:str(Reason)]
5053
)
@@ -63,16 +66,33 @@ format_error(Reason) ->
6366
test(AppInfo, Opts) ->
6467
TestDirs = rebar_app_info:get(AppInfo, clje_test_dirs, ?DEFAULT_TEST_DIRS),
6568
ok = code:add_pathsa(TestDirs),
66-
NsSymbols = case proplists:get_value(ns, Opts, undefined) of
69+
NsOpt = proplists:get_value(ns, Opts, undefined),
70+
VarOpt = proplists:get_value(var, Opts, undefined),
71+
72+
NsSymbols = case NsOpt of
6773
undefined -> lists:flatmap(fun find_tests/1, TestDirs);
68-
NsStr -> [clj_rt:symbol(list_to_binary(NsStr ++ "-test"))]
74+
NsOpt -> [clj_rt:symbol(list_to_binary(NsOpt))]
75+
end,
76+
77+
%% TODO: maybe change this to a compilation of the file
78+
['clojure.core':require([NsSym]) || NsSym <- NsSymbols],
79+
80+
Var = case {NsOpt, VarOpt} of
81+
{undefined, _} -> undefined;
82+
{_, undefined} -> undefined;
83+
_ ->
84+
VarSymbol = clj_rt:symbol( list_to_binary(NsOpt)
85+
, list_to_binary(VarOpt)
86+
),
87+
'clojure.core':'find-var'(VarSymbol)
6988
end,
7089

7190
rebar_api:debug("Test namespaces: ~p", [clj_rt:str(NsSymbols)]),
7291

73-
%% TODO: change this to a compilation of the file
74-
['clojure.core':require([NsSym]) || NsSym <- NsSymbols],
75-
'clojure.test':'run-tests'(NsSymbols),
92+
case Var of
93+
undefined -> 'clojure.test':'run-tests'(NsSymbols);
94+
_ -> 'clojure.test':'test-var'(Var)
95+
end,
7696
ok.
7797

7898
-spec find_tests(file:name()) -> ['clojerl.Symbol':type()].

0 commit comments

Comments
 (0)