Permalink
Browse files

Ensure a runtime error is raised if a macro is called at runtime

  • Loading branch information...
josevalim committed Apr 23, 2012
1 parent b840901 commit 8171c6ceed4ae19b01cad2efe57d7480cb0dca0b
Showing with 8 additions and 7 deletions.
  1. +8 −7 test/elixir/kernel/require_test.exs
@@ -1,12 +1,12 @@
Code.require_file "../../test_helper", __FILE__
defmodule Kernel.RequireTest.Nested do
- def value, do: 1
+ defmacro value, do: 1
end
-refer Kernel.RequireTest.Nested
-
defmodule Kernel.RequireTest do
+ require Kernel.RequireTest.Nested, as: Nested
+
use ExUnit.Case
defmacro my_macro do
@@ -28,10 +28,6 @@ defmodule Kernel.RequireTest do
assert_equal :"__MAIN__.lists.Bar", MyList.Bar
end
- test :automatic_require do
- assert_equal 1, Nested.value
- end
-
test :double_named_require do
require Kernel.RequireTest.Nested, as: Nested2
assert_equal 1, Nested.value
@@ -60,4 +56,9 @@ defmodule Kernel.RequireTest do
test :locals_with_default_are_always_required do
assert_equal 6, my_macro_with_default
end
+
+ test :cannot_be_called_dynamically_even_if_required do
+ x = Nested
+ assert_raises UndefinedFunctionError, fn -> x.value end
+ end
end

0 comments on commit 8171c6c

Please sign in to comment.