@@ -28,22 +28,38 @@ defmodule ExUnit.DocTest do
28
28
doctest MyModule
29
29
end
30
30
31
- The `doctest` macro is going to loop all functions and macros
32
- defined in `MyModule`, parsing their documentation in search for
33
- code examples.
31
+ The `doctest` macro is going to loop through all functions and
32
+ macros defined in `MyModule`, parsing their documentation in
33
+ search for code examples.
34
34
35
35
A very basic example is:
36
36
37
37
iex> 1+1
38
38
2
39
39
40
- Multiline is also supported:
40
+ Expressions on multiple lines are also supported:
41
41
42
42
iex> Enum.map [1,2,3], fn(x) ->
43
43
...> x * 2
44
44
...> end
45
45
[2,4,6]
46
46
47
+ Multiple results can be checked within the same test:
48
+
49
+ iex> a = 1
50
+ 1
51
+ iex> a + 1
52
+ 2
53
+
54
+ If you want to keep any two tests separate from each other,
55
+ add an empty line between them:
56
+
57
+ iex> a = 1
58
+ 1
59
+
60
+ iex> a + 1 # will fail with a "function a/0 undefined" error
61
+ 2
62
+
47
63
Similarly to iex you can use numbers in your "prompts":
48
64
49
65
iex(1)> [1+2,
@@ -56,7 +72,7 @@ defmodule ExUnit.DocTest do
56
72
* Copy-pasting examples from an actual iex sessions
57
73
58
74
We also allow you to select or skip some functions when calling
59
- `doctest`. See its documentation documentation for more info.
75
+ `doctest`. See its documentation for more info.
60
76
61
77
## Exceptions
62
78
@@ -90,18 +106,16 @@ defmodule ExUnit.DocTest do
90
106
@ doc """
91
107
This macro is used to generate ExUnit test cases for doctests.
92
108
93
- There are three ways this macro can be used:
94
-
95
- * `doctest(Module)` — will generate tests for all doctests found
96
- in the module `Module`
109
+ Calling `doctest(Module)` will generate tests for all doctests found
110
+ in the module `Module`
97
111
98
112
Options can also be supplied:
99
113
100
114
* `:except` — generate tests for all functions except those listed
101
115
(list of `{function, arity}` tuples)
102
116
103
- * `:only` — generate tests only forfunctions listed
104
- (list of `{function, arity}` tuples)
117
+ * `:only` — generate tests only forfunctions listed
118
+ (list of `{function, arity}` tuples)
105
119
106
120
* `:import` — when true, one can test a function defined in the module
107
121
without referring to the module name. However, this is not
@@ -113,7 +127,7 @@ defmodule ExUnit.DocTest do
113
127
114
128
doctest MyModule, except: [trick_fun: 1]
115
129
116
- This macro is auto-imported into every `ExUnit.Case`.
130
+ This macro is auto-imported with every `ExUnit.Case`.
117
131
"""
118
132
defmacro doctest ( mod , opts // [ ] ) do
119
133
quote do
0 commit comments