Yeah, that it would work since the options are just a keyword list. B I
worry that because that behavior isn't documented it could be confusing to
folks. That's why I was thinking there could be an official, documented way
of passing these options to custom formatters.
Alternatively, we could just document that `ExUnit.configure/1` accepts the
currently documented options, but can also accept any other options that
might be needed as configuration for cases like this.
On Friday, August 17, 2018 at 1:14:45 PM UTC+2, José Valim wrote:
>
> 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 <[email protected]
> <javascript:>> 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 [email protected] <javascript:>.
>> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-core/6a8e6364-1988-4223-bb0f-652a394f1293%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.