Merge pull request #46 from ericbmerritt/master

fix testing for erlware_commons
This commit is contained in:
Tristan Sloughter 2013-10-14 14:23:22 -07:00
commit 2e61eb481d
11 changed files with 46 additions and 49 deletions

View file

@ -227,7 +227,7 @@ colorize_(Color, Bold, Msg) when is_integer(Color), is_integer(Bold)->
%%% Test Functions %%% Test Functions
%%%=================================================================== %%%===================================================================
-ifndef(NOTEST). -ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
should_test() -> should_test() ->

View file

@ -33,7 +33,7 @@
is_true/1, is_true/1,
is_false/1]). is_false/1]).
-ifndef(NOTEST). -ifdef(DEV_ONLY).
-include_lib("proper/include/proper.hrl"). -include_lib("proper/include/proper.hrl").
-endif. -endif.
@ -218,10 +218,10 @@ to_atom(X) ->
to_atom(to_list(X)). to_atom(to_list(X)).
%%%=================================================================== %%%===================================================================
%%% API %%% Tests
%%%=================================================================== %%%===================================================================
-ifndef(NOTEST). -ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
force_proper_test_() -> force_proper_test_() ->

View file

@ -92,18 +92,18 @@ do_parse(Date, Now, Opts) ->
{error, bad_date} -> {error, bad_date} ->
erlang:throw({?MODULE, {bad_date, Date}}); erlang:throw({?MODULE, {bad_date, Date}});
{D1, T1} = {{Y, M, D}, {H, M1, S}} {D1, T1} = {{Y, M, D}, {H, M1, S}}
when is_number(Y), is_number(M), when is_number(Y), is_number(M),
is_number(D), is_number(H), is_number(D), is_number(H),
is_number(M1), is_number(S) -> is_number(M1), is_number(S) ->
case calendar:valid_date(D1) of case calendar:valid_date(D1) of
true -> {D1, T1}; true -> {D1, T1};
false -> erlang:throw({?MODULE, {bad_date, Date}}) false -> erlang:throw({?MODULE, {bad_date, Date}})
end; end;
{D1, _T1, {Ms}} = {{Y, M, D}, {H, M1, S}, {Ms}} {D1, _T1, {Ms}} = {{Y, M, D}, {H, M1, S}, {Ms}}
when is_number(Y), is_number(M), when is_number(Y), is_number(M),
is_number(D), is_number(H), is_number(D), is_number(H),
is_number(M1), is_number(S), is_number(M1), is_number(S),
is_number(Ms) -> is_number(Ms) ->
case calendar:valid_date(D1) of case calendar:valid_date(D1) of
true -> {D1, {H,M1,S,Ms}}; true -> {D1, {H,M1,S,Ms}};
false -> erlang:throw({?MODULE, {bad_date, Date}}) false -> erlang:throw({?MODULE, {bad_date, Date}})
@ -138,17 +138,17 @@ nparse(Date) ->
parse([Year, X, Month, X, Day, Hour, $:, Min, $:, Sec, $Z ], _Now, _Opts) parse([Year, X, Month, X, Day, Hour, $:, Min, $:, Sec, $Z ], _Now, _Opts)
when (?is_us_sep(X) orelse ?is_world_sep(X)) when (?is_us_sep(X) orelse ?is_world_sep(X))
andalso Year > 31 -> andalso Year > 31 ->
{{Year, Month, Day}, {hour(Hour, []), Min, Sec}, { 0}}; {{Year, Month, Day}, {hour(Hour, []), Min, Sec}, { 0}};
parse([Year, X, Month, X, Day, Hour, $:, Min, $:, Sec, $+, Off | _Rest ], _Now, _Opts) parse([Year, X, Month, X, Day, Hour, $:, Min, $:, Sec, $+, Off | _Rest ], _Now, _Opts)
when (?is_us_sep(X) orelse ?is_world_sep(X)) when (?is_us_sep(X) orelse ?is_world_sep(X))
andalso Year > 31 -> andalso Year > 31 ->
{{Year, Month, Day}, {hour(Hour, []) - Off, Min, Sec}, {0}}; {{Year, Month, Day}, {hour(Hour, []) - Off, Min, Sec}, {0}};
parse([Year, X, Month, X, Day, Hour, $:, Min, $:, Sec, $-, Off | _Rest ], _Now, _Opts) parse([Year, X, Month, X, Day, Hour, $:, Min, $:, Sec, $-, Off | _Rest ], _Now, _Opts)
when (?is_us_sep(X) orelse ?is_world_sep(X)) when (?is_us_sep(X) orelse ?is_world_sep(X))
andalso Year > 31 -> andalso Year > 31 ->
{{Year, Month, Day}, {hour(Hour, []) + Off, Min, Sec}, {0}}; {{Year, Month, Day}, {hour(Hour, []) + Off, Min, Sec}, {0}};
%% Date/Times 22 Aug 2008 6:35.0001 PM %% Date/Times 22 Aug 2008 6:35.0001 PM
@ -168,7 +168,7 @@ parse([Day,X,Month,X,Year,Hour,$:,Min,$:,Sec,$., Ms | PAM], _Now, _Opts)
parse([Year,X,Month,X,Day,Hour,$:,Min,$:,Sec,$., Ms], _Now, _Opts) parse([Year,X,Month,X,Day,Hour,$:,Min,$:,Sec,$., Ms], _Now, _Opts)
when (?is_us_sep(X) orelse ?is_world_sep(X)) when (?is_us_sep(X) orelse ?is_world_sep(X))
andalso ?is_year(Year) -> andalso ?is_year(Year) ->
{{Year, Month, Day}, {hour(Hour,[]), Min, Sec}, {Ms}}; {{Year, Month, Day}, {hour(Hour,[]), Min, Sec}, {Ms}};
parse([Month,X,Day,X,Year,Hour,$:,Min,$:,Sec,$., Ms], _Now, _Opts) parse([Month,X,Day,X,Year,Hour,$:,Min,$:,Sec,$., Ms], _Now, _Opts)
when ?is_us_sep(X) andalso ?is_month(Month) -> when ?is_us_sep(X) andalso ?is_month(Month) ->
@ -180,21 +180,21 @@ parse([Day,X,Month,X,Year,Hour,$:,Min,$:,Sec,$., Ms ], _Now, _Opts)
%% Date/Times Dec 1st, 2012 6:25 PM %% Date/Times Dec 1st, 2012 6:25 PM
parse([Month,Day,Year,Hour,$:,Min,$:,Sec | PAM], _Now, _Opts) parse([Month,Day,Year,Hour,$:,Min,$:,Sec | PAM], _Now, _Opts)
when ?is_meridian(PAM) andalso ?is_hinted_month(Month) andalso ?is_day(Day) -> when ?is_meridian(PAM) andalso ?is_hinted_month(Month) andalso ?is_day(Day) ->
{{Year, Month, Day}, {hour(Hour, PAM), Min, Sec}}; {{Year, Month, Day}, {hour(Hour, PAM), Min, Sec}};
parse([Month,Day,Year,Hour,$:,Min | PAM], _Now, _Opts) parse([Month,Day,Year,Hour,$:,Min | PAM], _Now, _Opts)
when ?is_meridian(PAM) andalso ?is_hinted_month(Month) andalso ?is_day(Day) -> when ?is_meridian(PAM) andalso ?is_hinted_month(Month) andalso ?is_day(Day) ->
{{Year, Month, Day}, {hour(Hour, PAM), Min, 0}}; {{Year, Month, Day}, {hour(Hour, PAM), Min, 0}};
parse([Month,Day,Year,Hour | PAM], _Now, _Opts) parse([Month,Day,Year,Hour | PAM], _Now, _Opts)
when ?is_meridian(PAM) andalso ?is_hinted_month(Month) andalso ?is_day(Day) -> when ?is_meridian(PAM) andalso ?is_hinted_month(Month) andalso ?is_day(Day) ->
{{Year, Month, Day}, {hour(Hour, PAM), 0, 0}}; {{Year, Month, Day}, {hour(Hour, PAM), 0, 0}};
%% Date/Times Dec 1st, 2012 18:25:15 (no AM/PM) %% Date/Times Dec 1st, 2012 18:25:15 (no AM/PM)
parse([Month,Day,Year,Hour,$:,Min,$:,Sec], _Now, _Opts) parse([Month,Day,Year,Hour,$:,Min,$:,Sec], _Now, _Opts)
when ?is_hinted_month(Month) andalso ?is_day(Day) -> when ?is_hinted_month(Month) andalso ?is_day(Day) ->
{{Year, Month, Day}, {hour(Hour, []), Min, Sec}}; {{Year, Month, Day}, {hour(Hour, []), Min, Sec}};
parse([Month,Day,Year,Hour,$:,Min], _Now, _Opts) parse([Month,Day,Year,Hour,$:,Min], _Now, _Opts)
when ?is_hinted_month(Month) andalso ?is_day(Day) -> when ?is_hinted_month(Month) andalso ?is_day(Day) ->
{{Year, Month, Day}, {hour(Hour, []), Min, 0}}; {{Year, Month, Day}, {hour(Hour, []), Min, 0}};
%% Times - 21:45, 13:45:54, 13:15PM etc %% Times - 21:45, 13:45:54, 13:15PM etc
parse([Hour,$:,Min,$:,Sec | PAM], {Date, _Time}, _O) when ?is_meridian(PAM) -> parse([Hour,$:,Min,$:,Sec | PAM], {Date, _Time}, _O) when ?is_meridian(PAM) ->
@ -243,7 +243,7 @@ parse([Day,X,Month,X,Year,Hour | PAM], _Date, _Opts)
{{Year, Month, Day}, {hour(Hour, PAM), 0, 0}}; {{Year, Month, Day}, {hour(Hour, PAM), 0, 0}};
parse([Month,X,Day,X,Year,Hour | PAM], _Date, _Opts) parse([Month,X,Day,X,Year,Hour | PAM], _Date, _Opts)
when ?is_meridian(PAM) andalso ?is_us_sep(X) -> when ?is_meridian(PAM) andalso ?is_us_sep(X) ->
{{Year, Month, Day}, {hour(Hour, PAM), 0, 0}}; {{Year, Month, Day}, {hour(Hour, PAM), 0, 0}};
%% Time is "6:35 PM" ms return %% Time is "6:35 PM" ms return
@ -671,14 +671,14 @@ pad2(X) when is_float(X) ->
ltoi(X) -> ltoi(X) ->
list_to_integer(X). list_to_integer(X).
%% %%%===================================================================
%% TEST FUNCTIONS %%% Tests
%% %%%===================================================================
%% c(dh_date,[{d,'TEST'}]).
%-define(NOTEST, 1).
-ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-define(DATE, {{2001,3,10},{17,16,17}}). -define(DATE, {{2001,3,10},{17,16,17}}).
-define(DATEMS, {{2001,3,10},{17,16,17,123456}}). -define(DATEMS, {{2001,3,10},{17,16,17,123456}}).
-define(DATE_NOON, {{2001,3,10},{12,0,0}}). -define(DATE_NOON, {{2001,3,10},{12,0,0}}).
@ -938,3 +938,4 @@ zulu_test_() ->
?_assertEqual(format("Y-m-d\\TH:i:s",nparse("2001-03-10T15:16:17-04:00")), ?_assertEqual(format("Y-m-d\\TH:i:s",nparse("2001-03-10T15:16:17-04:00")),
"2001-03-10T19:16:17") "2001-03-10T19:16:17")
]. ].
-endif.

