Skip to content
This repository
Browse code

use rebar's eunit support instead of scripts/run_tests.escript [bz 365]

test output is now in the .eunit/ directory, instead of test/
  • Loading branch information...
commit 80bfcb3ee7a71a9f8fddc16387a58b609b6f0e02 1 parent 1262540
Bryan Fink authored July 08, 2010
1  .hgignore
@@ -7,4 +7,5 @@ deps/mochiweb/ebin/mochiweb.app
7 7
 ebin/webmachine.app
8 8
 test\.log
9 9
 test/*
  10
+.eunit/*
10 11
 
2  Makefile
@@ -19,5 +19,5 @@ edoc:
19 19
 	@$(ERL) -noshell -run edoc_run application '$(APP)' '"."' '[{preprocess, true},{includes, ["."]}]'
20 20
 
21 21
 test: all
22  
-	scripts/run_tests.escript ebin | tee test.log
  22
+	@(./rebar skip_deps=true eunit)
23 23
 
1  rebar.config
... ...
@@ -1,5 +1,6 @@
1 1
 %%-*- mode: erlang -*-
2 2
 {fail_on_warning, true}.
  3
+{cover_enabled, true}.
3 4
 
4 5
 {deps, [
5 6
         {mochiweb, "1.7.1", {hg, "http://bitbucket.org/basho/mochiweb",
95  scripts/run_tests.escript
... ...
@@ -1,95 +0,0 @@
1  
-#!/usr/bin/env escript
2  
-%% -*- erlang -*-
3  
-%%! -name wm_test@127.0.0.1
4  
-main([Ebin]) ->
5  
-    code:add_path(Ebin),
6  
-    code:add_paths(filelib:wildcard("deps/*/ebin", Ebin)),
7  
-    code:add_paths(filelib:wildcard("deps/*/deps/*/ebin", Ebin)),
8  
-
9  
-    {ok, [{application, webmachine, App}]} =
10  
-        file:consult(filename:join([Ebin, "webmachine.app"])),
11  
-    {ok, NonTestRe} = re:compile("_tests$"),
12  
-    Modules = lists:filter(
13  
-                fun(M) when M =:= gen_server2 ->
14  
-                        false;
15  
-                   (M) when M =:= priority_queue ->
16  
-                        false;
17  
-                   (M) when M =:= json_pp ->
18  
-                        false;
19  
-                   (M) ->
20  
-                        nomatch == re:run(atom_to_list(M), NonTestRe)
21  
-                end,
22  
-                proplists:get_value(modules, App)),
23  
-    
24  
-    crypto:start(),
25  
-    start_cover(Modules),
26  
-    eunit:test(Modules, [verbose]),
27  
-    analyze_cover(Modules);
28  
-main(_) ->
29  
-    io:format("usage: run_tests.escript RIAK_EBIN_DIRECTORY~n"),
30  
-    halt(1).
31  
-
32  
-start_cover(Modules) ->
33  
-    {ok, _Cover} = cover:start(),
34  
-    io:format("Cover compiling...~n"),
35  
-    Compiled = [ M || {ok, M} <- [ cover:compile(
36  
-                                     filename:join(["src",atom_to_list(M)]))
37  
-                                   || M <- Modules ] ],
38  
-    case length(Modules) == length(Compiled) of
39  
-        true -> ok;
40  
-        false ->
41  
-            io:format("Warning: the following modules were not"
42  
-                      " cover-compiled:~n   ~p~n", [Compiled])
43  
-    end.
44  
-
45  
-analyze_cover(Modules) ->
46  
-    io:format("Analyzing cover...~n"),
47  
-    CoverBase = filename:join(["test", "cover"]),
48  
-    ok = filelib:ensure_dir(filename:join([CoverBase, "fake"])),
49  
-    Coverages = lists:foldl(
50  
-                  fun(M, Acc) ->
51  
-                          [analyze_module(CoverBase, M)|Acc]
52  
-                  end,
53  
-                  [], Modules),
54  
-    IndexFilename = filename:join([CoverBase, "index.html"]),
55  
-    {ok, Index} = file:open(IndexFilename, [write]),
56  
-    {LineTotal, CoverTotal} = 
57  
-        lists:foldl(fun({_,_,Lines,Covered}, {LineAcc, CovAcc}) ->
58  
-                            {LineAcc+Lines, CovAcc+Covered}
59  
-                    end, {0,0}, Coverages),
60  
-    file:write(Index,
61  
-               "<html><head><title>Riak Coverage</title></head>\n"
62  
-               "<body><h1>Riak Coverage</h1><ul>\n"),
63  
-    file:write(Index,
64  
-               io_lib:format("<h2>Total: ~.2f%</h2>\n",
65  
-                             [percentage(CoverTotal, LineTotal)])),
66  
-    [ file:write(Index,
67  
-                 io_lib:format(
68  
-                   "<li><a href=\"~s\">~p</a>: ~.2f%</li>~n",
69  
-                   [Filename, Module, percentage(Covered, Lines)]))
70  
-      || {Filename, Module, Lines, Covered} <- Coverages ],
71  
-    file:write(Index,"</ul></body></html>"),
72  
-    file:close(Index),
73  
-    io:format("Cover analysis in ~s~n", [IndexFilename]).
74  
-
75  
-analyze_module(CoverBase, Module) ->
76  
-    {ok, Filename} = 
77  
-        cover:analyze_to_file(
78  
-          Module,
79  
-          filename:join(CoverBase, atom_to_list(Module)++".COVER.html"),
80  
-          [html]),
81  
-    Lines = count_lines(Filename, "[[:digit:]]\.\.|"),
82  
-    Covered = count_lines(Filename, "[[:space:]]0\.\.|"),
83  
-    {filename:basename(Filename), Module, Lines, Lines-Covered}.
84  
-
85  
-count_lines(Filename, Pattern) ->
86  
-    {ok, [Lines],_} = io_lib:fread(
87  
-                        "~d",
88  
-                        os:cmd(io_lib:format("grep -e \"~s\" ~s | wc -l",
89  
-                                             [Pattern, Filename]))),
90  
-    Lines.
91  
-
92  
-percentage(_, 0) -> 1000.0;
93  
-percentage(Part, Total) ->
94  
-    (Part/Total)*100.
95  
-
0  test/.hgdummy
No changes.

0 notes on commit 80bfcb3

Please sign in to comment.
Something went wrong with that request. Please try again.