Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 8171c6ceed4ae19b01cad2efe57d7480cb0dca0b 1 parent b840901
José Valim authored April 23, 2012

Showing 1 changed file with 8 additions and 7 deletions. Show diff stats Hide diff stats

  1. 15  test/elixir/kernel/require_test.exs
15  test/elixir/kernel/require_test.exs
... ...
@@ -1,12 +1,12 @@
1 1
 Code.require_file "../../test_helper", __FILE__
2 2
 
3 3
 defmodule Kernel.RequireTest.Nested do
4  
-  def value, do: 1
  4
+  defmacro value, do: 1
5 5
 end
6 6
 
7  
-refer Kernel.RequireTest.Nested
8  
-
9 7
 defmodule Kernel.RequireTest do
  8
+  require Kernel.RequireTest.Nested, as: Nested
  9
+
10 10
   use ExUnit.Case
11 11
 
12 12
   defmacro my_macro do
@@ -28,10 +28,6 @@ defmodule Kernel.RequireTest do
28 28
     assert_equal :"__MAIN__.lists.Bar", MyList.Bar
29 29
   end
30 30
 
31  
-  test :automatic_require do
32  
-    assert_equal 1, Nested.value
33  
-  end
34  
-
35 31
   test :double_named_require do
36 32
     require Kernel.RequireTest.Nested, as: Nested2
37 33
     assert_equal 1, Nested.value
@@ -60,4 +56,9 @@ defmodule Kernel.RequireTest do
60 56
   test :locals_with_default_are_always_required do
61 57
     assert_equal 6, my_macro_with_default
62 58
   end
  59
+
  60
+  test :cannot_be_called_dynamically_even_if_required do
  61
+    x = Nested
  62
+    assert_raises UndefinedFunctionError, fn -> x.value end
  63
+  end
63 64
 end

0 notes on commit 8171c6c

Please sign in to comment.
Something went wrong with that request. Please try again.