View file

@ -298,7 +298,7 @@ sub_files(From) ->
%%% Test Functions %%% Test Functions
%%%=================================================================== %%%===================================================================
-ifndef(NOTEST). -ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
setup_test() -> setup_test() ->

View file

@ -154,7 +154,7 @@ keys(Data) ->
%%%=================================================================== %%%===================================================================
-ifndef(NOTEST). -ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
%% For me unit testing initially is about covering the obvious case. A %% For me unit testing initially is about covering the obvious case. A

View file

@ -68,7 +68,7 @@ fetch(Fun, List) when is_list(List), is_function(Fun) ->
%%% Test Functions %%% Test Functions
%%%=================================================================== %%%===================================================================
-ifndef(NOTEST). -ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
find1_test() -> find1_test() ->

View file

@ -314,7 +314,7 @@ internal_pes(Vsn, LVsn) ->
%%% Test Functions %%% Test Functions
%%%=================================================================== %%%===================================================================
-ifndef(NOTEST). -ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
eql_test() -> eql_test() ->

View file

@ -1,4 +1,3 @@
%%% vi:ts=4 sw=4 et
-module(ec_semver_parser). -module(ec_semver_parser).
-export([parse/1,file/1]). -export([parse/1,file/1]).
-compile({nowarn_unused_function,[p/4, p/5, p_eof/0, p_optional/1, p_not/1, p_assert/1, p_seq/1, p_and/1, p_choose/1, p_zero_or_more/1, p_one_or_more/1, p_label/2, p_string/1, p_anything/0, p_charclass/1, p_regexp/1, p_attempt/4, line/1, column/1]}). -compile({nowarn_unused_function,[p/4, p/5, p_eof/0, p_optional/1, p_not/1, p_assert/1, p_seq/1, p_and/1, p_choose/1, p_zero_or_more/1, p_one_or_more/1, p_label/2, p_string/1, p_anything/0, p_charclass/1, p_regexp/1, p_attempt/4, line/1, column/1]}).
@ -6,7 +5,7 @@
-compile(export_all). -compile(export_all).
-spec file(file:name()) -> any(). -spec file(file:name()) -> any().
file(Filename) -> {ok, Bin} = file:read_file(Filename), parse(Bin). file(Filename) -> case file:read_file(Filename) of {ok,Bin} -> parse(Bin); Err -> Err end.
-spec parse(binary() | list()) -> any(). -spec parse(binary() | list()) -> any().
parse(List) when is_list(List) -> parse(list_to_binary(List)); parse(List) when is_list(List) -> parse(list_to_binary(List));
@ -19,19 +18,19 @@ parse(Input) when is_binary(Input) ->
release_memo(), Result. release_memo(), Result.
'semver'(Input, Index) -> 'semver'(Input, Index) ->
p(Input, Index, 'semver', fun(I,D) -> (p_seq([fun 'major_minor_patch_min_patch'/2, p_optional(p_seq([p_string(<<"-">>), fun 'alpha_part'/2, p_zero_or_more(p_seq([p_string(<<".">>), fun 'alpha_part'/2]))])), p_optional(p_seq([p_string(<<"+">>), fun 'alpha_part'/2, p_zero_or_more(p_seq([p_string(<<".">>), fun 'alpha_part'/2]))])), p_not(p_anything())]))(I,D) end, fun(Node, _Idx) -> ec_semver:internal_parse_version(Node) end). p(Input, Index, 'semver', fun(I,D) -> (p_seq([fun 'major_minor_patch_min_patch'/2, p_optional(p_seq([p_string(<<"-">>), fun 'alpha_part'/2, p_zero_or_more(p_seq([p_string(<<".">>), fun 'alpha_part'/2]))])), p_optional(p_seq([p_string(<<"+">>), fun 'alpha_part'/2, p_zero_or_more(p_seq([p_string(<<".">>), fun 'alpha_part'/2]))])), p_not(p_anything())]))(I,D) end, fun(Node, _Idx) -> ec_semver:internal_parse_version(Node) end).
'major_minor_patch_min_patch'(Input, Index) -> 'major_minor_patch_min_patch'(Input, Index) ->
p(Input, Index, 'major_minor_patch_min_patch', fun(I,D) -> (p_seq([p_choose([p_seq([p_optional(p_string(<<"v">>)), fun 'numeric_part'/2]), fun 'alpha_part'/2]), p_optional(p_seq([p_string(<<".">>), fun 'version_part'/2])), p_optional(p_seq([p_string(<<".">>), fun 'version_part'/2])), p_optional(p_seq([p_string(<<".">>), fun 'version_part'/2]))]))(I,D) end, fun(Node, Idx) -> transform('major_minor_patch_min_patch', Node, Idx) end). p(Input, Index, 'major_minor_patch_min_patch', fun(I,D) -> (p_seq([p_choose([p_seq([p_optional(p_string(<<"v">>)), fun 'numeric_part'/2]), fun 'alpha_part'/2]), p_optional(p_seq([p_string(<<".">>), fun 'version_part'/2])), p_optional(p_seq([p_string(<<".">>), fun 'version_part'/2])), p_optional(p_seq([p_string(<<".">>), fun 'version_part'/2]))]))(I,D) end, fun(Node, Idx) ->transform('major_minor_patch_min_patch', Node, Idx) end).
'version_part'(Input, Index) -> 'version_part'(Input, Index) ->
p(Input, Index, 'version_part', fun(I,D) -> (p_choose([fun 'numeric_part'/2, fun 'alpha_part'/2]))(I,D) end, fun(Node, Idx) -> transform('version_part', Node, Idx) end). p(Input, Index, 'version_part', fun(I,D) -> (p_choose([fun 'numeric_part'/2, fun 'alpha_part'/2]))(I,D) end, fun(Node, Idx) ->transform('version_part', Node, Idx) end).
'numeric_part'(Input, Index) -> 'numeric_part'(Input, Index) ->
p(Input, Index, 'numeric_part', fun(I,D) -> (p_one_or_more(p_charclass(<<"[0-9]">>)))(I,D) end, fun(Node, _Idx) -> erlang:list_to_integer(erlang:binary_to_list(erlang:iolist_to_binary(Node))) end). p(Input, Index, 'numeric_part', fun(I,D) -> (p_one_or_more(p_charclass(<<"[0-9]">>)))(I,D) end, fun(Node, _Idx) ->erlang:list_to_integer(erlang:binary_to_list(erlang:iolist_to_binary(Node))) end).
'alpha_part'(Input, Index) -> 'alpha_part'(Input, Index) ->
p(Input, Index, 'alpha_part', fun(I,D) -> (p_one_or_more(p_charclass(<<"[A-Za-z0-9]">>)))(I,D) end, fun(Node, _Idx) -> erlang:iolist_to_binary(Node) end). p(Input, Index, 'alpha_part', fun(I,D) -> (p_one_or_more(p_charclass(<<"[A-Za-z0-9]">>)))(I,D) end, fun(Node, _Idx) ->erlang:iolist_to_binary(Node) end).
transform(_,Node,_Index) -> Node. transform(_,Node,_Index) -> Node.

