From d609d1900b36dd7e1a267d4cfb7b3570dd5b081d Mon Sep 17 00:00:00 2001 From: Brad Hanks Date: Mon, 1 Jan 2024 12:53:50 -0700 Subject: [PATCH 1/4] Update utils.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove warning: Compiling 5 files (.ex) warning: Application.get_env/3 is discouraged in the module body, use Application.compile_env/3 instead │ 6 │ if Application.get_env(:bypass, :enable_debug_log, false) do │ ~ │ └─ lib/bypass/utils.ex:6:18: Bypass.Utils (module) --- lib/bypass/utils.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bypass/utils.ex b/lib/bypass/utils.ex index 0c1f1a1..3c7280b 100644 --- a/lib/bypass/utils.ex +++ b/lib/bypass/utils.ex @@ -3,7 +3,7 @@ defmodule Bypass.Utils do Application.load(:bypass) - if Application.get_env(:bypass, :enable_debug_log, false) do + if Application.compile_env(:bypass, :enable_debug_log, false) do defmacro debug_log(msg) do quote bind_quoted: [msg: msg] do require Logger From 422aeefef12678d3692ba9df873309bc60a712be Mon Sep 17 00:00:00 2001 From: Brad Hanks Date: Mon, 1 Jan 2024 14:51:05 -0700 Subject: [PATCH 2/4] fix Mix.Config warnings --- config/config.exs | 2 +- test/bypass_test.exs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.exs b/config/config.exs index a1625b8..b28243c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,6 +1,6 @@ # This file is responsible for configuring your application # and its dependencies with the aid of the Mix.Config module. -use Mix.Config +import Config config :bypass, test_framework: :ex_unit diff --git a/test/bypass_test.exs b/test/bypass_test.exs index 6f41000..7f247c8 100644 --- a/test/bypass_test.exs +++ b/test/bypass_test.exs @@ -541,7 +541,7 @@ defmodule BypassTest do end test "Bypass.verify_expectations! - with ESpec it will check if the expectations are being met" do - Mix.Config.persist(bypass: [test_framework: :espec]) + Application.put_all_env(bypass: [test_framework: :espec]) # Fail: no requests bypass = prepare_stubs() @@ -579,7 +579,7 @@ defmodule BypassTest do Bypass.verify_expectations!(bypass) end - Mix.Config.persist(bypass: [test_framework: :ex_unit]) + Application.put_all_env(bypass: [test_framework: :ex_unit]) end test "Bypass.open/1 raises when cannot start child" do From e74e84569a426a0ff7d7dd8fa0e69816ddee5c0f Mon Sep 17 00:00:00 2001 From: Bartosz Szafran Date: Wed, 10 Apr 2024 09:18:05 +0200 Subject: [PATCH 3/4] Use compile_env!/2 instead of compile_env/3 &Application.compile_env!/2 is available since 1.10.0, whereas the &Application.compile_env/3 since 1.14.0. --- lib/bypass/utils.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bypass/utils.ex b/lib/bypass/utils.ex index 3c7280b..c92798e 100644 --- a/lib/bypass/utils.ex +++ b/lib/bypass/utils.ex @@ -3,7 +3,7 @@ defmodule Bypass.Utils do Application.load(:bypass) - if Application.compile_env(:bypass, :enable_debug_log, false) do + if Application.compile_env!(:bypass, :enable_debug_log) do defmacro debug_log(msg) do quote bind_quoted: [msg: msg] do require Logger From 9482226471087624c4e1f1a73a7a3b02b07d04ad Mon Sep 17 00:00:00 2001 From: Bartosz Szafran Date: Wed, 10 Apr 2024 09:25:32 +0200 Subject: [PATCH 4/4] Use Application.get_env/3 in macro to avoid compiliation errors --- lib/bypass/utils.ex | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/bypass/utils.ex b/lib/bypass/utils.ex index c92798e..50674b0 100644 --- a/lib/bypass/utils.ex +++ b/lib/bypass/utils.ex @@ -3,16 +3,14 @@ defmodule Bypass.Utils do Application.load(:bypass) - if Application.compile_env!(:bypass, :enable_debug_log) do - defmacro debug_log(msg) do - quote bind_quoted: [msg: msg] do + defmacro debug_log(msg) do + quote bind_quoted: [msg: msg] do + if Application.get_env(:bypass, :enable_debug_log, false) do require Logger Logger.debug(["[bypass] ", msg]) + else + :ok end end - else - defmacro debug_log(_msg) do - :ok - end end end