Skip to content

Commit 984e098

Browse files
committed
Add WarningCounter tests for HTML and Epub fixture tests
1 parent c8c738c commit 984e098

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

test/ex_doc/formatter/epub_test.exs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
defmodule ExDoc.Formatter.EPUBTest do
22
use ExUnit.Case, async: true
33

4+
import ExUnit.CaptureIO
5+
import TestHelper, only: [isolated_warning_counter: 1]
6+
47
@moduletag :tmp_dir
58

69
@before_closing_head_tag_content_epub "UNIQUE:<dont-escape>&copy;BEFORE-CLOSING-HEAD-TAG-HTML</dont-escape>"
@@ -248,4 +251,47 @@ defmodule ExDoc.Formatter.EPUBTest do
248251
after
249252
File.rm_rf!("test/tmp/epub_assets")
250253
end
254+
255+
describe "warning counter" do
256+
@describetag :warning_counter
257+
258+
test "4 warnings are counted when using warnings_as_errors: true", context do
259+
isolated_warning_counter do
260+
output =
261+
capture_io(:stderr, fn ->
262+
generate_docs(
263+
doc_config(context,
264+
skip_undefined_reference_warnings_on: [],
265+
warnings_as_errors: true
266+
)
267+
)
268+
end)
269+
270+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:2: Warnings"
271+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:18: Warnings.foo/0"
272+
273+
assert output =~
274+
~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:13: c:Warnings.handle_foo/0"
275+
276+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
277+
278+
assert ExDoc.WarningCounter.count() == 4
279+
end
280+
end
281+
282+
test "warnings are still counted even with warnings_as_errors: false", context do
283+
isolated_warning_counter do
284+
capture_io(:stderr, fn ->
285+
generate_docs(
286+
doc_config(context,
287+
skip_undefined_reference_warnings_on: [],
288+
warnings_as_errors: false
289+
)
290+
)
291+
end)
292+
293+
assert ExDoc.WarningCounter.count() == 4
294+
end
295+
end
296+
end
251297
end

test/ex_doc/formatter/html_test.exs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule ExDoc.Formatter.HTMLTest do
22
use ExUnit.Case, async: true
33

44
import ExUnit.CaptureIO
5+
import TestHelper, only: [isolated_warning_counter: 1]
6+
57
alias ExDoc.Formatter.HTML
68

79
@moduletag :tmp_dir
@@ -124,7 +126,9 @@ defmodule ExDoc.Formatter.HTMLTest do
124126
generate_docs(doc_config(context, main: "Randomerror"))
125127
end)
126128

127-
assert output =~ "warning: index.html redirects to Randomerror.html, which does not exist\n"
129+
assert output =~
130+
~R"warning: .+index.html redirects to Randomerror.html, which does not exist\n"
131+
128132
assert File.regular?(tmp_dir <> "/html/index.html")
129133
assert File.regular?(tmp_dir <> "/html/RandomError.html")
130134
end
@@ -141,6 +145,63 @@ defmodule ExDoc.Formatter.HTMLTest do
141145
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
142146
end
143147

148+
describe "warning counter" do
149+
@describetag :warning_counter
150+
151+
test "4 warnings are counted when using warnings_as_errors: true", context do
152+
isolated_warning_counter do
153+
output =
154+
capture_io(:stderr, fn ->
155+
generate_docs(
156+
doc_config(context,
157+
skip_undefined_reference_warnings_on: [],
158+
warnings_as_errors: true
159+
)
160+
)
161+
end)
162+
163+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:2: Warnings"
164+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:18: Warnings.foo/0"
165+
166+
assert output =~
167+
~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:13: c:Warnings.handle_foo/0"
168+
169+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
170+
171+
assert ExDoc.WarningCounter.count() == 4
172+
end
173+
end
174+
175+
test "warnings are still counted even with warnings_as_errors: false", context do
176+
isolated_warning_counter do
177+
capture_io(:stderr, fn ->
178+
generate_docs(
179+
doc_config(context,
180+
skip_undefined_reference_warnings_on: [],
181+
warnings_as_errors: false
182+
)
183+
)
184+
end)
185+
186+
assert ExDoc.WarningCounter.count() == 4
187+
end
188+
end
189+
190+
test "1 warning is counted when using warnings_as_errors: true", context do
191+
isolated_warning_counter do
192+
output =
193+
capture_io(:stderr, fn ->
194+
generate_docs(doc_config(context, main: "DoesNotExist", warnings_as_errors: true))
195+
end)
196+
197+
assert output =~
198+
~R"warning: .+index.html redirects to DoesNotExist.html, which does not exist\n"
199+
200+
assert ExDoc.WarningCounter.count() == 1
201+
end
202+
end
203+
end
204+
144205
test "generates headers for index.html and module pages", %{tmp_dir: tmp_dir} = context do
145206
generate_docs(doc_config(context, main: "RandomError"))
146207
content_index = File.read!(tmp_dir <> "/html/index.html")

0 commit comments

Comments
 (0)