<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -26,6 +26,27 @@ import '.depend_erlang.mf'
 
 namespace :erlang do
   
+  def handle_test(mode, args)
+    directories = ERL_DIRECTORIES + ERL_DIRECTORIES.pathmap(&quot;%{ebin,test}X&quot;)
+    if args.name
+      description = &quot;lib/&quot; + args.name + &quot;/test.desc&quot;
+      if File.file?(description)
+        run_description_test(description, mode, args.name, directories)
+      else
+        run_application_test(args.name, mode, directories)
+      end
+    else
+      ERL_APPLICATIONS.each do |application|
+        description = application.pathmap(&quot;%{ebin,test}d/test.desc&quot;)
+        if File.file?(description)
+          run_description_test(description, mode, application, directories)
+        else
+          run_application_test(application, mode, directories)
+        end
+      end
+    end
+  end
+    
   def collect_boot_files(releases)
     releases.collect { |elt|
       if elt =~ /^release/
@@ -98,13 +119,14 @@ namespace :erlang do
     erlang_source_dependencies + erlang_test_dependencies
   end
 
-  def run_application_test(application, directories)
+  def run_application_test(application, mode, directories)
     application_name = application.pathmap(&quot;%f&quot;).ext(&quot;&quot;)
-    run_script(&quot;run_test&quot;,[&quot;application&quot;, application_name] + directories)
+    run_script(&quot;run_test&quot;,[mode, application_name, &quot;all_tests&quot;] + directories)
   end
 
-  def run_description_test(description, directories)
-    run_script(&quot;run_test&quot;,[&quot;file&quot;, description] + directories)
+  def run_description_test(description, mode, application, directories)
+    application_name = application.pathmap(&quot;%f&quot;).ext(&quot;&quot;)
+    run_script(&quot;run_test&quot;,[mode, application_name, description, ] + directories)
   end
 
   def run_script(script, parameters)
@@ -158,6 +180,7 @@ namespace :erlang do
   end
 
   CLEAN.include(&quot;lib/*/test/*.beam&quot;)
+  CLEAN.include(&quot;lib/*/cover&quot;)
 
   def beam_dependencies_with_emake(beam, file) 
     dependencies = check_dependencies(file).uniq
@@ -201,15 +224,14 @@ namespace :erlang do
           file.write(&quot;{\&quot;#{elt}/*\&quot;,#{option_string}}.\n&quot;)
         end
       end
-      sh &quot;#{ERL_TOP}/bin/erl -noinput -s make all -s erlang halt &quot;
     end
     CLEAN.include &quot;Emakefile&quot;
     
-#     rule &quot;.beam&quot; =&gt;  [&quot;Emakefile&quot;] do |t|
-#       output = t.name.pathmap(&quot;%d&quot;)
-#       sh &quot;#{ERL_TOP}/bin/erl -noinput -s make all -s erlang halt &quot;
-#     end
-    
+    desc &quot;Compile Erlang sources&quot;
+    task :modules =&gt; ERL_DIRECTORIES + ERL_BEAM + ERL_BEAM_TESTS do
+      sh &quot;#{ERL_TOP}/bin/erl -noinput -s make all -s erlang halt &quot;
+    end
+
   else
     def erlang_test_dependencies
       FileList['lib/*/test/*.erl'].collect { |file|
@@ -229,6 +251,10 @@ namespace :erlang do
       output = t.name.pathmap(&quot;%d&quot;)
       sh &quot;#{ERL_TOP}/bin/erlc -Ilib #{ERLC_FLAGS} -o #{output} #{t.source}&quot;
     end
+
+    desc &quot;Compile Erlang sources&quot;
+    task :modules =&gt; ERL_DIRECTORIES + ERL_BEAM + ERL_BEAM_TESTS
+
   end
   rule '.app' =&gt; [&quot;%{ebin,src}X.app.src&quot;,
                   &quot;%{ebin,src}d/../vsn.config&quot;] do |t|
@@ -308,32 +334,20 @@ namespace :erlang do
     }
   end
 
-  desc &quot;Compile Erlang sources&quot;
-  task :modules =&gt; ERL_DIRECTORIES + ERL_BEAM + ERL_BEAM_TESTS
 
   desc &quot;Run erlang unit test for all or a specific application.&quot;\
   &quot;(No name given mean all applications)&quot;
   task :tests, :name, :needs =&gt; [:applications] + ERL_BEAM_TESTS do
     |t, args|
-    directories = ERL_DIRECTORIES + ERL_DIRECTORIES.pathmap(&quot;%{ebin,test}X&quot;)
-    if args.name
-      description = &quot;lib/&quot; + args.name + &quot;/test.desc&quot;
-      if File.file?(description)
-        run_description_test(description, directories)
-      else
-        run_application_test(args.name, directories)
-      end
-    else
-      ERL_APPLICATIONS.each do |application|
-        description = application.pathmap(&quot;%{ebin,test}d/test.desc&quot;)
-        if File.file?(description)
-          run_description_test(description, directories)
-        else
-          run_application_test(application, directories)
-        end
-      end
-    end
-    
+    handle_test(&quot;test&quot;, args)
+  end
+
+
+  desc &quot;Run cover on unit test for all or a specific application.&quot;\
+  &quot;(No name given mean all applications)&quot;
+  task :cover, :name, :needs =&gt; [:applications] + ERL_BEAM_TESTS do
+    |t, args|
+    handle_test(&quot;cover&quot;, args)
   end
 
   desc &quot;Build application resource file&quot;</diff>
      <filename>rakelib/erlang.rake</filename>
    </modified>
    <modified>
      <diff>@@ -1,22 +1,87 @@
 %% -*- erlang -*-
-%% Copyright (c) 2008 Nicolas Charpentier
-main([Type,Application|Paths]) -&gt;
+%% Copyright (c) 2008-2009 Nicolas Charpentier
+main([Mode, Application, Type |Paths]) -&gt;
+    run(Mode, Application, Type, Paths);
+main(_) -&gt;
+    usage().
+
+run(Mode, Application, Type, Paths) -&gt;
+    F = execution_fun(Mode, Application, Type),
     try
 	[code:add_path(Path) || Path &lt;- Paths],
-	ok = run_test(Type,Application)
+	ok = F()
     catch
         E:R -&gt;
 	    exit({E,R,erlang:get_stacktrace()})
-    end;
-main(_) -&gt;
-    usage().
-        
-run_test(&quot;application&quot;, Application) -&gt;
+    end.
+
+execution_fun(&quot;test&quot;, Application, Type) -&gt;
+    fun() -&gt; run_test(Application, Type) end;
+execution_fun(&quot;cover&quot;, Application, Type) -&gt;
+    Fun = fun() -&gt; ok = run_test(Application, Type) end,
+    fun () -&gt;
+	    Sources = filename:join(code:lib_dir(Application),&quot;src&quot;),
+	    Out = filename:join(code:lib_dir(Application),&quot;cover&quot;),
+	    Options = [{directories,[Sources]},{output_directory,Out}],
+	    ok = application:load(list_to_atom(Application)),
+	    cover(Fun, Options) end.
+
+run_test(Application, &quot;all_tests&quot;) -&gt;
     eunit:test({application, list_to_atom(Application)},[]);
-run_test(&quot;file&quot;, File) -&gt;
+run_test(_, File) -&gt;
     eunit:test({file, File},[]).
     
 usage() -&gt;
-    io:format(&quot;usage: run_test \&quot;application\&quot;|\&quot;file\&quot; &lt;application_name|file_name&gt; &lt;application_path&gt;\n&quot;),
+    io:format(&quot;usage: run_test \&quot;test\&quot;|\&quot;cover\&quot; &lt;application_name&gt;  &lt;\&quot;all_tests\&quot;|test_description_file&gt; &lt;application_path&gt;\n&quot;),
     halt(1).
 
+cover(Fun, Options) -&gt;
+    Directories = proplists: get_value(directories, Options, []),
+
+    [cover:compile_directory(D) || D &lt;- Directories],
+    try Fun() of
+	ok -&gt; ok
+    catch E:R -&gt;
+	    exit({E,R,erlang:get_stacktrace()})
+    after
+	report(Options)
+    end.
+
+report(Options) -&gt;
+    F = fun(M) -&gt;
+		App = case application:get_application(M) of
+			  {ok, X} -&gt; X;
+			  _ -&gt; undefined
+		      end,
+		Analyse = cover:analyse(M,calls,line),
+		{App, M, Analyse}
+	end,
+    Results = [F(M) || M &lt;- cover:modules()],
+    Coverage = cover_to_xml(Results), 
+    Export = xmerl:export_simple([{cover, Coverage}], xmerl_xml),
+    
+    Output_directory = proplists: get_value(output_directory, Options, &quot;.&quot;),
+    Directory_name = filename:absname(Output_directory),
+    ok = filelib:ensure_dir(Directory_name),
+    file:make_dir(Directory_name),
+    true = filelib:is_dir(Directory_name),
+
+    Summary_file = filename:join(Output_directory, &quot;cover_tool.xml&quot;),
+    file:write_file(Summary_file, Export),
+    
+    HTML_file = fun(M) -&gt;
+			filename:join(Directory_name, atom_to_list(M) ++&quot;.COVER.html&quot;)
+		end,
+    [cover:analyse_to_file(M, HTML_file(M), [html]) || M &lt;-cover:modules()],
+    ok.
+
+cover_to_xml(Results) -&gt;
+    [cover_to_xml(App, M, Lines) || {App,M,{ok,Lines}} &lt;- Results].
+
+cover_to_xml(App, Module, Lines) -&gt;
+    F = fun({_,0}) -&gt; false;
+	   (_) -&gt; true end,
+
+    Called = length(lists:filter(F, Lines)),
+    Uncalled = length(Lines) - Called,
+    {module,[{application, App},{name,Module}], [{lines,[{called, Called}, {uncalled, Uncalled}],[]}]}.</diff>
      <filename>rakelib/escripts/run_test</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>00477ec5a3dc67d0c55422f26703e508aaab9ea5</id>
    </parent>
  </parents>
  <author>
    <name>charpi</name>
    <email>charpi@3ab005ec-33ed-11dd-9e78-a92e4af85449</email>
  </author>
  <url>http://github.com/charpi/erl_selenium/commit/9984d0281c68fcc4d4d0fdaa38a5efecc7fe7990</url>
  <id>9984d0281c68fcc4d4d0fdaa38a5efecc7fe7990</id>
  <committed-date>2009-05-30T05:10:29-07:00</committed-date>
  <authored-date>2009-05-30T05:10:29-07:00</authored-date>
  <message>Update rakelib</message>
  <tree>9cb53aba1eae27da3c67a8965d0f694e9c55718c</tree>
  <committer>
    <name>charpi</name>
    <email>charpi@3ab005ec-33ed-11dd-9e78-a92e4af85449</email>
  </committer>
</commit>
