You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by be...@apache.org on 2014/01/13 23:09:01 UTC
[2/4] git commit: updated refs/heads/1994-merge-rcouch to fab1bad
reuse the code from test_lib
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/8e57d809
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/8e57d809
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/8e57d809
Branch: refs/heads/1994-merge-rcouch
Commit: 8e57d809974654116a9a886117448c85e420d002
Parents: edf99a3
Author: Benoit Chesneau <be...@apache.org>
Authored: Mon Jan 13 19:24:29 2014 +0100
Committer: Benoit Chesneau <be...@apache.org>
Committed: Mon Jan 13 19:24:29 2014 +0100
----------------------------------------------------------------------
test/etap/test_util.erl | 71 ++++++++++++++----
test/javascript/test_js.escript | 140 ++++-------------------------------
2 files changed, 71 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/8e57d809/test/etap/test_util.erl
----------------------------------------------------------------------
diff --git a/test/etap/test_util.erl b/test/etap/test_util.erl
index 9d323a1..8b403e0 100644
--- a/test/etap/test_util.erl
+++ b/test/etap/test_util.erl
@@ -13,10 +13,12 @@
-module(test_util).
-export([init_code_path/0]).
--export([source_file/1, build_file/1, test_file/1, config_files/0]).
+-export([builddir/0, srcdir/0, depsdir/0, testdir/0, scriptdir/0]).
+-export([source_file/1, build_file/1, test_file/1, config_files/0,
+ script_file/1, js_test_file/1]).
-export([run/2]).
-export([request/3, request/4]).
-
+-export([start_couch/0, stop_couch/0]).
builddir() ->
Current = filename:dirname(code:which(?MODULE)),
@@ -31,6 +33,31 @@ depsdir() ->
testdir() ->
filename:join([builddir(), "test", "out"]).
+scriptdir() ->
+ filename:join([testdir(), "share", "www", "script"]).
+
+source_file(Name) ->
+ filename:join([srcdir(), Name]).
+
+build_file(Name) ->
+ filename:join([builddir(), Name]).
+
+test_file(Name) ->
+ filename:join([testdir(), Name]).
+
+script_file(Name) ->
+ filename:join([scriptdir(), Name]).
+
+js_test_file(Name) ->
+ filename:join([builddir(), "test", "javascript", Name]).
+
+
+config_files() ->
+ [
+ filename:join([testdir(), "couch_test.ini"]),
+ filename:join([testdir(), "local.ini"])
+ ].
+
%%
%% Given a list of key value pairs, for each string value attempt to
%% render it using Dict as the context. Storing the result in Dict as Key.
@@ -94,22 +121,34 @@ init_code_path() ->
application:load(couch),
init_config().
+start_couch() ->
+ ok = test_util:init_code_path(),
+ IniFiles = test_util:config_files(),
-source_file(Name) ->
- filename:join([srcdir(), Name]).
-
-build_file(Name) ->
- filename:join([builddir(), Name]).
-
-test_file(Name) ->
- filename:join([testdir(), Name]).
-
-config_files() ->
- [
- filename:join([testdir(), "couch_test.ini"]),
- filename:join([testdir(), "local.ini"])
- ].
+ %% disable sasl
+ application:load(sasl),
+ application:set_env(sasl, errlog_type, error),
+ application:set_env(sasl, sasl_error_logger, false),
+ %% start couch
+ application:load(couch),
+ application:set_env(couch, config_files, IniFiles),
+ couch_util:start_app_deps(couch),
+ application:start(couch),
+
+ %% start couch_httpd
+ couch_util:start_app_deps(couch_httpd),
+ application:start(couch_httpd),
+
+ %% start couch_replicator
+ couch_util:start_app_deps(couch_replicator),
+ application:start(couch_replicator).
+
+stop_couch() ->
+ application:stop(couch_replicator),
+ application:stop(couch_httpd),
+ application:stop(couch),
+ application:stop(os_mon).
run(Plan, Fun) ->
test_util:init_code_path(),
http://git-wip-us.apache.org/repos/asf/couchdb/blob/8e57d809/test/javascript/test_js.escript
----------------------------------------------------------------------
diff --git a/test/javascript/test_js.escript b/test/javascript/test_js.escript
index 2a02972..45f747a 100755
--- a/test/javascript/test_js.escript
+++ b/test/javascript/test_js.escript
@@ -24,124 +24,16 @@
-export([main/1]).
-builddir() ->
- Current = filename:dirname(escript:script_name()),
- filename:absname(filename:join([Current, "..", ".."])).
-
-srcdir() ->
- filename:join([builddir(), "apps"]).
-
-depsdir() ->
- filename:join([builddir(), "deps"]).
-
-testdir() ->
- filename:join([builddir(), "test", "out"]).
-
-scriptdir() ->
- filename:join([testdir(), "share", "www", "script"]).
-
-
-script_file(Name) ->
- filename:join([scriptdir(), Name]).
-
-js_test_file(Name) ->
- filename:join([builddir(), "test", "javascript", Name]).
-
-
-config_files() ->
- [
- filename:join([testdir(), "couch_test.ini"]),
- filename:join([testdir(), "local.ini"])
- ].
-
-
-
-%%
-%% Given a list of key value pairs, for each string value attempt to
-%% render it using Dict as the context. Storing the result in Dict as Key.
-%%
-resolve_variables([], Dict) ->
- Dict;
-resolve_variables([{Key, Value0} | Rest], Dict) when is_integer(Value0) ->
- Value = render(list_to_binary(integer_to_list(Value0)), Dict),
- resolve_variables(Rest, dict:store(Key, Value, Dict));
-resolve_variables([{Key, Value0} | Rest], Dict) when is_list(Value0) ->
- Value = render(list_to_binary(Value0), Dict),
- resolve_variables(Rest, dict:store(Key, Value, Dict));
-resolve_variables([{Key, {list, Dicts}} | Rest], Dict) when is_list(Dicts) ->
- %% just un-tag it so mustache can use it
- resolve_variables(Rest, dict:store(Key, Dicts, Dict));
-resolve_variables([_Pair | Rest], Dict) ->
- resolve_variables(Rest, Dict).
-
-%%
-%% Render a binary to a string, using mustache and the specified context
-%%
-
-render(Bin, Context) ->
- %% Be sure to escape any double-quotes before rendering...
- ReOpts = [global, {return, list}],
- Str0 = re:replace(Bin, "\\\\", "\\\\\\", ReOpts),
- Str1 = re:replace(Str0, "\"", "\\\\\"", ReOpts),
- mustache:render(Str1, Context).
-
-
-init_config() ->
- {ok, Vars} = file:consult(filename:join([builddir(), "test",
- "vars.config"])),
-
- Vars1 = resolve_variables(Vars, dict:from_list([{testdir, testdir()}])),
-
- %% create test config
- {ok, Bin} = file:read_file(filename:join([builddir(), "etc",
- "couchdb", "couch.ini"])),
-
- Rendered = render(Bin, Vars1),
- file:write_file(filename:join([testdir(), "couch_test.ini"]),
- Rendered).
-
-
-init_code_path() ->
- lists:foreach(fun(Name) ->
- code:add_patha(filename:join([depsdir(), Name, "ebin"]))
- end, filelib:wildcard("*", depsdir())),
-
- lists:foreach(fun(Name) ->
- code:add_patha(filename:join([srcdir(), Name, "ebin"]))
- end, filelib:wildcard("*", srcdir())),
-
- code:add_patha(filename:join([builddir(), "test", "etap"])),
-
- %% init config
- init_config().
-
start_couch(Verbose) ->
- ok = init_code_path(),
- IniFiles = config_files(),
-
- application:load(sasl),
- %% disable sasl logging
- application:set_env(sasl, errlog_type, error),
- application:set_env(sasl, sasl_error_logger, false),
-
%% start couch
- application:load(couch),
- application:set_env(couch, config_files, IniFiles),
- couch_util:start_app_deps(couch),
- application:start(couch),
+ test_util:start_couch(),
%% set couch log level
couch_config:set("log", "level", atom_to_list(Verbose), false),
-
- couch_util:start_app_deps(couch_httpd),
- application:start(couch_httpd),
- couch_util:start_app_deps(couch_replicator),
- application:start(couch_replicator).
+ ok.
stop_couch() ->
- application:stop(couch_replicator),
- application:stop(couch_httpd),
- application:stop(couch),
- application:stop(os_mon).
+ application:stop(os_mon),
+ test_util:stop_couch().
restart_couch(Verbose) ->
stop_couch(),
@@ -163,20 +55,20 @@ exec_loop(Port, Verbose, Acc) ->
end.
exec(Path, Verbose) ->
- COUCHJS = filename:join([builddir(), "apps", "couch", "priv",
+ COUCHJS = filename:join([test_util:builddir(), "apps", "couch", "priv",
"couchjs"]),
- CouchUri = filename:join([testdir(), "data", "couch.uri"]),
+ CouchUri = filename:join([test_util:testdir(), "data", "couch.uri"]),
Cmd = string:join([COUCHJS, "-H", "-u", CouchUri,
- script_file("json2.js"),
- script_file("sha1.js"),
- script_file("oauth.js"),
- script_file("couch.js"),
- script_file("replicator_db_inc.js"),
- script_file("couch_test_runner.js"),
- js_test_file("couch_http.js"),
- js_test_file("test_setup.js"),
+ test_util:script_file("json2.js"),
+ test_util:script_file("sha1.js"),
+ test_util:script_file("oauth.js"),
+ test_util:script_file("couch.js"),
+ test_util:script_file("replicator_db_inc.js"),
+ test_util:script_file("couch_test_runner.js"),
+ test_util:js_test_file("couch_http.js"),
+ test_util:js_test_file("test_setup.js"),
Path,
- js_test_file("cli_runner.js")], " "),
+ test_util:js_test_file("cli_runner.js")], " "),
PortSettings = [exit_status, {line, 16384}, use_stdio, stderr_to_stdout,
hide],
@@ -229,7 +121,7 @@ test(TestDir, Files, Verbose) ->
end.
main([]) ->
- TestDir = filename:join([scriptdir(), "test"]),
+ TestDir = filename:join([test_util:scriptdir(), "test"]),
test(TestDir, filelib:wildcard("*.js", TestDir), none);
main(["-v", File | _]) ->
Dir = filename:absname(filename:dirname(File)),