Skip to content

Commit

Permalink
Add WarningCounter tests for HTML and Epub fixture tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eksperimental committed Jun 2, 2023
1 parent e06a5e0 commit c154edf
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
46 changes: 46 additions & 0 deletions test/ex_doc/formatter/epub_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
defmodule ExDoc.Formatter.EPUBTest do
use ExUnit.Case, async: true

import ExUnit.CaptureIO
import TestHelper, only: [isolated_warning_counter: 1]

@moduletag :tmp_dir

@before_closing_head_tag_content_epub "UNIQUE:<dont-escape>&copy;BEFORE-CLOSING-HEAD-TAG-HTML</dont-escape>"
Expand Down Expand Up @@ -275,4 +278,47 @@ defmodule ExDoc.Formatter.EPUBTest do
after
File.rm_rf!("test/tmp/epub_assets")
end

describe "warning counter" do
@describetag :warning_counter

test "4 warnings are counted when using warnings_as_errors: true", context do
isolated_warning_counter do
output =
capture_io(:stderr, fn ->
generate_docs(
doc_config(context,
skip_undefined_reference_warnings_on: [],
warnings_as_errors: true
)
)
end)

assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:2: Warnings"
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:18: Warnings.foo/0"

assert output =~
~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:13: c:Warnings.handle_foo/0"

assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"

assert ExDoc.WarningCounter.count() == 4
end
end

test "warnings are still counted even with warnings_as_errors: false", context do
isolated_warning_counter do
capture_io(:stderr, fn ->
generate_docs(
doc_config(context,
skip_undefined_reference_warnings_on: [],
warnings_as_errors: false
)
)
end)

assert ExDoc.WarningCounter.count() == 4
end
end
end
end
61 changes: 60 additions & 1 deletion test/ex_doc/formatter/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule ExDoc.Formatter.HTMLTest do
use ExUnit.Case, async: true

import ExUnit.CaptureIO
import TestHelper, only: [isolated_warning_counter: 1]

alias ExDoc.Formatter.HTML

@moduletag :tmp_dir
Expand Down Expand Up @@ -124,7 +126,7 @@ defmodule ExDoc.Formatter.HTMLTest do
generate_docs(doc_config(context, main: "Randomerror"))
end)

assert output =~ "warning: index.html redirects to Randomerror.html, which does not exist\n"
assert output =~ ~R"warning: .+index.html redirects to Randomerror.html, which does not exist\n"
assert File.regular?(tmp_dir <> "/html/index.html")
assert File.regular?(tmp_dir <> "/html/RandomError.html")
end
Expand All @@ -141,6 +143,63 @@ defmodule ExDoc.Formatter.HTMLTest do
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"
end

describe "warning counter" do
@describetag :warning_counter

test "4 warnings are counted when using warnings_as_errors: true", context do
isolated_warning_counter do
output =
capture_io(:stderr, fn ->
generate_docs(
doc_config(context,
skip_undefined_reference_warnings_on: [],
warnings_as_errors: true
)
)
end)

assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:2: Warnings"
assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:18: Warnings.foo/0"

assert output =~
~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:13: c:Warnings.handle_foo/0"

assert output =~ ~r"Warnings.bar/0.*\n test/fixtures/warnings.ex:8: t:Warnings.t/0"

assert ExDoc.WarningCounter.count() == 4
end
end

test "warnings are still counted even with warnings_as_errors: false", context do
isolated_warning_counter do
capture_io(:stderr, fn ->
generate_docs(
doc_config(context,
skip_undefined_reference_warnings_on: [],
warnings_as_errors: false
)
)
end)

assert ExDoc.WarningCounter.count() == 4
end
end

test "1 warning is counted when using warnings_as_errors: true", context do
isolated_warning_counter do
output =
capture_io(:stderr, fn ->
generate_docs(doc_config(context, main: "DoesNotExist", warnings_as_errors: true))
end)

assert output =~
~R"warning: .+index.html redirects to DoesNotExist.html, which does not exist\n"

assert ExDoc.WarningCounter.count() == 1
end
end
end

test "generates headers for index.html and module pages", %{tmp_dir: tmp_dir} = context do
generate_docs(doc_config(context, main: "RandomError"))
content_index = File.read!(tmp_dir <> "/html/index.html")
Expand Down

0 comments on commit c154edf

Please sign in to comment.