summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_prv_common_test.erl8
-rw-r--r--test/rebar_ct_SUITE.erl47
2 files changed, 52 insertions, 3 deletions
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 30596da..2ac8fc7 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -100,7 +100,9 @@ format_error({badconfig, Msg}) ->
io_lib:format(Msg, []);
format_error({multiple_errors, Errors}) ->
io_lib:format(lists:concat(["Error running tests:"] ++
- lists:map(fun(Error) -> "~n " ++ Error end, Errors)), []).
+ lists:map(fun(Error) -> "~n " ++ Error end, Errors)), []);
+format_error({error_reading_testspec, Reason}) ->
+ io_lib:format("Error reading testspec: ~p", [Reason]).
%% ===================================================================
%% Internal functions
@@ -549,8 +551,8 @@ get_dirs_from_specs(Specs) ->
RunList = lists:append([R || {_,R,_} <- NodeRunSkipList]),
DirList = [element(1,R) || R <- RunList],
{ok,{SpecList,DirList}};
- Error ->
- Error
+ {error,Reason} ->
+ {error,{?MODULE,{error_reading_testspec,Reason}}}
end.
get_tests_from_specs(Specs) ->
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 91324d2..06dc76e 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -54,6 +54,7 @@
misspecified_ct_first_files/1,
testspec/1,
testspec_at_root/1,
+ testspec_parse_error/1,
cmd_vs_cfg_opts/1]).
-include_lib("eunit/include/eunit.hrl").
@@ -73,6 +74,7 @@ all() -> [{group, basic_app},
misspecified_ct_first_files,
testspec,
testspec_at_root,
+ testspec_parse_error,
cmd_vs_cfg_opts].
groups() -> [{basic_app, [], [basic_app_default_dirs,
@@ -1452,6 +1454,51 @@ testspec_at_root(Config) ->
ok.
+testspec_parse_error(Config) ->
+ C = rebar_test_utils:init_rebar_state(Config, "ct_testspec_error"),
+
+ AppDir = ?config(apps, C),
+
+ Name = rebar_test_utils:create_random_name("ct_testspec_error"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ Spec1 = filename:join([AppDir, "test", "nonexisting.spec"]),
+ Spec2 = filename:join([AppDir, "test", "some.spec"]),
+ ok = filelib:ensure_dir(Spec2),
+ ok = file:write_file(Spec2, ".\n"),
+
+ {ok, State} = rebar_test_utils:run_and_check(C,
+ [],
+ ["as", "test", "lock"],
+ return),
+
+ Providers = rebar_state:providers(State),
+ Namespace = rebar_state:namespace(State),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+
+ %% Non existing testspec
+ {ok, GetOptResult1} = getopt:parse(GetOptSpec, ["--spec",Spec1]),
+ State1 = rebar_state:command_parsed_args(State, GetOptResult1),
+ Tests1 = rebar_prv_common_test:prepare_tests(State1),
+ {error,
+ {rebar_prv_common_test,
+ {error_reading_testspec,
+ {Spec1,"no such file or directory"}}}} =
+ rebar_prv_common_test:compile(State1, Tests1),
+
+ %% Syntax error
+ {ok, GetOptResult2} = getopt:parse(GetOptSpec, ["--spec",Spec2]),
+ State2 = rebar_state:command_parsed_args(State, GetOptResult2),
+ Tests2 = rebar_prv_common_test:prepare_tests(State2),
+ {error,
+ {rebar_prv_common_test,
+ {error_reading_testspec,
+ {Spec2,"1: syntax error before: '.'"}}}} =
+ rebar_prv_common_test:compile(State2, Tests2),
+
+ ok.
+
cmd_vs_cfg_opts(Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_cmd_vs_cfg_opts_"),