Very under tested project that I used to test this formatter:

Cover compiling modules ...
..

Finished in 0.1 seconds
2 tests, 0 failures

Randomized with seed 438070

Cover results
Percentage | Module
-----------|--------------------------
      0.0% | Elixir.Cover
      0.0% | Elixir.ImagerWeb.Instrumenter
     50.0% | Elixir.Imager.Application
      0.0% | Elixir.Imager.Convert
      0.0% | Elixir.ImagerWeb.ChannelCase
      0.0% | Elixir.ImagerWeb.UserSocket
      0.0% | Elixir.ImagerWeb.WebhookController
     6.45% | Elixir.ImagerWeb.Router.Helpers
    15.79% | Elixir.ImagerWeb.ErrorView
    45.45% | Elixir.ImagerWeb.ConnCase
     5.26% | Elixir.ImagerWeb.Endpoint
    23.81% | Elixir.Imager.Stats
     5.71% | Elixir.Imager
      0.0% | Elixir.ImagerWeb.Router
      0.0% | Elixir.ImagerWeb
-----------|--------------------------
     7.88% | Total

Screenshot with colours: https://cl.ly/0Y1K192Q220k

--

Łukasz Niemier
luk...@niemie.pl

W dniu środa, 9 maja 2018 13:25:04 UTC+2 użytkownik José Valim napisał:
>
> Can you please provide a sample of the output?
>
>
>
> *José Valimwww.plataformatec.com.br 
> <http://www.plataformatec.com.br/>Founder and Director of R&D*
>
> On Wed, May 9, 2018 at 12:22 PM, Łukasz Niemier <luk...@niemier.pl 
> <javascript:>> wrote:
>
>> This would greatly reduce people using additional coverage reporters like 
>> excoveralls or similar as some tools (at least GitLab CI that I am using) 
>> allows to parse test output to fetch general coverage from there.
>>
>> My proposal is to generate per module and total percentage from default 
>> coverage reporter. Example Coverage module that provides such result 
>> (additional there is additional option :threshold which colours resulting 
>> coverage red/green).
>>
>> defmodule Cover do
>>   @moduledoc false
>>
>>   @threshold 90
>>
>>   def start(compile_path, opts) do
>>     Mix.shell().info("Cover compiling modules ...")
>>     _ = :cover.start()
>>
>>     case :cover.compile_beam_directory(compile_path |> to_charlist) do
>>       results when is_list(results) ->
>>         :ok
>>
>>       {:error, _} ->
>>         Mix.raise("Failed to cover compile directory: " <> compile_path)
>>     end
>>
>>     output = opts[:output]
>>
>>     fn ->
>>       File.mkdir_p!(output)
>>
>>       Mix.shell().info("\nCover results")
>>
>>       {:result, ok, _fail} = :cover.analyse(:coverage, :module)
>>
>>       Mix.shell().info("Percentage | Module")
>>       Mix.shell().info("-----------|--------------------------")
>>
>>       total =
>>         ok
>>         |> Stream.each(&display(&1, opts))
>>         |> Stream.each(&html(&1, output))
>>         |> Enum.reduce({0, 0}, fn {_, {cov, not_cov}}, {tot_cov, 
>> tot_not_cov} ->
>>           {tot_cov + cov, tot_not_cov + not_cov}
>>         end)
>>
>>       Mix.shell().info("-----------|--------------------------")
>>
>>       display({"Total", total}, opts)
>>     end
>>   end
>>
>>   defp colour(percentage, threshold) when percentage > threshold, do: 
>> :green
>>   defp colour(_, _), do: :red
>>
>>   defp display({name, coverage}, opts) do
>>     threshold = Keyword.get(opts, :threshold, @threshold)
>>     percentage = percentage(coverage)
>>
>>     Mix.shell().info([
>>       colour(percentage, threshold),
>>       format(percentage, 9),
>>       "%",
>>       :reset,
>>       " | #{name}"
>>     ])
>>   end
>>
>>   defp html({mod, _}, output) do
>>     {:ok, _} = :cover.analyse_to_file(mod, '#{output}/#{mod}.html', 
>> [:html])
>>   end
>>
>>   defp percentage({0, 0}), do: 100
>>   defp percentage({cov, not_cov}), do: cov / (cov + not_cov) * 100
>>
>>   defp format(num, len) when is_integer(num) do
>>     num
>>     |> Integer.to_string()
>>     |> String.pad_leading(len)
>>   end
>>
>>   defp format(num, len) when is_float(num) do
>>     num
>>     |> Float.round(2)
>>     |> Float.to_string()
>>     |> String.pad_leading(len)
>>   end
>> end
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to elixir-lang-co...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/6ca4916a-8b3d-44c5-9df7-ba0467150a5a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/6ca4916a-8b3d-44c5-9df7-ba0467150a5a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/77aad7f1-f7a2-489a-b239-ada3197884d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to