summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTakeru Ohta <phjgt308@gmail.com>2015-09-08 04:29:15 +0900
committerTakeru Ohta <phjgt308@gmail.com>2015-09-08 04:30:22 +0900
commit902dd59d23335c35300b4e5520f128648f501a9f (patch)
treee597647a698beece234a790558d6b83295d026ec /test
parent4ff78b4d7785e567f682a9642772620043af788e (diff)
Add a testcase for 'plt_include_all_deps' dialyzer option
Diffstat (limited to 'test')
-rw-r--r--test/rebar_dialyzer_SUITE.erl71
1 files changed, 69 insertions, 2 deletions
diff --git a/test/rebar_dialyzer_SUITE.erl b/test/rebar_dialyzer_SUITE.erl
index 3158e8f..99d1024 100644
--- a/test/rebar_dialyzer_SUITE.erl
+++ b/test/rebar_dialyzer_SUITE.erl
@@ -7,7 +7,8 @@
all/0,
update_base_plt/1,
update_app_plt/1,
- build_release_plt/1]).
+ build_release_plt/1,
+ plt_include_all_deps_option/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -38,7 +39,7 @@ init_per_testcase(Testcase, Config) ->
rebar_test_utils:init_rebar_state(Config)].
all() ->
- [update_base_plt, update_app_plt, build_release_plt].
+ [update_base_plt, update_app_plt, build_release_plt, plt_include_all_deps_option].
update_base_plt(Config) ->
AppDir = ?config(apps, Config),
@@ -130,6 +131,56 @@ build_release_plt(Config) ->
{ok, PltFiles} = plt_files(Plt),
?assertEqual(ErtsFiles, PltFiles).
+plt_include_all_deps_option(Config) ->
+ AppDir = ?config(apps, Config),
+ RebarConfig = ?config(rebar_config, Config),
+ Plt = ?config(plt, Config),
+ State = ?config(state, Config),
+
+ %% Create applications
+ Name1 = rebar_test_utils:create_random_name("app1_"),
+ Vsn1 = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(filename:join([AppDir,"deps",Name1]), Name1, Vsn1,
+ [erts]),
+ App1 = ec_cnv:to_atom(Name1),
+
+ Name2 = rebar_test_utils:create_random_name("app2_"),
+ Vsn2 = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(filename:join([AppDir,"deps",Name2]), Name2, Vsn2,
+ [erts, App1]), % App2 depends on App1
+ App2 = ec_cnv:to_atom(Name2),
+
+ Name3 = rebar_test_utils:create_random_name("app3_"), % the project application
+ Vsn3 = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name3, Vsn3,
+ [erts, App2]), % App3 depends on App2
+
+ %% Dependencies settings
+ State1 = rebar_state:add_resource(State, {localfs, rebar_localfs_resource}),
+ Config1 = [{state, State1} | Config],
+ RebarConfig1 = merge_config(
+ [{deps,
+ [
+ {App1, {localfs, filename:join([AppDir,"deps",Name1])}},
+ {App2, {localfs, filename:join([AppDir,"deps",Name2])}}
+ ]}],
+ RebarConfig),
+
+ %% Dialyzer: plt_include_all_deps = false (default)
+ rebar_test_utils:run_and_check(Config1, RebarConfig1, ["dialyzer"],
+ {ok, [{app, Name3}]}),
+ {ok, PltFiles1} = plt_files(Plt),
+ ?assertEqual([App2, erts], get_apps_from_beam_files(PltFiles1)),
+
+ %% Dialyzer: plt_include_all_deps = true
+ RebarConfig2 = merge_config([{dialyzer, [{plt_include_all_deps, true}]}],
+ RebarConfig1),
+ rebar_test_utils:run_and_check(Config1, RebarConfig2, ["dialyzer"],
+ {ok, [{app, Name3}]}),
+
+ {ok, PltFiles2} = plt_files(Plt),
+ ?assertEqual([App1, App2, erts], get_apps_from_beam_files(PltFiles2)).
+
%% Helpers
erts_files() ->
@@ -157,3 +208,19 @@ alter_plt(Plt) ->
{init_plt, Plt},
{files, [code:which(dialyzer)]}]),
ok.
+
+-spec merge_config(Config, Config) -> Config when
+ Config :: [{term(), term()}].
+merge_config(NewConfig, OldConfig) ->
+ dict:to_list(
+ rebar_opts:merge_opts(dict:from_list(NewConfig),
+ dict:from_list(OldConfig))).
+
+-spec get_apps_from_beam_files(string()) -> [atom()].
+get_apps_from_beam_files(BeamFiles) ->
+ lists:usort(
+ [begin
+ AppNameVsn = filename:basename(filename:dirname(filename:dirname(File))),
+ [AppName | _] = string:tokens(AppNameVsn ++ "-", "-"),
+ ec_cnv:to_atom(AppName)
+ end || File <- BeamFiles]).