From 98229529f6d154a3aff9e0decf05badae09c4a69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 17 Dec 2024 10:03:36 +0100 Subject: [PATCH] Do not warn for CaseTemplate options, closes #14077 --- lib/ex_unit/lib/ex_unit/case.ex | 7 ++++++- lib/ex_unit/lib/ex_unit/case_template.ex | 2 +- lib/ex_unit/test/ex_unit/case_template_test.exs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index 0a61ae74410..21701d870d9 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -315,6 +315,11 @@ defmodule ExUnit.Case do end end + @keys [:async, :group, :parameterize, :register] + + @doc false + def __keys__(opts), do: Keyword.take(opts, @keys) + @doc false def __register__(module, opts) do if not Keyword.keyword?(opts) do @@ -324,7 +329,7 @@ defmodule ExUnit.Case do end {register?, opts} = Keyword.pop(opts, :register, true) - {next_opts, opts} = Keyword.split(opts, [:async, :group, :parameterize]) + {next_opts, opts} = Keyword.split(opts, @keys) if opts != [] do IO.warn("unknown options given to ExUnit.Case: #{inspect(opts)}") diff --git a/lib/ex_unit/lib/ex_unit/case_template.ex b/lib/ex_unit/lib/ex_unit/case_template.ex index 0e4023a8ff0..2449b7c1998 100644 --- a/lib/ex_unit/lib/ex_unit/case_template.ex +++ b/lib/ex_unit/lib/ex_unit/case_template.ex @@ -83,7 +83,7 @@ defmodule ExUnit.CaseTemplate do # We inject this code in the module that calls "use MyTemplate". def __proxy__(module, opts) do quote do - use ExUnit.Case, unquote(opts) + use ExUnit.Case, ExUnit.Case.__keys__(unquote(opts)) setup_all context do unquote(module).__ex_unit__(:setup_all, context) diff --git a/lib/ex_unit/test/ex_unit/case_template_test.exs b/lib/ex_unit/test/ex_unit/case_template_test.exs index b5265a8ce55..d660a32eb8d 100644 --- a/lib/ex_unit/test/ex_unit/case_template_test.exs +++ b/lib/ex_unit/test/ex_unit/case_template_test.exs @@ -36,7 +36,7 @@ defmodule ExUnit.NestedCase do end defmodule ExUnit.CaseTemplateTest do - use ExUnit.SampleCase, async: true + use ExUnit.SampleCase, async: true, another_option: 123 use ExUnit.NestedCase two = 2