diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/rebar_eunit_SUITE.erl | 35 | ||||
-rw-r--r-- | test/rebar_pkg_SUITE.erl | 22 | ||||
-rw-r--r-- | test/rebar_pkg_alias_SUITE.erl | 14 | ||||
-rw-r--r-- | test/rebar_pkg_repos_SUITE.erl | 8 |
4 files changed, 57 insertions, 22 deletions
diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl index 1a8bade..87dd3ed 100644 --- a/test/rebar_eunit_SUITE.erl +++ b/test/rebar_eunit_SUITE.erl @@ -13,6 +13,7 @@ -export([single_application_arg/1, multi_application_arg/1, missing_application_arg/1]). -export([single_module_arg/1, multi_module_arg/1, missing_module_arg/1]). -export([single_suite_arg/1, multi_suite_arg/1, missing_suite_arg/1]). +-export([single_generator_arg/1, multi_generator_arg/1, missing_generator_arg/1]). -export([single_file_arg/1, multi_file_arg/1, missing_file_arg/1]). -export([single_dir_arg/1, multi_dir_arg/1, missing_dir_arg/1]). -export([multiple_arg_composition/1, multiple_arg_errors/1]). @@ -47,6 +48,7 @@ groups() -> single_application_arg, multi_application_arg, missing_application_arg, single_module_arg, multi_module_arg, missing_module_arg, single_suite_arg, multi_suite_arg, missing_suite_arg, + single_generator_arg, multi_generator_arg, missing_generator_arg, single_file_arg, multi_file_arg, missing_file_arg, single_dir_arg, multi_dir_arg, missing_dir_arg, multiple_arg_composition, multiple_arg_errors]}]. @@ -239,7 +241,7 @@ multi_app_testset(Config) -> Set = {ok, [{application, multi_app_baz}, {application, multi_app_bar}, {module, multi_app_bar_tests_helper}, - {module, multi_app_baz_tests_helper}, + {module, multi_app_baz_tests_helper}, {module, multi_app_tests}, {module, multi_app_tests_helper}]}, Set = rebar_prv_eunit:prepare_tests(Result). @@ -404,6 +406,37 @@ missing_suite_arg(Config) -> Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Module `missing_app' not found in project."]}}}, Error = rebar_prv_eunit:validate_tests(State, rebar_prv_eunit:prepare_tests(State)). +%% check that the --generator cmd line opt generates the correct test set +single_generator_arg(Config) -> + S = ?config(result, Config), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--generator=module_name:function_name"]), + State = rebar_state:command_parsed_args(S, Args), + + {ok, [{generator, module_name, function_name}]} = rebar_prv_eunit:prepare_tests(State). + +multi_generator_arg(Config) -> + S = ?config(result, Config), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--generator=module1:func1;func2,module2:func1;func2"]), + State = rebar_state:command_parsed_args(S, Args), + + Generators = [{generator, module1, func1}, + {generator, module1, func2}, + {generator, module2, func1}, + {generator, module2, func2}], + {ok, Generators} = rebar_prv_eunit:prepare_tests(State). + +%% check that an invalid --suite cmd line opt generates an error +missing_generator_arg(Config) -> + S = ?config(result, Config), + + {ok, Args} = getopt:parse(rebar_prv_eunit:eunit_opts(S), ["--generator=missing_module:func1"]), + State = rebar_state:command_parsed_args(S, Args), + + Error = {error, {rebar_prv_eunit, {eunit_test_errors, ["Module `missing_module' not found in project."]}}}, + Error = rebar_prv_eunit:validate_tests(State, rebar_prv_eunit:prepare_tests(State)). + %% check that the --file cmd line opt generates the correct test set single_file_arg(Config) -> S = ?config(result, Config), diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl index ee74af5..ad06abd 100644 --- a/test/rebar_pkg_SUITE.erl +++ b/test/rebar_pkg_SUITE.erl @@ -99,7 +99,7 @@ init_per_testcase(bad_disconnect=Name, Config0) -> Config = mock_config(Name, Config1), meck:expect(hex_repo, get_tarball, fun(_, _, _) -> {error, econnrefused} - end), + end), Config; init_per_testcase(Name, Config0) -> Config = [{good_cache, false}, @@ -252,7 +252,7 @@ mock_config(Name, Config) -> CacheRoot = filename:join([Priv, "cache", atom_to_list(Name)]), TmpDir = filename:join([Priv, "tmp", atom_to_list(Name)]), Tid = ets:new(registry_table, [public]), - AllDeps = [ + AllDeps = [ {{<<"badindexchk">>,<<"1.0.0">>}, [[], ?bad_checksum, [<<"rebar3">>]]}, {{<<"goodpkg">>,<<"1.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]}, {{<<"goodpkg">>,<<"1.0.1">>}, [[], ?good_checksum, [<<"rebar3">>]]}, @@ -267,7 +267,7 @@ mock_config(Name, Config) -> ok = ets:tab2file(Tid, filename:join([CacheDir, "registry"])), catch ets:delete(?PACKAGE_TABLE), - rebar_packages:new_package_table(), + rebar_packages:new_package_table(), lists:foreach(fun({{N, Vsn}, [Deps, Checksum, _]}) -> case ets:member(?PACKAGE_TABLE, {ec_cnv:to_binary(N), Vsn, <<"hexpm">>}) of false -> @@ -279,18 +279,18 @@ mock_config(Name, Config) -> ok end end, AllDeps), - + meck:new(hex_repo, [passthrough]), - meck:expect(hex_repo, get_package, + meck:expect(hex_repo, get_package, fun(_Config, PkgName) -> Matches = ets:match_object(Tid, {{PkgName,'_'}, '_'}), - Releases = + Releases = [#{checksum => Checksum, version => Vsn, - dependencies => Deps} || + dependencies => Deps} || {{_, Vsn}, [Deps, Checksum, _]} <- Matches], - {ok, {200, #{}, #{releases => Releases}}} + {ok, {200, #{}, Releases}} end), %% The state returns us a fake registry @@ -321,7 +321,7 @@ mock_config(Name, Config) -> %% Cache fetches are mocked -- we assume the server and clients are %% correctly used. GoodCache = ?config(good_cache, Config), - {Pkg,Vsn} = ?config(pkg, Config), + {Pkg,Vsn} = ?config(pkg, Config), PkgFile = <<Pkg/binary, "-", Vsn/binary, ".tar">>, {ok, PkgContents} = file:read_file(filename:join(?config(data_dir, Config), PkgFile)), @@ -329,8 +329,8 @@ mock_config(Name, Config) -> {ok, {304, #{<<"etag">> => ?good_etag}, <<>>}}; (_, _, _) -> {ok, {200, #{<<"etag">> => ?good_etag}, PkgContents}} - end), - + end), + [{cache_root, CacheRoot}, {cache_dir, CacheDir}, {tmp_dir, TmpDir}, diff --git a/test/rebar_pkg_alias_SUITE.erl b/test/rebar_pkg_alias_SUITE.erl index 079a3fd..1ef5a34 100644 --- a/test/rebar_pkg_alias_SUITE.erl +++ b/test/rebar_pkg_alias_SUITE.erl @@ -224,7 +224,7 @@ mock_config(Name, Config) -> meck:expect(rebar_prv_update, do, fun(State) -> {ok, State} end), catch ets:delete(?PACKAGE_TABLE), - rebar_packages:new_package_table(), + rebar_packages:new_package_table(), lists:foreach(fun({{N, Vsn}, [Deps, Checksum, _]}) -> case ets:member(?PACKAGE_TABLE, {ec_cnv:to_binary(N), Vsn, <<"hexpm">>}) of @@ -238,11 +238,11 @@ mock_config(Name, Config) -> end; ({_N, _Vsns}) -> ok - - end, AllDeps), + + end, AllDeps), meck:new(hex_repo, [passthrough]), - meck:expect(hex_repo, get_package, + meck:expect(hex_repo, get_package, fun(_Config, PkgName) -> Matches = ets:match_object(Tid, {{PkgName,'_'}, '_'}), Releases = @@ -251,13 +251,13 @@ mock_config(Name, Config) -> dependencies => [{DAppName, {pkg, DN, DV, undefined}} || {DN, DV, _, DAppName} <- Deps]} || {{_, Vsn}, [Deps, Checksum, _]} <- Matches], - {ok, {200, #{}, #{releases => Releases}}} + {ok, {200, #{}, Releases}} end), meck:expect(hex_repo, get_tarball, fun(_, _, _) -> {ok, {304, #{<<"etag">> => EtagGood}, <<>>}} - end), - + end), + %% Move all packages to cache NewConf = [{cache_root, CacheRoot}, {cache_dir, CacheDir}, diff --git a/test/rebar_pkg_repos_SUITE.erl b/test/rebar_pkg_repos_SUITE.erl index c808475..55bc020 100644 --- a/test/rebar_pkg_repos_SUITE.erl +++ b/test/rebar_pkg_repos_SUITE.erl @@ -182,23 +182,25 @@ repo_merging(_Config) -> repo_replacing(_Config) -> Repo1 = #{name => <<"repo-1">>, + repo_name => <<"repo-1">>, api_url => <<"repo-1/api">>}, Repo2 = #{name => <<"repo-2">>, + repo_name => <<"repo-2">>, repo_url => <<"repo-2/repo">>, repo_verify => false}, ?assertMatch([Repo1, Repo2, #{name := <<"hexpm">>}], rebar_hex_repos:repos([{repos, [Repo1]}, - {repos, [Repo2]}])), + {repos, [Repo2]}])), %% use of replace is ignored if found in later entries than the first ?assertMatch([Repo1, Repo2, #{name := <<"hexpm">>}], rebar_hex_repos:repos([{repos, [Repo1]}, - {repos, replace, [Repo2]}])), + {repos, replace, [Repo2]}])), ?assertMatch([Repo1], rebar_hex_repos:repos([{repos, replace, [Repo1]}, - {repos, [Repo2]}])). + {repos, [Repo2]}])). auth_merging(_Config) -> Repo1 = #{name => <<"repo-1">>, |