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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/5e0ad079-0941-4fc9-b71f-02cb4f641c1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.