diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f76e374..49cfa50 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/.gitignore b/.gitignore index e8f4b5a..d306af0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,7 @@ _build erl_crash.dump *.pyc *~ +TEST-*.xml +/foo src/ec_semver_parser.peg diff --git a/src/ec_git_vsn.erl b/src/ec_git_vsn.erl index 569d78c..c932c58 100644 --- a/src/ec_git_vsn.erl +++ b/src/ec_git_vsn.erl @@ -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), - Vsn = slice(Tag, len(Pattern)), - Vsn1 = trim(trim(Vsn, left, "v"), right, "\n"), - {Tag, Vsn1}. + case Tag of + "fatal: " ++ _ -> + {undefined, ""}; + _ -> + Vsn = slice(Tag, len(Pattern)), + Vsn1 = trim(trim(Vsn, left, "v"), right, "\n"), + {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. diff --git a/src/ec_talk.erl b/src/ec_talk.erl index 36cff8e..454b1f8 100644 --- a/src/ec_talk.erl +++ b/src/ec_talk.erl @@ -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).