@@ -44,7 +44,7 @@ defmodule ExUnit.DocTestTest.ExceptionModule do
4444 def two_exceptions
4545end
4646
47- defmodule ExUnit.DocTestTest.SomewhatGoodModule do
47+ defmodule ExUnit.DocTestTest.SomewhatGoodModuleWithOnly do
4848 @ doc """
4949 iex> test_fun
5050 1
@@ -62,7 +62,7 @@ defmodule ExUnit.DocTestTest.SomewhatGoodModule do
6262 def test_fun1 , do: 1
6363end
6464
65- defmodule ExUnit.DocTestTest.SomewhatGoodModule1 do
65+ defmodule ExUnit.DocTestTest.SomewhatGoodModuleWithExcept do
6666 @ doc """
6767 iex> test_fun
6868 1
@@ -87,51 +87,42 @@ defmodule ExUnit.DocTestTest.NoImport do
8787 """
8888 def min ( a , b ) , do: max ( a , b )
8989end
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+
90104defmodule ExUnit.DocTestTest do
91105 use ExUnit.Case
92106
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+
96111 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
99114 doctest ExUnit.DocTestTest.NoImport
100115
101116 assert_raise ExUnit.DocTest.Error , fn ->
102117 doctest ExUnit.DocTestTest.ExceptionModule
103118 end
104119
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
122125 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
133126 end
134-
135- result || raise ( ExUnit.AssertionError , message: "Expected function given to format_rescue to fail" )
136127 end
137128end
0 commit comments