You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2021/11/17 14:16:03 UTC

[couchdb-b64url] branch erlfmt+dialyzer created (now b6ceef2)

This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a change to branch erlfmt+dialyzer
in repository https://gitbox.apache.org/repos/asf/couchdb-b64url.git.


      at b6ceef2  Format code with erlfmt, run dialyzer in CI

This branch includes the following new commits:

     new b6ceef2  Format code with erlfmt, run dialyzer in CI

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[couchdb-b64url] 01/01: Format code with erlfmt, run dialyzer in CI

Posted by ko...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a commit to branch erlfmt+dialyzer
in repository https://gitbox.apache.org/repos/asf/couchdb-b64url.git

commit b6ceef2deddaffc853beb3d04a8efc1277269df9
Author: Adam Kocoloski <ko...@apache.org>
AuthorDate: Wed Nov 17 09:15:19 2021 -0500

    Format code with erlfmt, run dialyzer in CI
---
 .github/workflows/ci.yml |   5 +++
 rebar.config             |   1 -
 src/b64url.erl           |  28 ++++---------
 test/b64url_tests.erl    | 106 +++++++++++++++++++++++------------------------
 4 files changed, 66 insertions(+), 74 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f41059e..c2428b1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -36,10 +36,15 @@ jobs:
       - name: Setup MSVC toolchain
         if: ${{ matrix.os == 'windows-latest' }}
         uses: ./.github/actions/msvc-dev-cmd
+      - name: Check coding style with erlfmt
+        if: ${{ matrix.os == 'ubuntu-latest' }}
+        run: rebar3 fmt --check
       - name: Compile
         run: rebar3 compile
       - name: EUnit tests
         run: rebar3 eunit
+      - name: Run dialyzer analysis
+        run: rebar3 as test dialyzer
       - name: Setup tmate session on job failure
         uses: ./.github/actions/tmate
         if: ${{ failure() }}
diff --git a/rebar.config b/rebar.config
index 83a227f..d9512ae 100644
--- a/rebar.config
+++ b/rebar.config
@@ -24,7 +24,6 @@
     % Production compilation
     {"(linux|solaris|darwin|freebsd)", "CFLAGS", "$CFLAGS -Wall -Werror -DNDEBUG -O3"},
     {"win32", "CFLAGS", "$CFLAGS /O2 /DNDEBUG /Wall"}
