Skip to content

Commit 4573f25

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

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>"
@@ -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: 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)