Simplify os_daemon_configer.escript There is no need to start couch_config, init code paths and include anything, just need to make ejson beams available.
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/73c33122 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/73c33122 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/73c33122 Branch: refs/heads/1963-eunit Commit: 73c331228bc396cc2aac08d5a84175336118b783 Parents: 62f0560 Author: Alexander Shorin <[email protected]> Authored: Mon Jun 23 01:33:06 2014 +0400 Committer: Alexander Shorin <[email protected]> Committed: Mon Jun 23 15:55:44 2014 +0400 ---------------------------------------------------------------------- .gitignore | 1 + configure.ac | 1 + test/couchdb/couchdb_os_daemons_tests.erl | 6 +- test/couchdb/fixtures/Makefile.am | 5 + .../couchdb/fixtures/os_daemon_configer.escript | 101 ------------------- .../fixtures/os_daemon_configer.escript.in | 84 +++++++++++++++ 6 files changed, 96 insertions(+), 102 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/73c33122/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 236aa5d..8991d29 100644 --- a/.gitignore +++ b/.gitignore @@ -131,6 +131,7 @@ test/bench/run test/couchdb/run test/couchdb/include/couch_eunit.hrl test/couchdb/fixtures/.deps/ +test/couchdb/fixtures/os_daemon_configer.escript test/javascript/run test/javascript/run_js_tests.sh test/local.ini http://git-wip-us.apache.org/repos/asf/couchdb/blob/73c33122/configure.ac ---------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index 5aba06a..9dbbdd2 100644 --- a/configure.ac +++ b/configure.ac @@ -756,6 +756,7 @@ AC_CONFIG_FILES([test/couchdb/run]) AC_CONFIG_FILES([test/couchdb/Makefile]) AC_CONFIG_FILES([test/couchdb/include/couch_eunit.hrl]) AC_CONFIG_FILES([test/couchdb/fixtures/Makefile]) +AC_CONFIG_FILES([test/couchdb/fixtures/os_daemon_configer.escript]) AC_CONFIG_FILES([test/javascript/Makefile]) AC_CONFIG_FILES([test/view_server/Makefile]) AC_CONFIG_FILES([utils/Makefile]) http://git-wip-us.apache.org/repos/asf/couchdb/blob/73c33122/test/couchdb/couchdb_os_daemons_tests.erl ---------------------------------------------------------------------- diff --git a/test/couchdb/couchdb_os_daemons_tests.erl b/test/couchdb/couchdb_os_daemons_tests.erl index 1058a78..ed9b6e8 100644 --- a/test/couchdb/couchdb_os_daemons_tests.erl +++ b/test/couchdb/couchdb_os_daemons_tests.erl @@ -34,6 +34,8 @@ -define(DAEMON_DIE_QUICKLY, "os_daemon_die_quickly.sh"). -define(DAEMON_CFGREG, "test_cfg_register"). -define(DELAY, 100). +-define(FIXTURES_BUILDDIR, + filename:join([?BUILDDIR, "test", "couchdb", "fixtures"])). -define(TIMEOUT, 1000). @@ -42,7 +44,9 @@ setup(DName) -> {ok, OsDPid} = couch_os_daemons:start_link(), Path = case DName of ?DAEMON_CFGREG -> - filename:join([?BUILDDIR, "test", "couchdb", "fixtures", DName]); + filename:join([?FIXTURES_BUILDDIR, DName]); + ?DAEMON_CONFIGER -> + filename:join([?FIXTURES_BUILDDIR, DName]); _ -> filename:join([?FIXTURESDIR, DName]) end, http://git-wip-us.apache.org/repos/asf/couchdb/blob/73c33122/test/couchdb/fixtures/Makefile.am ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/Makefile.am b/test/couchdb/fixtures/Makefile.am index 1273234..fa38d3f 100644 --- a/test/couchdb/fixtures/Makefile.am +++ b/test/couchdb/fixtures/Makefile.am @@ -13,3 +13,8 @@ noinst_PROGRAMS = test_cfg_register test_cfg_register_SOURCES = test_cfg_register.c test_cfg_register_CFLAGS = -D_BSD_SOURCE + +noinst_SCRIPTS = os_daemon_configer.escript + +all: + chmod +x os_daemon_configer.escript http://git-wip-us.apache.org/repos/asf/couchdb/blob/73c33122/test/couchdb/fixtures/os_daemon_configer.escript ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/os_daemon_configer.escript b/test/couchdb/fixtures/os_daemon_configer.escript deleted file mode 100755 index d437423..0000000 --- a/test/couchdb/fixtures/os_daemon_configer.escript +++ /dev/null @@ -1,101 +0,0 @@ -#! /usr/bin/env escript - -% 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("../couch_eunit.hrl"). - - -read() -> - case io:get_line('') of - eof -> - stop; - Data -> - ejson:decode(Data) - end. - -write(Mesg) -> - Data = iolist_to_binary(ejson:encode(Mesg)), - io:format(binary_to_list(Data) ++ "\n", []). - -get_cfg(Section) -> - write([<<"get">>, Section]), - read(). - -get_cfg(Section, Name) -> - write([<<"get">>, Section, Name]), - read(). - -log(Mesg) -> - write([<<"log">>, Mesg]). - -log(Mesg, Level) -> - write([<<"log">>, Mesg, {[{<<"level">>, Level}]}]). - -test_get_cfg1() -> - Path = list_to_binary(?FILE), - FileName = list_to_binary(filename:basename(?FILE)), - {[{FileName, Path}]} = get_cfg(<<"os_daemons">>). - -test_get_cfg2() -> - Path = list_to_binary(?FILE), - FileName = list_to_binary(filename:basename(?FILE)), - Path = get_cfg(<<"os_daemons">>, FileName), - <<"sequential">> = get_cfg(<<"uuids">>, <<"algorithm">>). - - -test_get_unknown_cfg() -> - {[]} = get_cfg(<<"aal;3p4">>), - null = get_cfg(<<"aal;3p4">>, <<"313234kjhsdfl">>). - -test_log() -> - log(<<"foobar!">>), - log(<<"some stuff!">>, <<"debug">>), - log(2), - log(true), - write([<<"log">>, <<"stuff">>, 2]), - write([<<"log">>, 3, null]), - write([<<"log">>, [1, 2], {[{<<"level">>, <<"debug">>}]}]), - write([<<"log">>, <<"true">>, {[]}]). - -do_tests() -> - test_get_cfg1(), - test_get_cfg2(), - test_get_unknown_cfg(), - test_log(), - loop(io:read("")). - -loop({ok, _}) -> - loop(io:read("")); -loop(eof) -> - init:stop(); -loop({error, _Reason}) -> - init:stop(). - -main([]) -> - init_code_path(), - couch_config:start_link(?CONFIG_CHAIN), - couch_drv:start_link(), - do_tests(). - -init_code_path() -> - Paths = [ - "couchdb", - "ejson", - "erlang-oauth", - "ibrowse", - "mochiweb", - "snappy" - ], - lists:foreach(fun(Name) -> - code:add_patha(filename:join([?BUILDDIR, "src", Name])) - end, Paths). http://git-wip-us.apache.org/repos/asf/couchdb/blob/73c33122/test/couchdb/fixtures/os_daemon_configer.escript.in ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/os_daemon_configer.escript.in b/test/couchdb/fixtures/os_daemon_configer.escript.in new file mode 100755 index 0000000..d2ecfa8 --- /dev/null +++ b/test/couchdb/fixtures/os_daemon_configer.escript.in @@ -0,0 +1,84 @@ +#! /usr/bin/env escript +%% -*- erlang -*- +%%! -DTEST -pa @abs_top_builddir@/src/ejson +%% +%% 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. + +read() -> + case io:get_line('') of + eof -> + stop; + Data -> + ejson:decode(Data) + end. + +write(Mesg) -> + Data = iolist_to_binary(ejson:encode(Mesg)), + io:format(binary_to_list(Data) ++ "\n", []). + +get_cfg(Section) -> + write([<<"get">>, Section]), + read(). + +get_cfg(Section, Name) -> + write([<<"get">>, Section, Name]), + read(). + +log(Mesg) -> + write([<<"log">>, Mesg]). + +log(Mesg, Level) -> + write([<<"log">>, Mesg, {[{<<"level">>, Level}]}]). + +test_get_cfg1() -> + Path = list_to_binary(?FILE), + FileName = list_to_binary(filename:basename(?FILE)), + {[{FileName, Path}]} = get_cfg(<<"os_daemons">>). + +test_get_cfg2() -> + Path = list_to_binary(?FILE), + FileName = list_to_binary(filename:basename(?FILE)), + Path = get_cfg(<<"os_daemons">>, FileName), + <<"sequential">> = get_cfg(<<"uuids">>, <<"algorithm">>). + + +test_get_unknown_cfg() -> + {[]} = get_cfg(<<"aal;3p4">>), + null = get_cfg(<<"aal;3p4">>, <<"313234kjhsdfl">>). + +test_log() -> + log(<<"foobar!">>), + log(<<"some stuff!">>, <<"debug">>), + log(2), + log(true), + write([<<"log">>, <<"stuff">>, 2]), + write([<<"log">>, 3, null]), + write([<<"log">>, [1, 2], {[{<<"level">>, <<"debug">>}]}]), + write([<<"log">>, <<"true">>, {[]}]). + +do_tests() -> + test_get_cfg1(), + test_get_cfg2(), + test_get_unknown_cfg(), + test_log(), + loop(io:read("")). + +loop({ok, _}) -> + loop(io:read("")); +loop(eof) -> + init:stop(); +loop({error, _Reason}) -> + init:stop(). + +main([]) -> + do_tests().