-
 ]}.
 
 {eunit_opts, [
diff --git a/src/b64url.erl b/src/b64url.erl
index 2eb4b82..6e6ddac 100644
--- a/src/b64url.erl
+++ b/src/b64url.erl
@@ -13,22 +13,18 @@
 -module(b64url).
 -on_load(init/0).
 
-
 -export([
     encode/1,
     decode/1
 ]).
 
-
 % Internal sanity checks
 -export([
     check_tables/0
 ]).
 
-
 -define(NOT_LOADED, not_loaded(?LINE)).
 
-
 -spec encode(iodata()) -> binary().
 encode(IoData) ->
     case encode_init(IoData) of
@@ -38,7 +34,6 @@ encode(IoData) ->
             encode_loop(IoData, St)
     end.
 
-
 -spec decode(iodata()) -> binary() | {error, any()}.
 decode(IoData) ->
     case decode_init(IoData) of
@@ -54,19 +49,18 @@ decode(IoData) ->
 check_tables() ->
     ?NOT_LOADED.
 
-
 init() ->
-    PrivDir = case code:priv_dir(?MODULE) of
-        {error, _} ->
-            EbinDir = filename:dirname(code:which(?MODULE)),
-            AppPath = filename:dirname(EbinDir),
-            filename:join(AppPath, "priv");
-        Path ->
-            Path
-    end,
+    PrivDir =
+        case code:priv_dir(?MODULE) of
+            {error, _} ->
+                EbinDir = filename:dirname(code:which(?MODULE)),
+                AppPath = filename:dirname(EbinDir),
+                filename:join(AppPath, "priv");
+            Path ->
+                Path
+        end,
     erlang:load_nif(filename:join(PrivDir, "b64url"), 0).
 
-
 encode_loop(IoData, St) ->
     case encode_cont(IoData, St) of
         {ok, Bin} ->
@@ -75,7 +69,6 @@ encode_loop(IoData, St) ->
             encode_loop(IoData, St)
     end.
 
-
 decode_loop(IoData, St) ->
     case decode_cont(IoData, St) of
         {ok, Bin} ->
@@ -86,13 +79,10 @@ decode_loop(IoData, St) ->
             decode_loop(IoData, St)
     end.
 
-
 encode_init(_) -> ?NOT_LOADED.
 encode_cont(_, _) -> ?NOT_LOADED.
 decode_init(_) -> ?NOT_LOADED.
 decode_cont(_, _) -> ?NOT_LOADED.
 
-
 not_loaded(Line) ->
     erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).
-
diff --git a/test/b64url_tests.erl b/test/b64url_tests.erl
index 27e69db..5e8e575 100644
--- a/test/b64url_tests.erl
+++ b/test/b64url_tests.erl
@@ -1,90 +1,93 @@
 -module(b64url_tests).
 
-
 -include_lib("eunit/include/eunit.hrl").
 
-
 -define(MAX_SIZE, 6401).
 -define(NUM_TESTS, 500).
 
-
 table_test() ->
     ?assertEqual(ok, b64url:check_tables()).
 
-
 encode_binary_test() ->
-    lists:foreach(fun(_) ->
-        Bin = gen_binary(),
-        A = couch_encode_base64url(Bin),
-        B = b64url:encode(Bin),
-        ?assertEqual(A, B)
-    end, lists:seq(1, ?NUM_TESTS)).
-
+    lists:foreach(
+        fun(_) ->
+            Bin = gen_binary(),
+            A = couch_encode_base64url(Bin),
+            B = b64url:encode(Bin),
+            ?assertEqual(A, B)
+        end,
+        lists:seq(1, ?NUM_TESTS)
+    ).
 
 encode_iolist_test() ->
-    lists:foreach(fun(_) ->
-        IoList = shallow_iolist(),
-        A = couch_encode_base64url(iolist_to_binary(IoList)),
-        B = b64url:encode(IoList),
-        ?assertEqual(A, B)
-    end, lists:seq(1, ?NUM_TESTS)).
-
+    lists:foreach(
+        fun(_) ->
+            IoList = shallow_iolist(),
+            A = couch_encode_base64url(iolist_to_binary(IoList)),
+            B = b64url:encode(IoList),
+            ?assertEqual(A, B)
+        end,
+        lists:seq(1, ?NUM_TESTS)
+    ).
 
 decode_binary_test() ->
-    lists:foreach(fun(_) ->
-        Bin = gen_binary(),
-        B64UrlBin = couch_encode_base64url(Bin),
-        Dec = b64url:decode(B64UrlBin),
-        ?assertEqual(Bin, Dec)
-    end, lists:seq(1, ?NUM_TESTS)).
-
+    lists:foreach(
+        fun(_) ->
+            Bin = gen_binary(),
+            B64UrlBin = couch_encode_base64url(Bin),
+            Dec = b64url:decode(B64UrlBin),
+            ?assertEqual(Bin, Dec)
+        end,
+        lists:seq(1, ?NUM_TESTS)
+    ).
 
 decode_iolist_test() ->
-    lists:foreach(fun(_) ->
-        IoList = shallow_b64_iolist(),
-        A = couch_decode_base64url(iolist_to_binary(IoList)),
-        B = b64url:decode(IoList),
-        ?assertEqual(A, B)
-    end, lists:seq(1, ?NUM_TESTS)).
-
+    lists:foreach(
+        fun(_) ->
+            IoList = shallow_b64_iolist(),
+            A = couch_decode_base64url(iolist_to_binary(IoList)),
+            B = b64url:decode(IoList),
+            ?assertEqual(A, B)
+        end,
+        lists:seq(1, ?NUM_TESTS)
+    ).
 
 decode_binary_error_test() ->
-    lists:foreach(fun(_) ->
-        {ErrBin, BlockPos} = bad_binary(),
-        Dec = b64url:decode(ErrBin),
-        ?assertEqual({error, {bad_block, BlockPos}}, Dec)
-    end, lists:seq(1, ?NUM_TESTS)).
-
+    lists:foreach(
+        fun(_) ->
+            {ErrBin, BlockPos} = bad_binary(),
+            Dec = b64url:decode(ErrBin),
+            ?assertEqual({error, {bad_block, BlockPos}}, Dec)
+        end,
+        lists:seq(1, ?NUM_TESTS)
+    ).
 
 decode_bad_length_test() ->
-    lists:foreach(fun(_) ->
-        Bin = bad_len_binary(),
-        ?assertError(badarg, b64url:decode(Bin))
-    end, lists:seq(1, ?NUM_TESTS)).
-
+    lists:foreach(
+        fun(_) ->
+            Bin = bad_len_binary(),
+            ?assertError(badarg, b64url:decode(Bin))
+        end,
+        lists:seq(1, ?NUM_TESTS)
+    ).
 
 gen_binary() ->
     % -1 to allow for 0 length
     Length = rand:uniform(?MAX_SIZE) - 1,
     crypto:strong_rand_bytes(Length).
 
-
 shallow_iolist() ->
     to_iolist(gen_binary()).
 
-
 shallow_b64_iolist() ->
     to_iolist(couch_encode_base64url(gen_binary())).
 
-
 bad_binary() ->
     insert_error(gen_binary()).
 
-
 bad_len_binary() ->
     make_bad_len(gen_binary()).
 
-
 to_iolist(<<>>) ->
     case rand:uniform(2) of
         1 -> <<>>;
@@ -98,11 +101,10 @@ to_iolist(B) when is_binary(B), size(B) > 0 ->
             [to_iolist(First), Second];
         2 ->
             [First, to_iolist(Second)];
-        3->
+        3 ->
             [First, Second]
     end.
 
-
 insert_error(B) when is_binary(B), size(B) < 2 ->
     case rand:uniform(2) of
         1 -> {<<122, 255>>, 0};
@@ -114,7 +116,6 @@ insert_error(B) when is_binary(B) ->
     <<First:S/binary, _:1/binary, Second/binary>> = B64,
     {<<First:S/binary, 255, Second/binary>>, 4 * (S div 4)}.
 
-
 make_bad_len(Bin) when size(Bin) rem 4 == 1 ->
     Bin;
 make_bad_len(Bin) when size(Bin) rem 4 == 2 ->
@@ -124,19 +125,16 @@ make_bad_len(Bin) when size(Bin) rem 4 == 3 ->
 make_bad_len(Bin) when size(Bin) rem 4 == 0 ->
     <<"A", Bin/binary>>.
 
-
 % These functions are copy/pasted from couch_util to avoid
 % the direct dependency. The goal of this project is to replace
 % these in couch_util anyway so when that happens they'll only
 % exist here for these tests.
 
-
 couch_encode_base64url(Url) ->
     Url1 = iolist_to_binary(re:replace(base64:encode(Url), "=+$", "")),
     Url2 = iolist_to_binary(re:replace(Url1, "/", "_", [global])),
     iolist_to_binary(re:replace(Url2, "\\+", "-", [global])).
 
-
 couch_decode_base64url(Url64) ->
     Url1 = re:replace(iolist_to_binary(Url64), "-", "+", [global]),
     Url2 = iolist_to_binary(