Permalink
Browse files

Added code coverage report generation target.

To generate reports:

    # Assuming etap is installed
    $ cd /path/to/couchdb
    $ ./bootstrap && ERLC_FLAGS=+debug_info ./configure && make cover

You can browse the report by opening ./cover/index.html in your html consuming software of choice.

Shoutout to Nick Gerakines in THANKS for helping with etap and testing in general.



git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@780326 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 2b44369 commit 9e9230c129816dc2ee7092734e72bffb2ac17748 @davisp davisp committed May 30, 2009
Showing with 14 additions and 220 deletions.
  1. +7 −0 Makefile.am
  2. +1 −0 THANKS
  3. +1 −0 configure.ac
  4. +1 −1 src/couchdb/Makefile.am
  5. +0 −215 src/couchdb/couch_btree.erl
  6. +1 −1 src/ibrowse/Makefile.am
  7. +1 −1 src/mochiweb/Makefile.am
  8. +2 −2 test/etap/030-doc-from-json.t
View
7 Makefile.am
@@ -39,6 +39,13 @@ THANKS.gz: $(top_srcdir)/THANKS
check: all
prove test/etap/*.t
+cover: all
+ rm -f cover/*.coverdata
+ COVER=1 COVER_BIN=./src/couchdb/ prove test/etap/*.t
+ SRC=./src/couchdb/ \
+ $(ERL) -noshell -eval 'etap_report:create()' \
+ -s init stop -noshell > /dev/null 2>&1
+
dev: all
@echo "This command is intended for developers to use;"
@echo "it creates development ini files as well as a"
View
1 THANKS
@@ -28,5 +28,6 @@ suggesting improvements or submitting changes. Some of these people are:
* Volker Mische <volker.mische@gmail.com>
* Brian Candler <B.Candler@pobox.com>
* Brad Anderson <brad@sankatygroup.com>
+ * Nick Gerakines <nick@gerakines.net>
For a list of authors see the `AUTHORS` file.
View
1 configure.ac
@@ -74,6 +74,7 @@ AC_ARG_WITH([js-lib], [AC_HELP_STRING([--with-js-lib=PATH],
[set PATH to the SpiderMonkey library directory])],
[JS_LIB_FLAGS="-L$withval"], [])
+AC_ARG_VAR([ERLC_FLAGS], [general flags to prepend to ERLC_FLAGS])
AC_ARG_VAR([FLAGS], [general flags to prepend to LDFLAGS and CPPFLAGS])
LIB_FLAGS="$JS_LIB_FLAGS -L/usr/local/lib -L/opt/local/lib"
View
2 src/couchdb/Makefile.am
@@ -169,7 +169,7 @@ couch.app: couch.app.tpl
# $(ERL) -noshell -run edoc_run files [\"$<\"]
%.beam: %.erl couch_db.hrl
- $(ERLC) ${TEST} $<;
+ $(ERLC) $(ERLC_FLAGS) ${TEST} $<;
install-data-hook:
if test -f "$(DESTDIR)/$(couchprivlibdir)/couch_erl_driver"; then \
View
215 src/couchdb/couch_btree.erl
@@ -15,7 +15,6 @@
-export([open/2, open/3, query_modify/4, add/2, add_remove/3, foldl/3, foldl/4]).
-export([foldr/3, foldr/4, fold/4, fold/5, full_reduce/1, final_reduce/2]).
-export([fold_reduce/6, fold_reduce/7, lookup/2, get_state/1, set_options/2]).
--export([test/1, test/0, test_remove/2, test_add/2]).
-define(CHUNK_THRESHOLD, 16#4ff).
@@ -652,217 +651,3 @@ stream_kv_node2(Bt, Reds, PrevKVs, [{K,V} | RestKVs], Dir, Fun, Acc) ->
{stop, Acc2} ->
{stop, Acc2}
end.
-
-shuffle(List) ->
-%% Determine the log n portion then randomize the list.
- randomize(round(math:log(length(List)) + 0.5), List).
-
-randomize(1, List) ->
- randomize(List);
-randomize(T, List) ->
- lists:foldl(fun(_E, Acc) ->
- randomize(Acc)
- end, randomize(List), lists:seq(1, (T - 1))).
-
-randomize(List) ->
- D = lists:map(fun(A) ->
- {random:uniform(), A}
- end, List),
- {_, D1} = lists:unzip(lists:keysort(1, D)),
- D1.
-
-
-
-test()->
- test(1000).
-
-test(N) ->
- Sorted = [{Seq, random:uniform()} || Seq <- lists:seq(1, N)],
- test_btree(Sorted), % sorted regular
- test_btree(lists:reverse(Sorted)), % sorted reverse
- test_btree(shuffle(Sorted)). % randomly distributed
-
-
-test_btree(KeyValues) ->
- {ok, Fd} = couch_file:open("foo", [create,overwrite]),
- {ok, Btree} = open(nil, Fd),
- ReduceFun =
- fun(reduce, KVs) ->
- length(KVs);
- (rereduce, Reds) ->
- lists:sum(Reds)
- end,
- Btree1 = set_options(Btree, [{reduce, ReduceFun}]),
-
- % first dump in all the values in one go
- {ok, Btree10} = add_remove(Btree1, KeyValues, []),
-
-
- Len = length(KeyValues),
-
- % get the leading reduction as we foldl/r
- % and count of all from start to Val1
- Val1 = Len div 3,
- {ok, _} = foldl(Btree10, Val1,
- fun(_X, LeadingReds, Acc) ->
- CountToStart = Val1 + Acc - 1,
- CountToStart = final_reduce(Btree10, LeadingReds),
- {ok, Acc + 1}
- end,
- 0),
-
- {ok, true} = foldr(Btree10, Val1, fun(_X, LeadingReds, _Acc) ->
- CountToEnd = Len - Val1,
- CountToEnd = final_reduce(Btree10, LeadingReds),
- {stop, true} % change Acc to 'true'
- end,
- false),
-
- ok = test_keys(Btree10, KeyValues),
-
- % remove everything
- {ok, Btree20} = test_remove(Btree10, KeyValues),
-
- % make sure its empty
- {ok, false} = foldl(Btree20, fun(_X, _Acc) ->
- {ok, true} % change Acc to 'true'
- end,
- false),
-
- % add everything back one at a time.
- {ok, Btree30} = test_add(Btree20, KeyValues),
-
- ok = test_keys(Btree30, KeyValues),
-
- KeyValuesRev = lists:reverse(KeyValues),
-
- % remove everything, in reverse order
- {ok, Btree40} = test_remove(Btree30, KeyValuesRev),
-
- % make sure its empty
- {ok, false} = foldl(Btree40, fun(_X, _Acc) ->
- {ok, true} % change Acc to 'true'
- end,
- false),
-
-
- {A, B} = every_other(KeyValues),
-
- % add everything back
- {ok, Btree50} = test_add(Btree40,KeyValues),
-
- ok = test_keys(Btree50, KeyValues),
-
- % remove half the values
- {ok, Btree60} = test_remove(Btree50, A),
-
- % verify the remaining
- ok = test_keys(Btree60, B),
-
- % add A back
- {ok, Btree70} = test_add(Btree60, A),
-
- % verify
- ok = test_keys(Btree70, KeyValues),
-
- % remove B
- {ok, Btree80} = test_remove(Btree70, B),
-
- % verify the remaining
- ok = test_keys(Btree80, A),
-
- {ok, Btree90} = test_remove(Btree80, A),
-
- EvenOdd = fun(V) when V rem 2 == 1 -> "odd"; (_) -> "even" end,
-
- EvenOddKVs = [{{EvenOdd(Key),Key}, 1} || {Key, _} <- KeyValues],
-
- {ok, Btree100} = test_add(Btree90, EvenOddKVs),
- GroupingFun = fun({K1, _},{K2,_}) -> K1 == K2 end,
- FoldFun = fun(GroupedKey, Unreduced, Acc) ->
- {ok, [{GroupedKey, final_reduce(Btree100, Unreduced)} | Acc]}
- end,
-
- Half = Len div 2,
-
- {ok, [{{"odd", _}, Half}, {{"even",_}, Half}]} =
- fold_reduce(Btree100, nil, nil, GroupingFun, FoldFun, []),
-
- {ok, [{{"even",_}, Half}, {{"odd", _}, Half}]} =
- fold_reduce(Btree100, rev, nil, nil, GroupingFun, FoldFun, []),
-
- {ok, [{{"even",_}, Half}]} =
- fold_reduce(Btree100, fwd, {"even", -1}, {"even", foo}, GroupingFun, FoldFun, []),
-
- {ok, [{{"even",_}, Half}]} =
- fold_reduce(Btree100, rev, {"even", foo}, {"even", -1}, GroupingFun, FoldFun, []),
-
- {ok, [{{"odd",_}, Half}]} =
- fold_reduce(Btree100, fwd, {"odd", -1}, {"odd", foo}, GroupingFun, FoldFun, []),
-
- {ok, [{{"odd",_}, Half}]} =
- fold_reduce(Btree100, rev, {"odd", foo}, {"odd", -1}, GroupingFun, FoldFun, []),
-
- {ok, [{{"odd", _}, Half}, {{"even",_}, Half}]} =
- fold_reduce(Btree100, {"even", -1}, {"odd", foo}, GroupingFun, FoldFun, []),
-
- ok = couch_file:close(Fd).
-
-
-
-
-
-every_other(List) ->
- every_other(List, [], [], 1).
-
-every_other([], AccA, AccB, _Flag) ->
- {lists:reverse(AccA), lists:reverse(AccB)};
-every_other([H|T], AccA, AccB, 1) ->
- every_other(T, [H|AccA], AccB, 0);
-every_other([H|T], AccA, AccB, 0) ->
- every_other(T, AccA, [H|AccB], 1).
-
-test_keys(Btree, List) ->
- FoldFun =
- fun(Element, [HAcc|TAcc]) ->
- Element = HAcc, % must match
- {ok, TAcc}
- end,
- Sorted = lists:sort(List),
- {ok, []} = foldl(Btree, FoldFun, Sorted),
- {ok, []} = foldr(Btree, FoldFun, lists:reverse(Sorted)),
-
- test_lookup(Btree, List).
-
-% Makes sure each key value pair is found in the btree
-test_lookup(_Btree, []) ->
- ok;
-test_lookup(Btree, [{Key, Value} | Rest]) ->
- [{ok,{Key, Value}}] = lookup(Btree, [Key]),
- {ok, []} = foldl(Btree, Key, fun({KeyIn, ValueIn}, []) ->
- KeyIn = Key,
- ValueIn = Value,
- {stop, []}
- end,
- []),
- {ok, []} = foldr(Btree, Key, fun({KeyIn, ValueIn}, []) ->
- KeyIn = Key,
- ValueIn = Value,
- {stop, []}
- end,
- []),
- test_lookup(Btree, Rest).
-
-% removes each key one at a time from the btree
-test_remove(Btree, []) ->
- {ok, Btree};
-test_remove(Btree, [{Key, _Value} | Rest]) ->
- {ok, Btree2} = add_remove(Btree,[], [Key]),
- test_remove(Btree2, Rest).
-
-% adds each key one at a time from the btree
-test_add(Btree, []) ->
- {ok, Btree};
-test_add(Btree, [KeyValue | Rest]) ->
- {ok, Btree2} = add_remove(Btree, [KeyValue], []),
- test_add(Btree2, Rest).
View
2 src/ibrowse/Makefile.am
@@ -45,4 +45,4 @@ CLEANFILES = \
$(ibrowseebin_make_generated_file_list)
%.beam: %.erl
- $(ERLC) $<
+ $(ERLC) $(ERLC_FLAGS) $<
View
2 src/mochiweb/Makefile.am
@@ -76,4 +76,4 @@ CLEANFILES = \
$(mochiwebebin_make_generated_file_list)
%.beam: %.erl
- $(ERLC) $<
+ $(ERLC) $(ERLC_FLAGS) $<
View
4 test/etap/030-doc-from-json.t
@@ -87,11 +87,11 @@ test_from_json_success() ->
},
{
{[
- {<<"_rev">>, <<"6-something">>},
{<<"_revisions">>, {[
{<<"start">>, 4},
{<<"ids">>, [<<"foo1">>, <<"phi3">>, <<"omega">>]}
- ]}}
+ ]}},
+ {<<"_rev">>, <<"6-something">>}
]},
#doc{revs={4, [<<"foo1">>, <<"phi3">>, <<"omega">>]}},
"_revisions attribute are preferred to _rev."

0 comments on commit 9e9230c

Please sign in to comment.