diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_prv_eunit.erl | 32 | ||||
-rw-r--r-- | src/rebar_prv_packages.erl | 4 |
2 files changed, 29 insertions, 7 deletions
diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index f120926..0b00e89 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -105,6 +105,8 @@ format_error({eunit_test_errors, Errors}) -> lists:map(fun(Error) -> "~n " ++ Error end, Errors)), []); format_error({badconfig, {Msg, {Value, Key}}}) -> io_lib:format(Msg, [Value, Key]); +format_error({generator, Value}) -> + io_lib:format("Generator ~p has an invalid format", [Value]); format_error({error, Error}) -> format_error({error_running_tests, Error}). @@ -134,19 +136,34 @@ resolve_tests(State) -> Files = resolve(file, RawOpts), Modules = resolve(module, RawOpts), Suites = resolve(suite, module, RawOpts), - Apps ++ Applications ++ Dirs ++ Files ++ Modules ++ Suites. + Generator = resolve(generator, RawOpts), + Apps ++ Applications ++ Dirs ++ Files ++ Modules ++ Suites ++ Generator. resolve(Flag, RawOpts) -> resolve(Flag, Flag, RawOpts). resolve(Flag, EUnitKey, RawOpts) -> case proplists:get_value(Flag, RawOpts) of undefined -> []; - Args -> lists:map(fun(Arg) -> normalize(EUnitKey, Arg) end, + Args -> normalize(EUnitKey, rebar_string:lexemes(Args, [$,])) end. -normalize(Key, Value) when Key == dir; Key == file -> {Key, Value}; -normalize(Key, Value) -> {Key, list_to_atom(Value)}. +normalize(generator, Args) -> + lists:flatmap(fun(Value) -> normalize_(generator, Value) end, Args); +normalize(EUnitKey, Args) -> + lists:map(fun(Arg) -> normalize_(EUnitKey, Arg) end, Args). + +normalize_(generator, Value) -> + case string:tokens(Value, [$:]) of + [Module0, Functions] -> + Module = list_to_atom(Module0), + lists:map(fun(F) -> {generator, Module, list_to_atom(F)} end, + string:tokens(Functions, [$;])); + _ -> + ?PRV_ERROR({generator, Value}) + end; +normalize_(Key, Value) when Key == dir; Key == file -> {Key, Value}; +normalize_(Key, Value) -> {Key, list_to_atom(Value)}. cfg_tests(State) -> case rebar_state:get(State, eunit_tests, []) of @@ -353,6 +370,8 @@ validate(State, {module, Module}) -> validate_module(State, Module); validate(State, {suite, Module}) -> validate_module(State, Module); +validate(State, {generator, Module, Function}) -> + validate_generator(State, Module, Function); validate(State, Module) when is_atom(Module) -> validate_module(State, Module); validate(State, Path) when is_list(Path) -> @@ -395,6 +414,9 @@ validate_module(_State, Module) -> _ -> ok end. +validate_generator(State, Module, _Function) -> + validate_module(State, Module). + resolve_eunit_opts(State) -> {Opts, _} = rebar_state:command_parsed_args(State), EUnitOpts = rebar_state:get(State, eunit_opts, []), @@ -490,6 +512,7 @@ eunit_opts(_State) -> {file, $f, "file", string, help(file)}, {module, $m, "module", string, help(module)}, {suite, $s, "suite", string, help(module)}, + {generator, $g, "generator", string, help(generator)}, {verbose, $v, "verbose", boolean, help(verbose)}, {name, undefined, "name", atom, help(name)}, {sname, undefined, "sname", atom, help(sname)}, @@ -501,6 +524,7 @@ help(cover_export_name) -> "Base name of the coverdata file to write"; help(dir) -> "Comma separated list of dirs to load tests from. Equivalent to `[{dir, Dir}]`."; help(file) -> "Comma separated list of files to load tests from. Equivalent to `[{file, File}]`."; help(module) -> "Comma separated list of modules to load tests from. Equivalent to `[{module, Module}]`."; +help(generator) -> "Comma separated list of generators (the format is `module:function`) to load tests from. Equivalent to `[{generator, Module, Function}]`."; help(verbose) -> "Verbose output. Defaults to false."; help(name) -> "Gives a long name to the node"; help(sname) -> "Gives a short name to the node"; diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl index 3e54cdc..a143455 100644 --- a/src/rebar_prv_packages.erl +++ b/src/rebar_prv_packages.erl @@ -72,16 +72,14 @@ print_packages({RepoName, {ok, #{<<"name">> := Name, Description = maps:get(<<"description">>, Meta, ""), Licenses = join(maps:get(<<"licenses">>, Meta, []), <<", ">>), Links = join_map(maps:get(<<"links">>, Meta, []), <<"\n ">>), - Maintainers = join(maps:get(<<"maintainers">>, Meta, []), <<", ">>), Versions = [V || #{<<"version">> := V} <- Releases], VsnStr = join(Versions, <<", ">>), ?CONSOLE("~ts:~n" " Name: ~ts~n" " Description: ~ts~n" " Licenses: ~ts~n" - " Maintainers: ~ts~n" " Links:~n ~ts~n" - " Versions: ~ts~n", [RepoName, Name, Description, Licenses, Maintainers, Links, VsnStr]); + " Versions: ~ts~n", [RepoName, Name, Description, Licenses, Links, VsnStr]); print_packages(_) -> ok. |