@@ -166,69 +166,56 @@ defmodule ExUnit.DocTest do
166166 exceptions_num = Enum . count exprs , exc_filter_fn
167167 if exceptions_num > 1 do
168168 # FIXME: stacktrace pointing to the doctest?
169- raise Error , message: "Multiple exceptions in one doctest case are not supported"
169+ raise Error , [ message: "Multiple exceptions in one doctest case are not supported" ]
170+
171+ # this doesn't work :( nothing is raised
172+ #raise Error[message: "Multiple exceptions in one doctest case are not supported"], [], stack
170173 end
171174
172175 { tests , whole_expr } = Enum . map_reduce exprs , "" , fn { expr , expected } , acc ->
173176 { test_case_content ( expr , expected , module , line , file , stack ) , acc <> expr <> "\n " }
174177 end
175- exception_expr = Enum . find ( exprs , exc_filter_fn )
178+ { exception , message } = case Enum . find ( exprs , exc_filter_fn ) do
179+ { _ , { :error , exception , message } } ->
180+ { exception , message }
181+ nil ->
182+ { nil , nil }
183+ end
176184
177- if nil? ( exception_expr ) do
178- quote do
179- unquote_splicing ( test_import ( module , do_import ) )
180- try do
181- # Put all tests into one context
182- unquote_splicing ( tests )
183- rescue
184- e in [ ExUnit.ExpectationError ] ->
185- raise e , [ ] , unquote ( stack )
186- actual ->
187- raise ExUnit.ExpectationError ,
188- [ prelude: "Expected doctest" ,
189- description: unquote ( whole_expr ) ,
190- expected: "without an exception" ,
191- reason: "complete" ,
192- actual: inspect ( actual ) ] ,
193- unquote ( stack )
194- end
195- end
196- else
197- { expr , { :error , exception , message } } = exception_expr
198- quote do
199- unquote_splicing ( test_import ( module , do_import ) )
200- try do
201- # Put all tests into one context
202- unquote_splicing ( tests )
203- rescue
204- e in [ ExUnit.ExpectationError ] ->
205- case e . reason do
206- "evaluate to" ->
207- raise e , [ ] , unquote ( stack )
208- "raise" ->
209- raise ( e )
210- end
211-
212- error in [ unquote ( exception ) ] ->
213- unless error . message == unquote ( message ) do
214- raise ExUnit.ExpectationError ,
215- [ prelude: "Expected doctest" ,
216- description: unquote ( expr ) ,
217- expected: "#{ inspect unquote ( exception ) } with message #{ inspect unquote ( message ) } " ,
218- reason: "raise" ,
219- actual: inspect ( error ) ] ,
220- unquote ( stack )
221- end
222-
223- actual ->
185+ quote do
186+ unquote_splicing ( test_import ( module , do_import ) )
187+ unquote ( gen_code_for_tests ( tests , whole_expr , exception , message , stack ) )
188+ end
189+ end
190+
191+ defp gen_code_for_tests ( tests , whole_expr , exception , message , stack ) do
192+ quote do
193+ try do
194+ # Put all tests into one context
195+ unquote_splicing ( tests )
196+ rescue
197+ e in [ ExUnit.ExpectationError ] ->
198+ raise e , [ ] , unquote ( stack )
199+
200+ error in [ unquote ( exception ) ] ->
201+ unless error . message == unquote ( message ) do
224202 raise ExUnit.ExpectationError ,
225203 [ prelude: "Expected doctest" ,
226204 description: unquote ( whole_expr ) ,
227- expected: "#{ inspect unquote ( exception ) } " ,
228- reason: "complete or raise" ,
229- actual: inspect ( actual ) ] ,
205+ expected: "#{ inspect unquote ( exception ) } with message #{ inspect unquote ( message ) } " ,
206+ reason: "raise" ,
207+ actual: inspect ( error ) ] ,
230208 unquote ( stack )
231- end
209+ end
210+
211+ error ->
212+ raise ExUnit.ExpectationError ,
213+ [ prelude: "Expected doctest" ,
214+ description: unquote ( whole_expr ) ,
215+ expected: "#{ inspect unquote ( exception ) } " ,
216+ reason: "complete or raise" ,
217+ actual: inspect ( error ) ] ,
218+ unquote ( stack )
232219 end
233220 end
234221 end
0 commit comments