Skip to content

Commit 2caacae

Browse files
whatyouhidejosevalim
authored andcommitted
Add some specs and types to ExUnit.Formatter (#13130)
1 parent 1ff5e0c commit 2caacae

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/ex_unit/lib/ex_unit/formatter.ex

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ defmodule ExUnit.Formatter do
6767
load: pos_integer | nil
6868
}
6969

70+
@typedoc """
71+
A function that this module calls to format various things.
72+
"""
73+
@typedoc since: "1.16.0"
74+
@type formatter_callback :: (atom, term -> term)
75+
76+
@typedoc """
77+
Width for formatting.
78+
79+
For example, see `format_assertion_diff/4`.
80+
"""
81+
@typedoc since: "1.16.0"
82+
@type width :: non_neg_integer | :infinity
83+
7084
import Exception, only: [format_stacktrace_entry: 1, format_file_line: 3]
7185

7286
alias ExUnit.Diff
@@ -155,6 +169,14 @@ defmodule ExUnit.Formatter do
155169
@doc """
156170
Receives a test and formats its failure.
157171
"""
172+
@spec format_test_failure(
173+
ExUnit.Test.t(),
174+
[failure],
175+
non_neg_integer,
176+
width,
177+
formatter_callback
178+
) :: String.t()
179+
when failure: {atom, term, Exception.stacktrace()}
158180
def format_test_failure(test, failures, counter, width, formatter) do
159181
%ExUnit.Test{name: name, module: module, tags: tags} = test
160182

@@ -177,6 +199,14 @@ defmodule ExUnit.Formatter do
177199
@doc """
178200
Receives a test module and formats its failure.
179201
"""
202+
@spec format_test_all_failure(
203+
ExUnit.TestModule.t(),
204+
[failure],
205+
non_neg_integer,
206+
width,
207+
formatter_callback
208+
) :: String.t()
209+
when failure: {atom, term, Exception.stacktrace()}
180210
def format_test_all_failure(test_module, failures, counter, width, formatter) do
181211
name = test_module.name
182212

@@ -280,6 +310,12 @@ defmodule ExUnit.Formatter do
280310
for formatted content, the width (may be `:infinity`),
281311
and the formatter callback function.
282312
"""
313+
@spec format_assertion_diff(
314+
%ExUnit.AssertionError{},
315+
non_neg_integer,
316+
width,
317+
formatter_callback
318+
) :: keyword
283319
def format_assertion_diff(assert_error, padding_size, width, formatter)
284320

285321
def format_assertion_diff(%ExUnit.AssertionError{context: {:mailbox, _pins, []}}, _, _, _) do

0 commit comments

Comments
 (0)