I believe currently we pass all of the options given to configure. So you
could do:

ExUnit.configure custom_formatter: %{print_results: ...}


Would this work? Is this acceptable?



*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D

On Fri, Aug 17, 2018 at 1:07 PM, Devon Estes <devon.c.es...@gmail.com>
wrote:

> I'm writing a custom formatter for ExUnit and there is some configuration
> I would like the user to be able to do. However, it would be much better
> for the configuration to be able to happen by passing arguments to the
> `init/1` callback so we don't need to rely on compile time application
> config for this. Right now, since all custom formatters are just passed the
> ExUnit configuration when they're started in 
> `ex_unit/lib/ex_unit/event_manager.ex`,
> and the user can't control how these custom formatters are started, I don't
> see a way to do this.
>
> My proposal is to make a small change to the ExUnit configuration for
> formatters. Instead of only allowing a list of module names representing
> the GenServer we're going to use as formatters, we can also accept a tuple
> that contains the module name of our GenServer as well as configuration for
> that formatter. For example:
>
> ExUnit.configure(formatters: [ExUnit.CLIFormatter, {CustomFormatter,
> %{print_results: false, email_results: true, api_key:
> System.get_env("API_KEY")}}])
>
> Since then these options would be passed to our CustomFormatter when it's
> started, it would be easy enough for me to pick them up by doing:
>
> def init(opts) do
>   {_, my_opts} = Enum.find(opts[:formatters], {nil, %{}}, fn
>     {__MODULE__, _} -> true
>     _ -> false
>   end)
>
>   {:ok, my_opts}
> 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-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/elixir-lang-core/5e0ad079-0941-4fc9-b71f-
> 02cb4f641c1f%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/5e0ad079-0941-4fc9-b71f-02cb4f641c1f%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/CAGnRm4K8TwyEVQM_%2BTiXr0V2rGhw_suZr%2Br2o3%2BAbWL3%2BGbu4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to