View file

@ -43,8 +43,6 @@
type/0, type/0,
supported/0]). supported/0]).
-include_lib("eunit/include/eunit.hrl").
%%============================================================================ %%============================================================================
%% Types %% Types
%%============================================================================ %%============================================================================
@ -202,6 +200,9 @@ get_string(String) ->
%%%==================================================================== %%%====================================================================
%%% tests %%% tests
%%%==================================================================== %%%====================================================================
-ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl").
general_test_() -> general_test_() ->
[?_test(42 == get_integer("42")), [?_test(42 == get_integer("42")),
?_test(500211 == get_integer("500211")), ?_test(500211 == get_integer("500211")),
@ -216,3 +217,5 @@ general_test_() ->
?_test(false == get_boolean("False")), ?_test(false == get_boolean("False")),
?_test(false == get_boolean("No")), ?_test(false == get_boolean("No")),
?_test(false == get_boolean("no"))]. ?_test(false == get_boolean("no"))].
-endif.

View file

@ -1,6 +1,8 @@
%%% @copyright Erlware, LLC. %%% @copyright Erlware, LLC.
-module(ec_plists_tests). -module(ec_plists_tests).
-ifdef(DEV_ONLY).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
%%%=================================================================== %%%===================================================================
@ -73,3 +75,5 @@ ftmap_bad_test() ->
lists:seq(1, 5)), lists:seq(1, 5)),
?assertMatch([{value, 1}, {error,{throw,test_exception}}, {value, 3}, ?assertMatch([{value, 1}, {error,{throw,test_exception}}, {value, 3},
{value, 4}, {value, 5}] , Results). {value, 4}, {value, 5}] , Results).
-endif.

View file

@ -1,10 +0,0 @@
-module(mock).
-export([new_dictionary/0]).
new_dictionary() ->
meck:new(ec_dictionary_proper),
meck:expect(ec_dictionary_proper, dictionary, fun() ->
proper_types:union([ec_dict])
end).