Updated Branches:
refs/heads/1994-merge-rcouch 8cb6e7fdf -> 16217de4d
add javascript test and make check target
now it's possible to run javascript tests from the console:
make testjs
While I was here I added the make check target to launch all tests.
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/16217de4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/16217de4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/16217de4
Branch: refs/heads/1994-merge-rcouch
Commit: 16217de4d64cca14f90ee7f90a651ce98d1dd3c9
Parents: 8cb6e7f
Author: Benoit Chesneau <[email protected]>
Authored: Fri Jan 10 02:07:57 2014 +0100
Committer: Benoit Chesneau <[email protected]>
Committed: Fri Jan 10 02:07:57 2014 +0100
----------------------------------------------------------------------
Makefile | 15 ++-
src/apps/couch/src/couch_app.erl | 2 +
src/test/Makefile.am | 15 ---
src/test/etap/test_util.erl | 2 +-
src/test/javascript/Makefile.am | 27 -----
src/test/javascript/run.tpl | 138 ---------------------
src/test/javascript/test_js.escript | 202 +++++++++++++++++++++++++++++++
src/test/random_port.ini | 19 ---
src/test/view_server/Makefile.am | 15 ---
9 files changed, 217 insertions(+), 218 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index dd86765..3046311 100644
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,12 @@ rel: generate
relclean:
@rm -rf rel/apache-couchdb
+check: test testjs
+
+#
+# rebar
+#
+
rebar:
@(test ! -e $(BASE_DIR)/src/support/rebar/rebar && \
echo "==> build rebar" && \
@@ -63,16 +69,19 @@ export COUCHDB_ETAP_DIR
ERL_LIBS=$(BASE_DIR)/src/deps:$(BASE_DIR)/src/apps:$(BASE_DIR)/src/test/etap
export ERL_LIBS
-test: deps compile testbuild
+test: testbuild
prove $(COUCHDB_ETAP_DIR)/*.t
prove $(BASE_DIR)/src/apps/couch_mrview/test/*.t
prove $(BASE_DIR)/src/apps/couch_replicator/test/*.t
-verbose-test: deps compile testbuild
+verbose-test: testbuild
prove -v $(COUCHDB_ETAP_DIR)/*.t
prove -v $(BASE_DIR)/src/apps/couch_mrview/test/*.t
prove -v $(BASE_DIR)/src/apps/couch_replicator/test/*.t
+testjs: testbuild
+ $(ESCRIPT) $(BASE_DIR)/src/test/javascript/test_js.escript
+
testbuild: testclean
$(ERLC) -v -o $(COUCHDB_ETAP_DIR) $(COUCHDB_ETAP_DIR)/etap.erl
$(ERLC) -v -o $(COUCHDB_ETAP_DIR) $(COUCHDB_ETAP_DIR)/test_web.erl
@@ -87,7 +96,7 @@ testbuild: testclean
cp $(BASE_DIR)/src/apps/couch/priv/couchjs $(BASE_DIR)/src/test/out/bin/
cp -r $(BASE_DIR)/src/share/server $(BASE_DIR)/src/test/out/share
cp -r $(BASE_DIR)/src/share/www $(BASE_DIR)/src/test/out/share
-
+ cp $(BASE_DIR)/src/etc/couchdb/local.ini $(BASE_DIR)/src/test/out/
testclean:
@rm -rf $(COUCHDB_ETAP_DIR)/*.beam
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/apps/couch/src/couch_app.erl
----------------------------------------------------------------------
diff --git a/src/apps/couch/src/couch_app.erl b/src/apps/couch/src/couch_app.erl
index 414a5c9..2e1e5bd 100644
--- a/src/apps/couch/src/couch_app.erl
+++ b/src/apps/couch/src/couch_app.erl
@@ -33,4 +33,6 @@ get_ini_files() ->
Defaults = lists:map(fun(FName) ->
filename:join(DefaultConfDir, FName)
end, ?CONF_FILES),
+ io:format("default files ~p~n", [couch:get_app_env(config_files,
+ Defaults)]),
couch:get_app_env(config_files, Defaults).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/test/Makefile.am
----------------------------------------------------------------------
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
deleted file mode 100644
index 7c70a5a..0000000
--- a/src/test/Makefile.am
+++ /dev/null
@@ -1,15 +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.
-
-SUBDIRS = bench etap javascript view_server
-EXTRA_DIST = random_port.ini
-
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/test/etap/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test/etap/test_util.erl b/src/test/etap/test_util.erl
index 0397b4b..9d323a1 100644
--- a/src/test/etap/test_util.erl
+++ b/src/test/etap/test_util.erl
@@ -107,7 +107,7 @@ test_file(Name) ->
config_files() ->
[
filename:join([testdir(), "couch_test.ini"]),
- filename:join([builddir(), "etc", "couchdb", "local.ini"])
+ filename:join([testdir(), "local.ini"])
].
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/test/javascript/Makefile.am
----------------------------------------------------------------------
diff --git a/src/test/javascript/Makefile.am b/src/test/javascript/Makefile.am
deleted file mode 100644
index e7036ca..0000000
--- a/src/test/javascript/Makefile.am
+++ /dev/null
@@ -1,27 +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.
-
-EXTRA_DIST = \
- cli_runner.js \
- couch_http.js \
- test_setup.js \
- run.tpl
-
-noinst_SCRIPTS = run
-CLEANFILES = run
-
-run: run.tpl
- sed -e "s|%abs_top_srcdir%|$(abs_top_srcdir)|" \
- -e "s|%abs_top_builddir%|$(abs_top_builddir)|" \
- -e "s|%localstaterundir%|$(abs_top_builddir)/tmp/run|g" \
- < $< > $@
- chmod +x $@
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/test/javascript/run.tpl
----------------------------------------------------------------------
diff --git a/src/test/javascript/run.tpl b/src/test/javascript/run.tpl
deleted file mode 100644
index 75192da..0000000
--- a/src/test/javascript/run.tpl
+++ /dev/null
@@ -1,138 +0,0 @@
-#!/bin/sh -e
-
-# 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.
-
-SRC_DIR=%abs_top_srcdir%
-BUILD_DIR=%abs_top_builddir%
-SCRIPT_DIR=$SRC_DIR/share/www/script
-JS_TEST_DIR=$SRC_DIR/test/javascript
-
-COUCHJS=%abs_top_builddir%/src/couchdb/priv/couchjs
-COUCH_URI_FILE=%localstaterundir%/couch.uri
-
-# make check-js calls us with MAKE=$(MAKE) so BSDish `gmake` invocations
-# will get passed on correctly. If $0 gets run manually, default to
-# `make`
-if [ -z "$MAKE" ]; then
- MAKE=make
-fi
-
-trap 'abort' EXIT INT
-
-start() {
- ./utils/run -b -r 0 -n \
- -a $BUILD_DIR/etc/couchdb/default_dev.ini \
- -a $SRC_DIR/test/random_port.ini \
- -a $BUILD_DIR/etc/couchdb/local_dev.ini 1>/dev/null
-}
-
-stop() {
- ./utils/run -d 1>/dev/null
-}
-
-restart() {
- stop
- start
-}
-
-abort() {
- trap - 0
- stop
- exit 2
-}
-
-process_response() {
- while read data
- do
- if [ $data = 'restart' ];
- then
- if [ -z $COUCHDB_NO_START ]; then
- restart
- fi
- else
- echo "$data"
- fi
- done
-}
-
-run() {
- # start the tests
- /bin/echo -n "$1 ... "
- $COUCHJS -H -u $COUCH_URI_FILE \
- $SCRIPT_DIR/json2.js \
- $SCRIPT_DIR/sha1.js \
- $SCRIPT_DIR/oauth.js \
- $SCRIPT_DIR/couch.js \
- $SCRIPT_DIR/replicator_db_inc.js \
- $SCRIPT_DIR/couch_test_runner.js \
- $JS_TEST_DIR/couch_http.js \
- $JS_TEST_DIR/test_setup.js \
- $1 \
- $JS_TEST_DIR/cli_runner.js | process_response
-
- if [ -z $RESULT ]; then
- RESULT=$?
- elif [ "$?" -eq 1 ]; then
- RESULT=$?
- fi
-
-}
-
-run_files() {
- COUNTER=1
- FILE_COUNT=$(ls -l $1 | wc -l)
- FILE_COUNT=$(expr $FILE_COUNT + 0)
- for TEST_SRC in $1
- do
- /bin/echo -n "$COUNTER/$FILE_COUNT "
- COUNTER=$(expr $COUNTER + 1)
- run $TEST_SRC
- done
-}
-
-# start CouchDB
-if [ -z $COUCHDB_NO_START ]; then
- $MAKE dev
- start
-fi
-
-echo "Running javascript tests ..."
-
-if [ "$#" -eq 0 ];
-then
- run_files "$SCRIPT_DIR/test/*.js"
-else
- if [ -d $1 ]; then
- run_files "$1/*.js"
- else
- TEST_SRC="$1"
- if [ ! -f $TEST_SRC ]; then
- TEST_SRC="$SCRIPT_DIR/test/$1"
- if [ ! -f $TEST_SRC ]; then
- TEST_SRC="$SCRIPT_DIR/test/$1.js"
- if [ ! -f $TEST_SRC ]; then
- echo "file $1 does not exist"
- exit 1
- fi
- fi
- fi
- fi
- run $TEST_SRC
-fi
-
-if [ -z $COUCHDB_NO_START ]; then
- stop
-fi
-
-trap - 0
-exit $RESULT
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/test/javascript/test_js.escript
----------------------------------------------------------------------
diff --git a/src/test/javascript/test_js.escript
b/src/test/javascript/test_js.escript
new file mode 100755
index 0000000..76e3c50
--- /dev/null
+++ b/src/test/javascript/test_js.escript
@@ -0,0 +1,202 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap
+
+% 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.
+
+% Test replication of documents with many leaf revisions.
+% Motivated by COUCHDB-1340 and other similar issues where a document
+% GET with a too long ?open_revs revision list doesn't work due to
+% maximum web server limits for the HTTP request path.
+%
+%
+-module(test_js).
+
+-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() ->
+ ok = init_code_path(),
+ IniFiles = config_files(),
+ application:load(couch),
+ application:set_env(couch, config_files, IniFiles),
+ couch_util:start_app_deps(couch),
+ application:start(couch),
+ couch_util:start_app_deps(couch_replicator),
+ application:start(couch_replicator).
+
+stop_couch() ->
+ application:stop(couch_replicator),
+ application:stop(couch).
+
+restart_couch() ->
+ stop_couch(),
+ timer:sleep(1000),
+ start_couch().
+
+exec(Path) ->
+ COUCHJS = filename:join([builddir(), "apps", "couch", "priv",
+ "couchjs"]),
+ CouchUri = filename:join([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"),
+ Path,
+ js_test_file("cli_runner.js")], " "),
+
+ Resp = os:cmd(Cmd),
+ Lines = string:tokens(Resp, "\n"),
+ Result = lists:foldr(fun
+ ("restart", Acc) ->
+ restart_couch(),
+ Acc;
+ ("OK", _Acc) ->
+ ok;
+ (_, Acc) ->
+ Acc
+ end, fail, Lines),
+ io:format("~s ... ~s~n", [filename:basename(Path), Result]),
+ Result.
+
+
+
+test(TestDir, Files) ->
+ start_couch(),
+ timer:sleep(1000),
+
+ io:format("==> run javascript tests.~n~n", []),
+ {Failed, Success} = lists:foldl(fun(Name, {FAILs, OKs}) ->
+ Path = filename:join([TestDir, Name]),
+ Result = exec(Path),
+ case Result of
+ ok-> {FAILs, [Name | OKs]};
+ _ -> {[Name | FAILs], OKs}
+ end
+
+ end, {[], []}, Files),
+
+ NFailed = length(Failed),
+ NSuccess = length(Success),
+ Count = NFailed + NSuccess,
+
+ case NFailed of
+ 0 ->
+ io:format("~nAll tests successful.~nTests: ~p~n", [Count]);
+ _ ->
+ io:format("~n~p/~p tests failed~n", [NFailed, Count])
+ end,
+
+ stop_couch().
+
+main([]) ->
+ TestDir = filename:join([scriptdir(), "test"]),
+ test(TestDir, filelib:wildcard("*.js", TestDir));
+main([File |_]) ->
+ Dir = filename:absname(filename:dirname(File)),
+ test(Dir, [filename:basename(File)]).
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/test/random_port.ini
----------------------------------------------------------------------
diff --git a/src/test/random_port.ini b/src/test/random_port.ini
deleted file mode 100644
index 2b2d130..0000000
--- a/src/test/random_port.ini
+++ /dev/null
@@ -1,19 +0,0 @@
-; 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.
-
-[httpd]
-port = 0
http://git-wip-us.apache.org/repos/asf/couchdb/blob/16217de4/src/test/view_server/Makefile.am
----------------------------------------------------------------------
diff --git a/src/test/view_server/Makefile.am b/src/test/view_server/Makefile.am
deleted file mode 100644
index 11e7feb..0000000
--- a/src/test/view_server/Makefile.am
+++ /dev/null
@@ -1,15 +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.
-
-EXTRA_DIST = \
- query_server_spec.rb \
- run_native_process.es