From 113323380ffd8232c9c5bb6e0f53eaa2d86c5941 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 16:00:48 -0300 Subject: [PATCH 01/14] Added include file from couchdb-couch to get the project to compile --- .gitignore | 18 ++++++++++ include/couch_eunit.hrl | 73 +++++++++++++++++++++++++++++++++++++++++ rebar.config | 19 +++++++++++ test/config_tests.erl | 3 +- 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 include/couch_eunit.hrl create mode 100644 rebar.config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..08cc530 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +relx +_rel/ +.erlang.mk/ +db +Mnesia* +ebin +deps +doc +examples/blog/log +.eunit +*.o +*.beam +*.plt +.rebar +log*/ +erl_crash.dump +.erlang.mk.* +tmp/ diff --git a/include/couch_eunit.hrl b/include/couch_eunit.hrl new file mode 100644 index 0000000..41957e8 --- /dev/null +++ b/include/couch_eunit.hrl @@ -0,0 +1,73 @@ +% 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. + +-include_lib("eunit/include/eunit.hrl"). + +-define(BUILDDIR, + fun() -> + case os:getenv("BUILDDIR") of + false -> + throw("BUILDDIR environment variable must be set"); + Dir -> + Dir + end + end). +-define(CONFIG_DEFAULT, + filename:join([?BUILDDIR(), "tmp", "etc", "default_eunit.ini"])). +-define(CONFIG_CHAIN, [ + ?CONFIG_DEFAULT, + filename:join([?BUILDDIR(), "tmp", "etc", "local_eunit.ini"]), + filename:join([?BUILDDIR(), "tmp", "etc", "eunit.ini"])]). +-define(FIXTURESDIR, + filename:join([?BUILDDIR(), "src", "couch", "test", "fixtures"])). +-define(TEMPDIR, + filename:join([?BUILDDIR(), "tmp", "tmp_data"])). + +-define(tempfile, + fun() -> + {A, B, C} = erlang:now(), + N = node(), + FileName = lists:flatten(io_lib:format("~p-~p.~p.~p", [N, A, B, C])), + filename:join([?TEMPDIR, FileName]) + end). +-define(tempdb, + fun() -> + Nums = tuple_to_list(erlang:now()), + Prefix = "eunit-test-db", + Suffix = lists:concat([integer_to_list(Num) || Num <- Nums]), + list_to_binary(Prefix ++ "-" ++ Suffix) + end). +-define(docid, + fun() -> + {A, B, C} = erlang:now(), + lists:flatten(io_lib:format("~p~p~p", [A, B, C])) + end). + +%% Borrowed from https://github.com/richcarl/eunit/blob/master/include/eunit.hrl#L200-L219 +%% TODO: get rid of this once R14* is no longer supported +-ifndef(assertNotMatch). +-define(assertNotMatch(Guard, Expr), + begin + ((fun () -> + __V = (Expr), + case __V of + Guard -> erlang:error({assertNotMatch_failed, + [{module, ?MODULE}, + {line, ?LINE}, + {expression, (??Expr)}, + {pattern, (??Guard)}, + {value, __V}]}); + _ -> ok + end + end)()) + end). +-endif. diff --git a/rebar.config b/rebar.config new file mode 100644 index 0000000..dc67418 --- /dev/null +++ b/rebar.config @@ -0,0 +1,19 @@ +{erl_opts, [{src_dirs, ["src", "test"]}, + {inlcude, ["inlcude"]}, + warn_unused_vars, + warn_export_all, + warn_shadow_vars, + warn_unused_import, + warn_unused_function, + warn_bif_clash, + warn_unused_record, + warn_deprecated_function, + warn_obsolete_guard, + strict_validation, + warn_export_vars, + warn_exported_vars, +% warn_missing_spec, + debug_info]}. +{eunit_opts, [verbose]}. +{xref_warnings, true}. +{xref_checks, [undefined_function_calls, locals_not_used, deprecated_function_calls]}. diff --git a/test/config_tests.erl b/test/config_tests.erl index c823d3e..0f4623a 100644 --- a/test/config_tests.erl +++ b/test/config_tests.erl @@ -16,8 +16,7 @@ -export([handle_config_change/5, handle_config_terminate/3]). --include_lib("couch/include/couch_eunit.hrl"). --include_lib("couch/include/couch_db.hrl"). +-include("couch_eunit.hrl"). -define(SHORT_TIMEOUT, 100). -define(TIMEOUT, 1000). From 30990ed5cd69a655a2cf8a892db0ec47d61c4e6c Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 16:02:48 -0300 Subject: [PATCH 02/14] Fixed module dependencies with couchdb-couch and also many DEPS were not actual deps :) --- src/config.app.src | 2 +- src/config.erl | 14 +++++++------- test/config_tests.erl | 13 +++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/config.app.src b/src/config.app.src index 7f8eef6..e0a1acd 100644 --- a/src/config.app.src +++ b/src/config.app.src @@ -17,6 +17,6 @@ config, config_event ]}, - {applications, [kernel, stdlib]}, + {applications, [kernel, stdlib, syntax_tools, compiler]}, {mod, {config_app, []}} ]}. diff --git a/src/config.erl b/src/config.erl index 8e79296..817244c 100644 --- a/src/config.erl +++ b/src/config.erl @@ -208,7 +208,7 @@ handle_call(all, _From, Config) -> {reply, Resp, Config}; handle_call({set, Sec, Key, Val, Persist, Reason}, _From, Config) -> true = ets:insert(?MODULE, {{Sec, Key}, Val}), - couch_log:notice("~p: [~s] ~s set to ~s for reason ~p", + error_logger:info_msg("~p: [~s] ~s set to ~s for reason ~p", [?MODULE, Sec, Key, Val, Reason]), case {Persist, Config#config.write_filename} of {true, undefined} -> @@ -223,7 +223,7 @@ handle_call({set, Sec, Key, Val, Persist, Reason}, _From, Config) -> {reply, ok, Config}; handle_call({delete, Sec, Key, Persist, Reason}, _From, Config) -> true = ets:delete(?MODULE, {Sec,Key}), - couch_log:notice("~p: [~s] ~s deleted for reason ~p", + error_logger:info_msg("~p: [~s] ~s deleted for reason ~p", [?MODULE, Sec, Key, Reason]), case {Persist, Config#config.write_filename} of {true, undefined} -> @@ -270,16 +270,16 @@ handle_cast(_Msg, State) -> {noreply, State}. handle_info({gen_event_EXIT, {config_listener, Module}, shutdown}, State) -> - couch_log:notice("config_listener(~p) stopped with reason: shutdown~n", [Module]), + error_logger:info_msg("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, normal}, State) -> - couch_log:info("config_listener(~p) stopped with reason: shutdown~n", [Module]), + error_logger:info_msg("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, Reason}, State) -> - couch_log:error("config_listener(~p) stopped with reason: ~p~n", [Module, Reason]), + error_logger:info_msg("config_listener(~p) stopped with reason: ~p~n", [Module, Reason]), {noreply, State}; handle_info(Info, State) -> - couch_log:error("config:handle_info Info: ~p~n", [Info]), + error_logger:info_msg("config:handle_info Info: ~p~n", [Info]), {noreply, State}. code_change(_OldVsn, State, _Extra) -> @@ -295,7 +295,7 @@ parse_ini_file(IniFile) -> {error, enoent} -> Fmt = "Couldn't find server configuration file ~s.", Msg = list_to_binary(io_lib:format(Fmt, [IniFilename])), - couch_log:error("~s~n", [Msg]), + error_logger:error_msg("~s~n", [Msg]), throw({startup_error, Msg}) end, diff --git a/test/config_tests.erl b/test/config_tests.erl index 0f4623a..24783aa 100644 --- a/test/config_tests.erl +++ b/test/config_tests.erl @@ -36,10 +36,6 @@ FileName end). --define(DEPS, [couch_stats, couch_log, folsom, lager, - goldrush, syntax_tools, compiler, config]). - - setup() -> setup(?CONFIG_CHAIN). setup({temporary, Chain}) -> @@ -48,7 +44,8 @@ setup({persistent, Chain}) -> setup(lists:append(Chain, [?CONFIG_FIXTURE_TEMP])); setup(Chain) -> ok = application:set_env(config, ini_files, Chain), - test_util:start_applications(?DEPS). + {ok, _} = application:ensure_all_started(config), + ok. setup_empty() -> setup([]). @@ -61,12 +58,12 @@ setup_config_listener() -> teardown({Pid, _}) -> stop_listener(Pid), - [application:stop(App) || App <- ?DEPS]; + application:stop(config); teardown(_) -> - [application:stop(App) || App <- ?DEPS]. + application:stop(config). teardown(_, _) -> - [application:stop(App) || App <- ?DEPS]. + application:stop(config). handle_config_change("remove_handler", _Key, _Value, _Persist, _State) -> remove_handler; From e037fea641bd75a6d3cc56bc9325f3a5dea2183d Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 16:05:07 -0300 Subject: [PATCH 03/14] added Makefile to make our lives easier :P and also fixed the tests by: - fixing the CONFIG_FIXTURESDIR path - ensuring that required dirs are created before creating a file in them - adding a default_eunit.ini file - making sure some required files are there before starting the tests --- Makefile | 27 +++++++++++++++++++++++++++ test/config_tests.erl | 5 +++-- test/fixtures/default_eunit.ini | 29 +++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 test/fixtures/default_eunit.ini diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1c67004 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +export BUILDDIR ?= /Users/elbrujohalcon/Projects/inaka/couchdb-config + +REBAR ?= rebar -vvv + +.PHONY: all app clean test shell xref + +all: + ${REBAR} get compile + +app: + ${REBAR} skip_deps=true compile + +clean: app + ${REBAR} clean + +test: app + mkdir -p tmp/etc; + cp test/fixtures/default_eunit.ini tmp/etc/default_eunit.ini; + touch tmp/etc/local_eunit.ini; + touch tmp/etc/eunit.ini; + ${REBAR} eunit + +shell: all + erl -pa deps/*/ebin `pwd`/ebin -boot start_sasl + +xref: app + ${REBAR} xref diff --git a/test/config_tests.erl b/test/config_tests.erl index 24783aa..d178751 100644 --- a/test/config_tests.erl +++ b/test/config_tests.erl @@ -22,7 +22,7 @@ -define(TIMEOUT, 1000). -define(CONFIG_FIXTURESDIR, - filename:join([?BUILDDIR(), "src", "config", "test", "fixtures"])). + filename:join([?BUILDDIR(), "test", "fixtures"])). -define(CONFIG_FIXTURE_1, filename:join([?CONFIG_FIXTURESDIR, "config_tests_1.ini"])). -define(CONFIG_FIXTURE_2, @@ -30,6 +30,7 @@ -define(CONFIG_FIXTURE_TEMP, begin FileName = filename:join([?TEMPDIR, "config_temp.ini"]), + ok = filelib:ensure_dir(FileName), {ok, Fd} = file:open(FileName, write), ok = file:truncate(Fd), ok = file:close(Fd), @@ -236,7 +237,7 @@ should_return_custom_default_value_on_missed_option() -> config:get("httpd", "foo", "bar")). should_only_return_default_on_missed_option() -> - ?_assertEqual("0", + ?_assertEqual("5986", config:get("httpd", "port", "bar")). should_fail_to_get_binary_value() -> diff --git a/test/fixtures/default_eunit.ini b/test/fixtures/default_eunit.ini new file mode 100644 index 0000000..7b8ec1e --- /dev/null +++ b/test/fixtures/default_eunit.ini @@ -0,0 +1,29 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; to you 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. + +[couchdb] +max_dbs_open=500 + +[httpd] +port=5986 +bind_address=127.0.0.1 + +[httpd_design_handlers] +_view={couch_mrview_http, handle_view_req} + +[daemons] +names=Beelzebub,Satan From 7a27a4a8d8b4a5f3bc5d3a23441c124d7b9d5b69 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 16:17:04 -0300 Subject: [PATCH 04/14] Missing license headers and hardcoded path --- Makefile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1c67004..28a4b99 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,15 @@ -export BUILDDIR ?= /Users/elbrujohalcon/Projects/inaka/couchdb-config +# 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. +export BUILDDIR ?= .. REBAR ?= rebar -vvv From cbc03cf96c6f576d92f8c7a75787a19c0c352d2f Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 16:21:51 -0300 Subject: [PATCH 05/14] Fixed port number to use a random one for tests --- test/config_tests.erl | 8 ++++---- test/fixtures/default_eunit.ini | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/config_tests.erl b/test/config_tests.erl index d178751..3cfc108 100644 --- a/test/config_tests.erl +++ b/test/config_tests.erl @@ -237,7 +237,7 @@ should_return_custom_default_value_on_missed_option() -> config:get("httpd", "foo", "bar")). should_only_return_default_on_missed_option() -> - ?_assertEqual("5986", + ?_assertEqual("0", config:get("httpd", "port", "bar")). should_fail_to_get_binary_value() -> @@ -284,7 +284,7 @@ should_ensure_in_defaults(_, _) -> ?_test(begin ?assertEqual("500", config:get("couchdb", "max_dbs_open")), - ?assertEqual("5986", + ?assertEqual("0", config:get("httpd", "port")), ?assertEqual(undefined, config:get("fizbang", "unicode")) @@ -311,7 +311,7 @@ should_win_last_in_chain(_, _) -> should_write_changes(_, _) -> ?_test(begin - ?assertEqual("5986", + ?assertEqual("0", config:get("httpd", "port")), ?assertEqual(ok, config:set("httpd", "port", "8080")), @@ -325,7 +325,7 @@ should_write_changes(_, _) -> should_ensure_that_default_wasnt_modified(_, _) -> ?_test(begin - ?assertEqual("5986", + ?assertEqual("0", config:get("httpd", "port")), ?assertEqual("127.0.0.1", config:get("httpd", "bind_address")) diff --git a/test/fixtures/default_eunit.ini b/test/fixtures/default_eunit.ini index 7b8ec1e..cae9881 100644 --- a/test/fixtures/default_eunit.ini +++ b/test/fixtures/default_eunit.ini @@ -19,7 +19,7 @@ max_dbs_open=500 [httpd] -port=5986 +port=0 bind_address=127.0.0.1 [httpd_design_handlers] From 74ce41d9e839012f6c3dea650259f683986fb6b0 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 16:31:36 -0300 Subject: [PATCH 06/14] Using couch_log instead of error_logger --- Makefile | 2 +- rebar.config | 5 +++++ src/config.erl | 14 +++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 28a4b99..bef80a2 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ # the License. export BUILDDIR ?= .. -REBAR ?= rebar -vvv +REBAR ?= rebar .PHONY: all app clean test shell xref diff --git a/rebar.config b/rebar.config index dc67418..debd900 100644 --- a/rebar.config +++ b/rebar.config @@ -1,3 +1,8 @@ +{deps, [ + {couch_log, ".*", + {git, "https://github.com/apache/couchdb-couch-log.git", + "275043ea"}} +]}. {erl_opts, [{src_dirs, ["src", "test"]}, {inlcude, ["inlcude"]}, warn_unused_vars, diff --git a/src/config.erl b/src/config.erl index 817244c..84ed0da 100644 --- a/src/config.erl +++ b/src/config.erl @@ -208,7 +208,7 @@ handle_call(all, _From, Config) -> {reply, Resp, Config}; handle_call({set, Sec, Key, Val, Persist, Reason}, _From, Config) -> true = ets:insert(?MODULE, {{Sec, Key}, Val}), - error_logger:info_msg("~p: [~s] ~s set to ~s for reason ~p", + couch_log:notice("~p: [~s] ~s set to ~s for reason ~p", [?MODULE, Sec, Key, Val, Reason]), case {Persist, Config#config.write_filename} of {true, undefined} -> @@ -223,7 +223,7 @@ handle_call({set, Sec, Key, Val, Persist, Reason}, _From, Config) -> {reply, ok, Config}; handle_call({delete, Sec, Key, Persist, Reason}, _From, Config) -> true = ets:delete(?MODULE, {Sec,Key}), - error_logger:info_msg("~p: [~s] ~s deleted for reason ~p", + couch_log:notice("~p: [~s] ~s deleted for reason ~p", [?MODULE, Sec, Key, Reason]), case {Persist, Config#config.write_filename} of {true, undefined} -> @@ -270,16 +270,16 @@ handle_cast(_Msg, State) -> {noreply, State}. handle_info({gen_event_EXIT, {config_listener, Module}, shutdown}, State) -> - error_logger:info_msg("config_listener(~p) stopped with reason: shutdown~n", [Module]), + couch_log:notice("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, normal}, State) -> - error_logger:info_msg("config_listener(~p) stopped with reason: shutdown~n", [Module]), + couch_log:notice("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, Reason}, State) -> - error_logger:info_msg("config_listener(~p) stopped with reason: ~p~n", [Module, Reason]), + couch_log:notice("config_listener(~p) stopped with reason: ~p~n", [Module, Reason]), {noreply, State}; handle_info(Info, State) -> - error_logger:info_msg("config:handle_info Info: ~p~n", [Info]), + couch_log:notice("config:handle_info Info: ~p~n", [Info]), {noreply, State}. code_change(_OldVsn, State, _Extra) -> @@ -295,7 +295,7 @@ parse_ini_file(IniFile) -> {error, enoent} -> Fmt = "Couldn't find server configuration file ~s.", Msg = list_to_binary(io_lib:format(Fmt, [IniFilename])), - error_logger:error_msg("~s~n", [Msg]), + couch_log:error("~s~n", [Msg]), throw({startup_error, Msg}) end, From 9ea376ce8bf329d43959510ba81684f7499db6f7 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 16:42:10 -0300 Subject: [PATCH 07/14] Using master branch and ASF git repo --- rebar.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index debd900..85a0bbc 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,7 @@ {deps, [ {couch_log, ".*", - {git, "https://github.com/apache/couchdb-couch-log.git", - "275043ea"}} + {git, "https://git-wip-us.apache.org/repos/asf/couchdb-couch-log.git", + {branch, "master"}}} ]}. {erl_opts, [{src_dirs, ["src", "test"]}, {inlcude, ["inlcude"]}, From 141475bcb7c613feff64dda18a51028780755a66 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 17:00:40 -0300 Subject: [PATCH 08/14] Tests should not be compiled with the actual code --- rebar.config | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index 85a0bbc..fe57425 100644 --- a/rebar.config +++ b/rebar.config @@ -3,8 +3,7 @@ {git, "https://git-wip-us.apache.org/repos/asf/couchdb-couch-log.git", {branch, "master"}}} ]}. -{erl_opts, [{src_dirs, ["src", "test"]}, - {inlcude, ["inlcude"]}, +{erl_opts, [{inlcude, ["inlcude"]}, warn_unused_vars, warn_export_all, warn_shadow_vars, From 58812e822ddab8dec6afc4d5854881b6dd23cc77 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 17:04:46 -0300 Subject: [PATCH 09/14] make test -> make check --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bef80a2..06b679a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ export BUILDDIR ?= .. REBAR ?= rebar -.PHONY: all app clean test shell xref +.PHONY: all app clean check shell xref all: ${REBAR} get compile @@ -24,7 +24,7 @@ app: clean: app ${REBAR} clean -test: app +check: app mkdir -p tmp/etc; cp test/fixtures/default_eunit.ini tmp/etc/default_eunit.ini; touch tmp/etc/local_eunit.ini; From 5a4888ab8c304aea24834f628feaf7d89137f943 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 17:52:45 -0300 Subject: [PATCH 10/14] Fixing errors detected by @chewbranca --- rebar.config | 3 +-- src/config.erl | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/rebar.config b/rebar.config index fe57425..c0b3020 100644 --- a/rebar.config +++ b/rebar.config @@ -3,8 +3,7 @@ {git, "https://git-wip-us.apache.org/repos/asf/couchdb-couch-log.git", {branch, "master"}}} ]}. -{erl_opts, [{inlcude, ["inlcude"]}, - warn_unused_vars, +{erl_opts, [warn_unused_vars, warn_export_all, warn_shadow_vars, warn_unused_import, diff --git a/src/config.erl b/src/config.erl index 84ed0da..4860243 100644 --- a/src/config.erl +++ b/src/config.erl @@ -273,13 +273,13 @@ handle_info({gen_event_EXIT, {config_listener, Module}, shutdown}, State) -> couch_log:notice("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, normal}, State) -> - couch_log:notice("config_listener(~p) stopped with reason: shutdown~n", [Module]), + couch_log:error("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, Reason}, State) -> - couch_log:notice("config_listener(~p) stopped with reason: ~p~n", [Module, Reason]), + couch_log:error("config_listener(~p) stopped with reason: ~p~n", [Module, Reason]), {noreply, State}; handle_info(Info, State) -> - couch_log:notice("config:handle_info Info: ~p~n", [Info]), + couch_log:error("config:handle_info Info: ~p~n", [Info]), {noreply, State}. code_change(_OldVsn, State, _Extra) -> From 19a17904723eed7b7331cc966007450df027538b Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 17:57:10 -0300 Subject: [PATCH 11/14] no more couch_eunit.hrl --- include/couch_eunit.hrl | 73 ----------------------------------------- test/config_tests.erl | 20 ++++++++++- 2 files changed, 19 insertions(+), 74 deletions(-) delete mode 100644 include/couch_eunit.hrl diff --git a/include/couch_eunit.hrl b/include/couch_eunit.hrl deleted file mode 100644 index 41957e8..0000000 --- a/include/couch_eunit.hrl +++ /dev/null @@ -1,73 +0,0 @@ -% 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. - --include_lib("eunit/include/eunit.hrl"). - --define(BUILDDIR, - fun() -> - case os:getenv("BUILDDIR") of - false -> - throw("BUILDDIR environment variable must be set"); - Dir -> - Dir - end - end). --define(CONFIG_DEFAULT, - filename:join([?BUILDDIR(), "tmp", "etc", "default_eunit.ini"])). --define(CONFIG_CHAIN, [ - ?CONFIG_DEFAULT, - filename:join([?BUILDDIR(), "tmp", "etc", "local_eunit.ini"]), - filename:join([?BUILDDIR(), "tmp", "etc", "eunit.ini"])]). --define(FIXTURESDIR, - filename:join([?BUILDDIR(), "src", "couch", "test", "fixtures"])). --define(TEMPDIR, - filename:join([?BUILDDIR(), "tmp", "tmp_data"])). - --define(tempfile, - fun() -> - {A, B, C} = erlang:now(), - N = node(), - FileName = lists:flatten(io_lib:format("~p-~p.~p.~p", [N, A, B, C])), - filename:join([?TEMPDIR, FileName]) - end). --define(tempdb, - fun() -> - Nums = tuple_to_list(erlang:now()), - Prefix = "eunit-test-db", - Suffix = lists:concat([integer_to_list(Num) || Num <- Nums]), - list_to_binary(Prefix ++ "-" ++ Suffix) - end). --define(docid, - fun() -> - {A, B, C} = erlang:now(), - lists:flatten(io_lib:format("~p~p~p", [A, B, C])) - end). - -%% Borrowed from https://github.com/richcarl/eunit/blob/master/include/eunit.hrl#L200-L219 -%% TODO: get rid of this once R14* is no longer supported --ifndef(assertNotMatch). --define(assertNotMatch(Guard, Expr), - begin - ((fun () -> - __V = (Expr), - case __V of - Guard -> erlang:error({assertNotMatch_failed, - [{module, ?MODULE}, - {line, ?LINE}, - {expression, (??Expr)}, - {pattern, (??Guard)}, - {value, __V}]}); - _ -> ok - end - end)()) - end). --endif. diff --git a/test/config_tests.erl b/test/config_tests.erl index 3cfc108..39ac0fe 100644 --- a/test/config_tests.erl +++ b/test/config_tests.erl @@ -16,7 +16,25 @@ -export([handle_config_change/5, handle_config_terminate/3]). --include("couch_eunit.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +-define(BUILDDIR, + fun() -> + case os:getenv("BUILDDIR") of + false -> + throw("BUILDDIR environment variable must be set"); + Dir -> + Dir + end + end). +-define(CONFIG_DEFAULT, + filename:join([?BUILDDIR(), "tmp", "etc", "default_eunit.ini"])). +-define(CONFIG_CHAIN, [ + ?CONFIG_DEFAULT, + filename:join([?BUILDDIR(), "tmp", "etc", "local_eunit.ini"]), + filename:join([?BUILDDIR(), "tmp", "etc", "eunit.ini"])]). +-define(TEMPDIR, + filename:join([?BUILDDIR(), "tmp", "tmp_data"])). -define(SHORT_TIMEOUT, 100). -define(TIMEOUT, 1000). From 995c249afc0426b0d92d5a89a23970f49bfe98c7 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 18:03:48 -0300 Subject: [PATCH 12/14] Now actually fixing the errors detected by @chewbranca --- src/config.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.erl b/src/config.erl index 4860243..8e79296 100644 --- a/src/config.erl +++ b/src/config.erl @@ -273,7 +273,7 @@ handle_info({gen_event_EXIT, {config_listener, Module}, shutdown}, State) -> couch_log:notice("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, normal}, State) -> - couch_log:error("config_listener(~p) stopped with reason: shutdown~n", [Module]), + couch_log:info("config_listener(~p) stopped with reason: shutdown~n", [Module]), {noreply, State}; handle_info({gen_event_EXIT, {config_listener, Module}, Reason}, State) -> couch_log:error("config_listener(~p) stopped with reason: ~p~n", [Module, Reason]), From f0dff7562abfbe95c9bea302f9f0849ad8ff5b2d Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 18 Jun 2015 18:09:40 -0300 Subject: [PATCH 13/14] Starting couch_log instead of just letting it silently fail. For this commit to work, apache/couchdb-lager#1 must be merged first --- src/config.app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.app.src b/src/config.app.src index e0a1acd..9b0ddc7 100644 --- a/src/config.app.src +++ b/src/config.app.src @@ -17,6 +17,6 @@ config, config_event ]}, - {applications, [kernel, stdlib, syntax_tools, compiler]}, + {applications, [kernel, stdlib, couch_log, syntax_tools, compiler]}, {mod, {config_app, []}} ]}. From e0335c939ac54711411e5e583b89b76a6452a407 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Fri, 19 Jun 2015 09:25:14 -0300 Subject: [PATCH 14/14] .gitignore trimming --- .gitignore | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.gitignore b/.gitignore index 08cc530..40a7f0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,6 @@ -relx -_rel/ -.erlang.mk/ -db -Mnesia* ebin deps doc -examples/blog/log .eunit *.o *.beam @@ -14,5 +8,4 @@ examples/blog/log .rebar log*/ erl_crash.dump -.erlang.mk.* tmp/