summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-12-04 15:52:06 -0500
committerGitHub <noreply@github.com>2017-12-04 15:52:06 -0500
commit1f57efcd5c787a71bbc1237dd2b1f99610593286 (patch)
treee94a5c7cf5ecda18b762cbac37c7e624ff6c924d /test
parent4b5a66ff65b304ea4b3b80058a4819cfc1c72fc4 (diff)
parent805dc0fa2aad53a5ac551033fd0da3b433f6b6e1 (diff)
Merge pull request #1679 from ferd/min-coverage
Support minimal coverage validation in tests
Diffstat (limited to 'test')
-rw-r--r--test/rebar_cover_SUITE.erl50
1 files changed, 48 insertions, 2 deletions
diff --git a/test/rebar_cover_SUITE.erl b/test/rebar_cover_SUITE.erl
index c99dbb7..8d6429d 100644
--- a/test/rebar_cover_SUITE.erl
+++ b/test/rebar_cover_SUITE.erl
@@ -15,7 +15,9 @@
flag_verbose/1,
config_verbose/1,
excl_mods_and_apps/1,
- coverdata_is_reset_on_write/1]).
+ coverdata_is_reset_on_write/1,
+ flag_min_coverage/1,
+ config_min_coverage/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -40,7 +42,8 @@ all() ->
root_extra_src_dirs,
index_written,
flag_verbose, config_verbose,
- excl_mods_and_apps, coverdata_is_reset_on_write].
+ excl_mods_and_apps, coverdata_is_reset_on_write,
+ flag_min_coverage, config_min_coverage].
flag_coverdata_written(Config) ->
AppDir = ?config(apps, Config),
@@ -274,3 +277,46 @@ coverdata_is_reset_on_write(Config) ->
Res = lists:map(fun(M) -> cover:analyse(M) end, cover:modules()),
Ok = lists:foldl(fun({ok, R}, Acc) -> R ++ Acc end, [], Res),
[] = lists:filter(fun({_, {0,_}}) -> false; (_) -> true end, Ok).
+
+flag_min_coverage(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("min_cover_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RebarConfig = [{erl_opts, [{d, some_define}]}],
+ ?assertMatch({ok, _},
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig,
+ ["do", "eunit", "--cover", ",", "cover", "--min_coverage=5"],
+ return)),
+
+ ?assertMatch({error,{rebar_prv_cover,{min_coverage_failed,{65,_}}}},
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig,
+ ["do", "eunit", "--cover", ",", "cover", "--min_coverage=65"],
+ return)),
+ ok.
+
+config_min_coverage(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("cover_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RebarConfig1 = [{erl_opts, [{d, some_define}]}, {cover_opts, [{min_coverage,5}]}],
+ ?assertMatch({ok, _},
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig1,
+ ["do", "eunit", "--cover", ",", "cover"],
+ return)),
+
+ RebarConfig2 = [{erl_opts, [{d, some_define}]}, {cover_opts, [{min_coverage,65}]}],
+ ?assertMatch({error,{rebar_prv_cover,{min_coverage_failed,{65,_}}}},
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig2,
+ ["do", "eunit", "--cover", ",", "cover"],
+ return)),
+ ok.