@@ -44,7 +44,7 @@ defmodule ExUnit.DocTestTest.ExceptionModule do
44
44
def two_exceptions
45
45
end
46
46
47
- defmodule ExUnit.DocTestTest.SomewhatGoodModule do
47
+ defmodule ExUnit.DocTestTest.SomewhatGoodModuleWithOnly do
48
48
@ doc """
49
49
iex> test_fun
50
50
1
@@ -62,7 +62,7 @@ defmodule ExUnit.DocTestTest.SomewhatGoodModule do
62
62
def test_fun1 , do: 1
63
63
end
64
64
65
- defmodule ExUnit.DocTestTest.SomewhatGoodModule1 do
65
+ defmodule ExUnit.DocTestTest.SomewhatGoodModuleWithExcept do
66
66
@ doc """
67
67
iex> test_fun
68
68
1
@@ -87,51 +87,42 @@ defmodule ExUnit.DocTestTest.NoImport do
87
87
"""
88
88
def min ( a , b ) , do: max ( a , b )
89
89
end
90
+
91
+ defmodule ExUnit.DocTestTest.Invalid do
92
+ @ doc """
93
+ iex> _a = 1
94
+ 1
95
+
96
+ iex> _a + 1
97
+ 2
98
+ """
99
+ def no_leak do
100
+ end
101
+ end
102
+
103
+
90
104
defmodule ExUnit.DocTestTest do
91
105
use ExUnit.Case
92
106
93
- # This is intentional. The doctests in DocTest's docs fail for demonstration
94
- # purposes.
95
- #doctest ExUnit.DocTest
107
+ # This is intentional. The doctests in DocTest's docs fail
108
+ # for demonstration purposes.
109
+ # doctest ExUnit.DocTest
110
+
96
111
doctest ExUnit.DocTestTest.GoodModule , import: true
97
- doctest ExUnit.DocTestTest.SomewhatGoodModule , only: [ test_fun: 0 ] , import: true
98
- doctest ExUnit.DocTestTest.SomewhatGoodModule1 , except: [ test_fun1: 0 ] , import: true
112
+ doctest ExUnit.DocTestTest.SomewhatGoodModuleWithOnly , only: [ test_fun: 0 ] , import: true
113
+ doctest ExUnit.DocTestTest.SomewhatGoodModuleWithExcept , except: [ test_fun1: 0 ] , import: true
99
114
doctest ExUnit.DocTestTest.NoImport
100
115
101
116
assert_raise ExUnit.DocTest.Error , fn ->
102
117
doctest ExUnit.DocTestTest.ExceptionModule
103
118
end
104
119
105
- test :var_leak do
106
- assert "nofile:9: function '_a'/0 undefined" = format_rescue ( """
107
- defmodule M do
108
- @doc \" \" \"
109
- iex> _a = 1
110
- 1
111
-
112
- iex> _a + 1
113
- 2
114
- \" \" \"
115
- def no_leak
116
- end
117
-
118
- defmodule M.Test do
119
- require ExUnit.DocTest
120
-
121
- ExUnit.DocTest.doctest M
120
+ test :no_var_leak do
121
+ assert_raise CompileError , % r "function '_a'/0 undefined" , fn ->
122
+ defmodule NeverCompiled do
123
+ import ExUnit.DocTest
124
+ doctest ExUnit.DocTestTest.Invalid
122
125
end
123
- """
124
- )
125
- end
126
-
127
- defp format_rescue ( expr ) do
128
- result = try do
129
- :elixir . eval ( to_char_list ( expr ) , [ ] )
130
- nil
131
- rescue
132
- error -> error . message
133
126
end
134
-
135
- result || raise ( ExUnit.AssertionError , message: "Expected function given to format_rescue to fail" )
136
127
end
137
128
end
0 commit comments