summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_prv_dialyzer.erl24
-rw-r--r--test/rebar_dialyzer_SUITE.erl79
2 files changed, 96 insertions, 7 deletions
diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl
index 622ee60..ec9e81a 100644
--- a/src/rebar_prv_dialyzer.erl
+++ b/src/rebar_prv_dialyzer.erl
@@ -353,8 +353,19 @@ update_base_plt(State, BasePlt, Output, BaseFiles) ->
build_plt(State, BasePlt, Output, BaseFiles)
end.
+build_plt(State, Plt, _, []) ->
+ ?INFO("Building with no files in ~p...", [Plt]),
+ Opts = [{get_warnings, false},
+ {output_plt, Plt},
+ {apps, [erts]}],
+ % Create a PLT with erts files and then remove erts files to be left with an
+ % empty PLT. Dialyzer will crash when trying to build a PLT with an empty
+ % file list.
+ _ = dialyzer:run([{analysis_type, plt_build} | Opts]),
+ _ = dialyzer:run([{analysis_type, plt_remove}, {init_plt, Plt} | Opts]),
+ {0, State};
build_plt(State, Plt, Output, Files) ->
- ?INFO("Adding ~b files to ~p...", [length(Files), Plt]),
+ ?INFO("Building with ~b files in ~p...", [length(Files), Plt]),
GetWarnings = get_config(State, get_warnings, false),
Opts = [{analysis_type, plt_build},
{get_warnings, GetWarnings},
@@ -369,12 +380,15 @@ succ_typings(State, Plt, Output) ->
{0, State};
_ ->
Apps = rebar_state:project_apps(State),
- succ_typings(State, Plt, Output, Apps)
+ ?INFO("Doing success typing analysis...", []),
+ Files = apps_to_files(Apps),
+ succ_typings(State, Plt, Output, Files)
end.
-succ_typings(State, Plt, Output, Apps) ->
- ?INFO("Doing success typing analysis...", []),
- Files = apps_to_files(Apps),
+succ_typings(State, Plt, _, []) ->
+ ?INFO("Analyzing no files with ~p...", [Plt]),
+ {0, State};
+succ_typings(State, Plt, Output, Files) ->
?INFO("Analyzing ~b files with ~p...", [length(Files), Plt]),
Opts = [{analysis_type, succ_typings},
{get_warnings, true},
diff --git a/test/rebar_dialyzer_SUITE.erl b/test/rebar_dialyzer_SUITE.erl
index 22a4894..e5d8c52 100644
--- a/test/rebar_dialyzer_SUITE.erl
+++ b/test/rebar_dialyzer_SUITE.erl
@@ -3,8 +3,14 @@
-export([suite/0,
init_per_suite/1,
end_per_suite/1,
+ init_per_group/2,
+ end_per_group/2,
init_per_testcase/2,
all/0,
+ groups/0,
+ empty_base_plt/1,
+ empty_app_plt/1,
+ empty_app_succ_typings/1,
update_base_plt/1,
update_app_plt/1,
build_release_plt/1,
@@ -23,6 +29,14 @@ init_per_suite(Config) ->
end_per_suite(_Config) ->
ok.
+init_per_group(empty, Config) ->
+ [{base_plt_apps, []} | Config];
+init_per_group(_Group, Config) ->
+ [{base_plt_apps, [erts]} | Config].
+
+end_per_group(_Group, _Config) ->
+ ok.
+
init_per_testcase(Testcase, Config) ->
PrivDir = ?config(priv_dir, Config),
Prefix = ec_cnv:to_list(Testcase),
@@ -31,7 +45,7 @@ init_per_testcase(Testcase, Config) ->
{plt_location, PrivDir},
{base_plt_prefix, BasePrefix},
{base_plt_location, PrivDir},
- {base_plt_apps, [erts]}],
+ {base_plt_apps, ?config(base_plt_apps, Config)}],
Suffix = "_" ++ rebar_utils:otp_release() ++ "_plt",
[{plt, filename:join(PrivDir, Prefix ++ Suffix)},
{base_plt, filename:join(PrivDir, BasePrefix ++ Suffix)},
@@ -39,7 +53,68 @@ init_per_testcase(Testcase, Config) ->
rebar_test_utils:init_rebar_state(Config)].
all() ->
- [update_base_plt, update_app_plt, build_release_plt, plt_apps_option].
+ [{group, empty}, {group, build_and_check}, {group, update}].
+
+groups() ->
+ [{empty, [empty_base_plt, empty_app_plt, empty_app_succ_typings]},
+ {build_and_check, [build_release_plt, plt_apps_option]},
+ {update, [update_base_plt, update_app_plt]}].
+
+empty_base_plt(Config) ->
+ AppDir = ?config(apps, Config),
+ RebarConfig = ?config(rebar_config, Config),
+ BasePlt = ?config(base_plt, Config),
+ Plt = ?config(plt, Config),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [erts]),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"],
+ {ok, [{app, Name}]}),
+
+ {ok, BasePltFiles} = plt_files(BasePlt),
+ ?assertEqual([], BasePltFiles),
+
+ ErtsFiles = erts_files(),
+ {ok, PltFiles} = plt_files(Plt),
+ ?assertEqual(ErtsFiles, PltFiles),
+
+ ok.
+
+empty_app_plt(Config) ->
+ AppDir = ?config(apps, Config),
+ RebarConfig = ?config(rebar_config, Config),
+ BasePlt = ?config(base_plt, Config),
+ Plt = ?config(plt, Config),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, []),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"],
+ {ok, [{app, Name}]}),
+
+ {ok, BasePltFiles} = plt_files(BasePlt),
+ ?assertEqual([], BasePltFiles),
+
+ {ok, PltFiles} = plt_files(Plt),
+ ?assertEqual([], PltFiles),
+
+ ok.
+
+empty_app_succ_typings(Config) ->
+ AppDir = ?config(apps, Config),
+ RebarConfig = ?config(rebar_config, Config),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_empty_app(AppDir, Name, Vsn, []),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"],
+ {ok, [{app, Name}]}),
+
+ ok.
update_base_plt(Config) ->
AppDir = ?config(apps, Config),