You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/09/18 15:43:47 UTC

[3/4] couch-log commit: updated refs/heads/master to fd40b31

Add tests and specs


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/commit/f3b894e6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/tree/f3b894e6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/diff/f3b894e6

Branch: refs/heads/master
Commit: f3b894e6f660243fc292256ae32a0f6925005fae
Parents: 4974126
Author: Eric Avdey <ei...@eiri.ca>
Authored: Thu Sep 17 18:07:44 2015 -0300
Committer: Eric Avdey <ei...@eiri.ca>
Committed: Fri Sep 18 10:36:00 2015 -0300

----------------------------------------------------------------------
 .gitignore        |  2 ++
 rebar.config      | 15 +++++++++++++++
 src/couch_log.erl | 45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/f3b894e6/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 3b66f4e..e24db8a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 /ebin
+.eunit
+.rebar

http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/f3b894e6/rebar.config
----------------------------------------------------------------------
diff --git a/rebar.config b/rebar.config
index e69de29..7104d3b 100644
--- a/rebar.config
+++ b/rebar.config
@@ -0,0 +1,15 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+{deps, [
+    {meck, ".*", {git, "https://git-wip-us.apache.org/repos/asf/couchdb-meck.git", {tag, "0.8.2"}}}
+]}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-log/blob/f3b894e6/src/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couch_log.erl b/src/couch_log.erl
index 3b5e4f9..0c10230 100644
--- a/src/couch_log.erl
+++ b/src/couch_log.erl
@@ -12,6 +12,10 @@
 
 -module(couch_log).
 
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+-endif.
+
 -export([debug/2, info/2, notice/2, warning/2, error/2, critical/2, alert/2, emergency/2]).
 -export([set_level/1]).
 
@@ -23,50 +27,60 @@ behaviour_info(callbacks) ->
 behaviour_info(_) ->
     undefined.
 
+-spec debug(string(), list()) -> ok.
 debug(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, debug]),
     Backend:debug(Fmt, Args).
 
+-spec info(string(), list()) -> ok.
 info(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, info]),
     Backend:info(Fmt, Args).
 
+-spec notice(string(), list()) -> ok.
 notice(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, notice]),
     Backend:notice(Fmt, Args).
 
+-spec warning(string(), list()) -> ok.
 warning(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, warning]),
     Backend:warning(Fmt, Args).
 
+-spec error(string(), list()) -> ok.
 error(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, 'error']),
     Backend:error(Fmt, Args).
 
+-spec critical(string(), list()) -> ok.
 critical(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, critical]),
     Backend:critical(Fmt, Args).
 
+-spec alert(string(), list()) -> ok.
 alert(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, alert]),
     Backend:alert(Fmt, Args).
 
+-spec emergency(string(), list()) -> ok.
 emergency(Fmt, Args) ->
     {ok, Backend} = get_backend(),
     catch couch_stats:increment_counter([couch_log, level, emergency]),
     Backend:emergency(Fmt, Args).
 
+-spec set_level(atom()) -> ok.
 set_level(Level) ->
     {ok, Backend} = application:get_env(?MODULE, backend),
     Backend:set_level(Level).
 
+-spec get_backend() -> {ok, atom()}.
 get_backend() ->
     case application:get_env(?MODULE, backend) of
         undefined ->
@@ -75,3 +89,34 @@ get_backend() ->
         {ok, Backend} ->
             {ok, Backend}
     end.
+
+
+-ifdef(TEST).
+
+callbacks_test_() ->
+    {setup,
+        fun setup/0,
+        fun cleanup/1,
+        [
+            ?_assertEqual({ok, couch_log_stderr}, get_backend()),
+            ?_assertEqual(ok, couch_log:debug("message", [])),
+            ?_assertEqual(ok, couch_log:info("message", [])),
+            ?_assertEqual(ok, couch_log:notice("message", [])),
+            ?_assertEqual(ok, couch_log:warning("message", [])),
+            ?_assertEqual(ok, couch_log:error("message", [])),
+            ?_assertEqual(ok, couch_log:critical("message", [])),
+            ?_assertEqual(ok, couch_log:alert("message", [])),
+            ?_assertEqual(ok, couch_log:emergency("message", [])),
+            ?_assertEqual(ok, couch_log:set_level(info))
+        ]
+    }.
+
+setup() ->
+    meck:new([couch_stats]),
+    meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
+    application:load(?MODULE).
+
+cleanup(_) ->
+    meck:unload([couch_stats]).
+
+-endif.