Merge pull request #152 from paulo-ferraz-oliveira/fix/for_dialyzer
Fixes for dialyzer
This commit is contained in:
commit
0318b467bc
4 changed files with 38 additions and 21 deletions
10
.github/workflows/main.yml
vendored
10
.github/workflows/main.yml
vendored
|
@ -12,20 +12,20 @@ jobs:
|
|||
build:
|
||||
name: Test on OTP ${{ matrix.otp_version }} and ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
container:
|
||||
image: erlang:${{matrix.otp_version}}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
otp_version: ['23.2.1', '22.3.4.2', '21.3.8.16', '20.3.8.21', '19.3.6.13']
|
||||
otp_version: ['23.2', '22.3', '21.3', '20.3', '19.3']
|
||||
os: [ubuntu-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: bajankristof/setup-erlang@master
|
||||
with:
|
||||
otp-version: ${{ matrix.otp_version }}
|
||||
|
||||
- name: Compile
|
||||
run: rebar3 compile
|
||||
- name: Dialyze
|
||||
run: rebar3 as test dialyzer
|
||||
- name: EUnit tests
|
||||
run: TERM=xterm rebar3 eunit
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -12,5 +12,7 @@ _build
|
|||
erl_crash.dump
|
||||
*.pyc
|
||||
*~
|
||||
TEST-*.xml
|
||||
/foo
|
||||
|
||||
src/ec_semver_parser.peg
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
new() ->
|
||||
{}.
|
||||
|
||||
-spec vsn(t()) -> {ok, string()} | {error, Reason::any()}.
|
||||
-spec vsn(t()|string()) -> {ok, string()} | {error, Reason::any()}.
|
||||
vsn(Data) ->
|
||||
{Vsn, RawRef, RawCount} = collect_default_refcount(Data),
|
||||
{ok, build_vsn_string(Vsn, RawRef, RawCount)}.
|
||||
|
@ -61,12 +61,7 @@ collect_default_refcount(Data) ->
|
|||
build_vsn_string(Vsn, RawRef, RawCount) ->
|
||||
%% Cleanup the tag and the Ref information. Basically leading 'v's and
|
||||
%% whitespace needs to go away.
|
||||
RefTag = case RawRef of
|
||||
undefined ->
|
||||
"";
|
||||
RawRef ->
|
||||
[".ref", re:replace(RawRef, "\\s", "", [global])]
|
||||
end,
|
||||
RefTag = [".ref", re:replace(RawRef, "\\s", "", [global])],
|
||||
Count = erlang:iolist_to_binary(re:replace(RawCount, "\\s", "", [global])),
|
||||
|
||||
%% Create the valid [semver](http://semver.org) version from the tag
|
||||
|
@ -82,26 +77,48 @@ get_patch_count(RawRef) ->
|
|||
Ref = re:replace(RawRef, "\\s", "", [global]),
|
||||
Cmd = io_lib:format("git rev-list --count ~s..HEAD",
|
||||
[Ref]),
|
||||
os:cmd(Cmd).
|
||||
case os:cmd(Cmd) of
|
||||
"fatal: " ++ _ ->
|
||||
0;
|
||||
Count ->
|
||||
Count
|
||||
end.
|
||||
|
||||
-spec parse_tags(t()) -> {string()|undefined, ec_semver:version_string()}.
|
||||
-spec parse_tags(t()|string()) -> {string()|undefined, ec_semver:version_string()}.
|
||||
parse_tags({}) ->
|
||||
parse_tags("");
|
||||
parse_tags(Pattern) ->
|
||||
Cmd = io_lib:format("git describe --abbrev=0 --tags --match \"~s*\"", [Pattern]),
|
||||
Tag = os:cmd(Cmd),
|
||||
case Tag of
|
||||
"fatal: " ++ _ ->
|
||||
{undefined, ""};
|
||||
_ ->
|
||||
Vsn = slice(Tag, len(Pattern)),
|
||||
Vsn1 = trim(trim(Vsn, left, "v"), right, "\n"),
|
||||
{Tag, Vsn1}.
|
||||
{Tag, Vsn1}
|
||||
end.
|
||||
|
||||
-ifdef(unicode_str).
|
||||
len(Str) -> string:length(Str).
|
||||
trim(Str, right, Chars) -> string:trim(Str, trailing, Chars);
|
||||
trim(Str, left, Chars) -> string:trim(Str, leading, Chars);
|
||||
trim(Str, both, Chars) -> string:trim(Str, both, Chars).
|
||||
trim(Str, left, Chars) -> string:trim(Str, leading, Chars).
|
||||
slice(Str, Len) -> string:slice(Str, Len).
|
||||
-else.
|
||||
len(Str) -> string:len(Str).
|
||||
trim(Str, Dir, [Chars|_]) -> string:strip(Str, Dir, Chars).
|
||||
slice(Str, Len) -> string:substr(Str, Len + 1).
|
||||
-endif.
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
parse_tags_test() ->
|
||||
?assertEqual({undefined, ""}, parse_tags("a.b.c")).
|
||||
|
||||
get_patch_count_test() ->
|
||||
?assertEqual(0, get_patch_count("a.b.c")).
|
||||
|
||||
collect_default_refcount_test() ->
|
||||
?assertMatch({"", _, _}, collect_default_refcount("a.b.c")).
|
||||
-endif.
|
||||
|
|
|
@ -199,8 +199,6 @@ get_string(String) ->
|
|||
|
||||
-ifdef(unicode_str).
|
||||
trim(Str) -> string:trim(Str).
|
||||
trim(Str, right, Chars) -> string:trim(Str, trailing, Chars);
|
||||
trim(Str, left, Chars) -> string:trim(Str, leading, Chars);
|
||||
trim(Str, both, Chars) -> string:trim(Str, both, Chars).
|
||||
-else.
|
||||
trim(Str) -> string:strip(Str).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue