Skip to content

Commit c154edf

Browse files
committed
Add WarningCounter tests for HTML and Epub fixture tests
1 parent e06a5e0 commit c154edf

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-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>"
@@ -275,4 +278,47 @@ defmodule ExDoc.Formatter.EPUBTest do
275278
after
276279
File.rm_rf!("test/tmp/epub_assets")
277280
end
281+
282+
describe "warning counter" do
283+
@describetag :warning_counter
284+
285+
test "4 warnings are counted when using warnings_as_errors: true", context do
286+
isolated_warning_counter do
287+
output =
288+
capture_io(:stderr, fn ->
289+
generate_docs(
290+
doc_config(context,
291+
skip_undefined_reference_warnings_on: [],
292+
warnings_as_errors: true
293+
)
294+
)
295+
end)
296+
297+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:2: Warnings"
298+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:18: Warnings.foo/0"
299+
300+
assert output =~
301+
~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:13: c:Warnings.handle_foo/0"
302+
303+
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
304+
305+
assert ExDoc.WarningCounter.count() == 4
306+
end
307+
end
308+
309+
test "warnings are still counted even with warnings_as_errors: false", context do
310+
isolated_warning_counter do
311+
capture_io(:stderr, fn ->
312+
generate_docs(
313+
doc_config(context,
314+
skip_undefined_reference_warnings_on: [],
315+
warnings_as_errors: false
316+
)
317+
)
318+
end)
319+
320+
assert ExDoc.WarningCounter.count() == 4
321+
end
322+
end
323+
end
278324
end

test/ex_doc/formatter/html_test.exs

Lines changed: 60 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,7 @@ 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 =~ ~R"warning: .+index.html redirects to Randomerror.html, which does not exist\n"
128130
assert File.regular?(tmp_dir <> "/html/index.html")
129131
assert File.regular?(tmp_dir <> "/html/RandomError.html")
130132
end
@@ -141,6 +143,63 @@ defmodule ExDoc.Formatter.HTMLTest do
141143
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
142144
end
143145

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

0 commit comments

Comments
 (0)