2
2
ExUnit . start [ ]
3
3
4
4
defmodule IEx.Case do
5
+ @ moduledoc false
6
+
7
+ #
8
+ # Provides convenience functions for testing IEx-related functionality.
9
+ # Use this module inside your test module like this:
10
+ #
11
+ # defmodule IEx.InteractionTest do
12
+ # use IEx.Case
13
+ #
14
+ # test :input do
15
+ # assert capture_iex("1+2") == "3"
16
+ # end
17
+ # end
18
+ #
19
+ # The environment provided by capture_iex is mostly similar to the normal IEx
20
+ # session, except colors are disabled by default and .iex files are not
21
+ # loaded.
22
+ #
23
+ # You can provide your own IEx.Options and a path to a .iex file as
24
+ # additional arguments to the capture_iex function.
25
+ #
26
+
5
27
defmacro __using__ ( _ ) do
6
28
quote do
7
29
use ExUnit.Case , async: false
@@ -21,28 +43,26 @@ defmodule IEx.Case do
21
43
end
22
44
end
23
45
46
+ @ doc """
47
+ Starts an IEx eval loop, feeds it the provided input and returns produced
48
+ output. The output is stripped of the first intro line and of any trailing
49
+ whitespace.
50
+
51
+ Options, if provided, will be set before the eval loop is started.
52
+
53
+ If you provide the dot_iex_path argument, it will be passed to
54
+ IEx.Server.start to be used in the normal .iex loading process.
55
+ """
24
56
def capture_iex ( input , options // [ ] , dot_iex_path // "" ) do
25
57
Enum . each options , fn { opt , value } ->
26
58
IEx.Options . set ( opt , value )
27
59
end
28
60
29
61
ExUnit.CaptureIO . capture_io ( input , fn ->
30
- IEx.Server . start ( iex_config ( dot_iex_path: dot_iex_path ) )
62
+ IEx.Server . start ( IEx . boot_config ( dot_iex_path: dot_iex_path ) )
31
63
end ) |> strip_iex
32
64
end
33
65
34
- def iex_exception ( name , message // "" ) do
35
- % r /#{iex_format_exception(name, message)}/
36
- end
37
-
38
- def iex_format_exception ( name , message // "" ) do
39
- "\\ *\\ * \\ (#{ Module . to_binary name } \\ ) (.*?)#{ message } "
40
- end
41
-
42
- defp iex_config ( opts ) do
43
- IEx . boot_config ( opts )
44
- end
45
-
46
66
defp strip_iex ( string ) do
47
67
string
48
68
|> strip_line # strip the greeting
0 commit comments