From 04fedc7422c26002785f6e7cb6e814fdb8a2f0dd Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Tue, 2 Jun 2015 15:12:12 -0400 Subject: Add functions to validate OTP release in use In the spirit of Original Rebar's "require_min_otp_vsn", this adds rebar_utils:check_min_otp_version/1 (taking a string containing the minimum version) and rebar_utils:check_blacklisted_otp_versions/1 (taking a list of regular expression strings), as well as tests in rebar_utils_SUITE. They're currently only called by the tests- how/where to best place calls to them from non-test code needs to be determined (at which point two corresponding rebar.config keys can be supported). For example, the version probably shouldn't be enforced when just running "rebar3 help". --- test/rebar_utils_SUITE.erl | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index f04ab63..d766af4 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -1,6 +1,8 @@ -module(rebar_utils_SUITE). -export([all/0, + init_per_testcase/2, + end_per_testcase/2, groups/0, init_per_group/2, end_per_group/2, @@ -22,12 +24,22 @@ task_with_flag_with_commas/1, task_with_multiple_flags/1, special_task_do/1, + valid_otp_version/1, + valid_otp_version_equal/1, + invalid_otp_version/1, + nonblacklisted_otp_version/1, + blacklisted_otp_version/1, sh_does_not_miss_messages/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("kernel/include/file.hrl"). +init_per_testcase(_, Config) -> + rebar_test_utils:init_rebar_state(Config). + +end_per_testcase(_, _Config) -> + catch meck:unload(). all() -> [{group, args_to_tasks}, @@ -51,7 +63,13 @@ groups() -> task_with_flag_with_trailing_comma, task_with_flag_with_commas, task_with_multiple_flags, - special_task_do]}]. + special_task_do, + valid_otp_version, + valid_otp_version_equal, + invalid_otp_version, + nonblacklisted_otp_version, + blacklisted_otp_version + ]}]. init_per_group(_, Config) -> Config. end_per_group(_, Config) -> Config. @@ -120,6 +138,37 @@ special_task_do(_Config) -> "do", "bar,", "baz"]). + +valid_otp_version(_Config) -> + meck:new(rebar_utils, [passthrough]), + meck:expect(rebar_utils, otp_release, fun() -> "42.4" end), + rebar_utils:check_min_otp_version("42.3"), + meck:unload(rebar_utils). + +valid_otp_version_equal(_Config) -> + meck:new(rebar_utils, [passthrough]), + meck:expect(rebar_utils, otp_release, fun() -> "42.3" end), + rebar_utils:check_min_otp_version("42.3"), + meck:unload(rebar_utils). + +invalid_otp_version(_Config) -> + meck:new(rebar_utils, [passthrough]), + meck:expect(rebar_utils, otp_release, fun() -> "17.4" end), + ?assertException(throw, rebar_abort, rebar_utils:check_min_otp_version("42.3")), + meck:unload(rebar_utils). + +nonblacklisted_otp_version(_Config) -> + meck:new(rebar_utils, [passthrough]), + meck:expect(rebar_utils, otp_release, fun() -> "42.4" end), + rebar_utils:check_blacklisted_otp_versions(["1\\.2", "42\\.3"]), + meck:unload(rebar_utils). + +blacklisted_otp_version(_Config) -> + meck:new(rebar_utils, [passthrough]), + meck:expect(rebar_utils, otp_release, fun() -> "42.4" end), + ?assertException(throw, rebar_abort, rebar_utils:check_blacklisted_otp_versions(["1\\.2", "42\\.[1-4]"])), + meck:unload(rebar_utils). + sh_does_not_miss_messages(_Config) -> Source = "~nmain(_) ->~n io:format(\"donotmissme\").~n", file:write_file("do_not_miss_messages", io_lib:format(Source,[])), -- cgit v1.1 From 6e9df6cc577f84cac330065c26ba2ada7bc56a32 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 24 Jul 2015 21:40:43 -0500 Subject: parse old format of OTP versions --- test/rebar_utils_SUITE.erl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index d766af4..144b840 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -25,6 +25,7 @@ task_with_multiple_flags/1, special_task_do/1, valid_otp_version/1, + valid_old_format_otp_version/1, valid_otp_version_equal/1, invalid_otp_version/1, nonblacklisted_otp_version/1, @@ -65,6 +66,7 @@ groups() -> task_with_multiple_flags, special_task_do, valid_otp_version, + valid_old_format_otp_version, valid_otp_version_equal, invalid_otp_version, nonblacklisted_otp_version, @@ -145,6 +147,12 @@ valid_otp_version(_Config) -> rebar_utils:check_min_otp_version("42.3"), meck:unload(rebar_utils). +valid_old_format_otp_version(_Config) -> + meck:new(rebar_utils, [passthrough]), + meck:expect(rebar_utils, otp_release, fun() -> "R15B03-1" end), + rebar_utils:check_min_otp_version("R15"), + meck:unload(rebar_utils). + valid_otp_version_equal(_Config) -> meck:new(rebar_utils, [passthrough]), meck:expect(rebar_utils, otp_release, fun() -> "42.3" end), -- cgit v1.1 From 90fbd6dbb9a1a8d1185fc521ffd2d391e8befcdf Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 25 Jul 2015 11:43:54 -0500 Subject: add support for old format otp versions --- test/rebar_utils_SUITE.erl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index 144b840..24e8afe 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -150,7 +150,17 @@ valid_otp_version(_Config) -> valid_old_format_otp_version(_Config) -> meck:new(rebar_utils, [passthrough]), meck:expect(rebar_utils, otp_release, fun() -> "R15B03-1" end), - rebar_utils:check_min_otp_version("R15"), + rebar_utils:check_min_otp_version("14"), + + meck:expect(rebar_utils, otp_release, fun() -> "R16B03" end), + rebar_utils:check_min_otp_version("16.0"), + + meck:expect(rebar_utils, otp_release, fun() -> "18.0.1" end), + rebar_utils:check_min_otp_version("17.5.4"), + + meck:expect(rebar_utils, otp_release, fun() -> "18.0-rc1" end), + ?assertException(throw, rebar_abort, rebar_utils:check_min_otp_version("19")), + meck:unload(rebar_utils). valid_otp_version_equal(_Config) -> -- cgit v1.1