Allow Application.compile_env* to accept attributes (#11383)
This commit is contained in:
committed by
José Valim
parent
c28073b4fc
commit
00a0f07824
@@ -508,7 +508,7 @@ defmodule Application do
|
||||
# compile time instead of compile_env
|
||||
@doc since: "1.10.0"
|
||||
@spec compile_env(app, key | list, value) :: value
|
||||
defmacro compile_env(app, key_or_path, default \\ nil) when is_atom(app) do
|
||||
defmacro compile_env(app, key_or_path, default \\ nil) do
|
||||
if __CALLER__.function do
|
||||
raise "Application.compile_env/3 cannot be called inside functions, only in the module body"
|
||||
end
|
||||
@@ -545,7 +545,7 @@ defmodule Application do
|
||||
"""
|
||||
@doc since: "1.10.0"
|
||||
@spec compile_env!(app, key | list) :: value
|
||||
defmacro compile_env!(app, key_or_path) when is_atom(app) do
|
||||
defmacro compile_env!(app, key_or_path) do
|
||||
if __CALLER__.function do
|
||||
raise "Application.compile_env!/2 cannot be called inside functions, only in the module body"
|
||||
end
|
||||
|
||||
@@ -6,6 +6,8 @@ defmodule ApplicationTest do
|
||||
import PathHelpers
|
||||
import ExUnit.CaptureIO
|
||||
|
||||
@app :elixir
|
||||
|
||||
test "application environment" do
|
||||
assert_raise ArgumentError, ~r/because the application was not loaded nor configured/, fn ->
|
||||
Application.fetch_env!(:unknown, :unknown)
|
||||
@@ -75,12 +77,14 @@ defmodule ApplicationTest do
|
||||
|
||||
assert Application.put_env(:elixir, :unknown, nested: [key: :value]) == :ok
|
||||
|
||||
assert compile_env(@app, :unknown, :default) == [nested: [key: :value]]
|
||||
assert compile_env(:elixir, :unknown, :default) == [nested: [key: :value]]
|
||||
assert_received {:compile_env, :elixir, [:unknown], {:ok, [nested: [key: :value]]}}
|
||||
|
||||
assert compile_env(:elixir, :unknown) == [nested: [key: :value]]
|
||||
assert_received {:compile_env, :elixir, [:unknown], {:ok, [nested: [key: :value]]}}
|
||||
|
||||
assert compile_env!(@app, :unknown) == [nested: [key: :value]]
|
||||
assert compile_env!(:elixir, :unknown) == [nested: [key: :value]]
|
||||
assert_received {:compile_env, :elixir, [:unknown], {:ok, [nested: [key: :value]]}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user