diff options
author | CrowdHailer <peterhsaxton@gmail.com> | 2015-10-01 16:04:35 +0100 |
---|---|---|
committer | CrowdHailer <peterhsaxton@gmail.com> | 2015-10-01 16:04:35 +0100 |
commit | f2cd34f1a8b3fd7a05490e4845757820f1ae5fa8 (patch) | |
tree | 07efbb7be0b6bec76c1bdd73539fa0cf4d47204c | |
parent | ca5a9060ef0dd58b15840280c17374984740373d (diff) | |
download | elixir-f2cd34f1a8b3fd7a05490e4845757820f1ae5fa8.tar.gz |
use macro to show code sample in error message
-rw-r--r-- | lib/elixir/lib/kernel.ex | 2 | ||||
-rw-r--r-- | lib/elixir/test/elixir/kernel_test.exs | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/elixir/lib/kernel.ex b/lib/elixir/lib/kernel.ex index c7ecbc422..c69b58a61 100644 --- a/lib/elixir/lib/kernel.ex +++ b/lib/elixir/lib/kernel.ex @@ -3627,7 +3627,7 @@ defmodule Kernel do unquote(expanded).__using__(unquote(opts)) end _otherwise -> - raise ArgumentError, "invalid arguments for use, expected an atom or alias as argument" + raise ArgumentError, "invalid arguments for use, expected a compile time atom or alias, got: #{Macro.to_string(module)}" end) quote(do: (unquote_splicing calls)) end diff --git a/lib/elixir/test/elixir/kernel_test.exs b/lib/elixir/test/elixir/kernel_test.exs index 1b1dbd52e..14d5a2d39 100644 --- a/lib/elixir/test/elixir/kernel_test.exs +++ b/lib/elixir/test/elixir/kernel_test.exs @@ -660,13 +660,20 @@ defmodule KernelTest do end end - test "invalid argument" do - message = "invalid arguments for use, expected an atom or alias as argument" + test "invalid argument is literal" do + message = "invalid arguments for use, expected a compile time atom or alias, got: 42" assert_raise ArgumentError, message, fn -> Code.eval_string("use 42") end end + test "invalid argument is variable" do + message = "invalid arguments for use, expected a compile time atom or alias, got: variable" + assert_raise ArgumentError, message, fn -> + Code.eval_string("use variable") + end + end + test "multi-call" do assert capture_io(fn -> Code.eval_string("use UseMacro.{SampleA, SampleB,}", [], __ENV__) |