Skip to content

Commit 037ec01

Browse files
committed
Clean up epub tests
1 parent 0b6eb87 commit 037ec01

File tree

1 file changed

+33
-48
lines changed

1 file changed

+33
-48
lines changed

test/ex_doc/formatter/epub_test.exs

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ defmodule ExDoc.Formatter.EPUBTest do
2424
formatter: "epub",
2525
output: tmp_dir <> "/epub",
2626
source_beam: "test/tmp/beam",
27-
extras: ["test/fixtures/README.md"],
2827
skip_undefined_reference_warnings_on: ["Warnings"]
2928
]
3029
end
@@ -63,7 +62,7 @@ defmodule ExDoc.Formatter.EPUBTest do
6362
assert content =~ ~r{<html.*lang="fr".*xmlns:epub="http://www.idpf.org/2007/ops">}ms
6463
end
6564

66-
test "allows to set the authors of the book", %{tmp_dir: tmp_dir} = context do
65+
test "allows to set the authors of the document", %{tmp_dir: tmp_dir} = context do
6766
generate_docs_and_unzip(context, doc_config(context, authors: ["John Doe", "Jane Doe"]))
6867

6968
content = File.read!(tmp_dir <> "/epub/OEBPS/content.opf")
@@ -108,7 +107,6 @@ defmodule ExDoc.Formatter.EPUBTest do
108107
assert File.regular?("#{oebps_dir}/content.opf")
109108
assert File.regular?("#{oebps_dir}/nav.xhtml")
110109
assert File.regular?("#{oebps_dir}/title.xhtml")
111-
assert File.regular?("#{oebps_dir}/readme.xhtml")
112110
assert File.regular?("#{oebps_dir}/CompiledWithDocs.xhtml")
113111
assert File.regular?("#{oebps_dir}/CompiledWithDocs.Nested.xhtml")
114112
assert [_] = Path.wildcard("#{dist_dir}/epub-*.js")
@@ -129,7 +127,7 @@ defmodule ExDoc.Formatter.EPUBTest do
129127
end
130128

131129
test "generates the readme file", %{tmp_dir: tmp_dir} = context do
132-
config = doc_config(context, main: "README")
130+
config = doc_config(context, main: "README", extras: ["test/fixtures/README.md"])
133131
generate_docs_and_unzip(context, config)
134132

135133
content = File.read!(tmp_dir <> "/epub/OEBPS/readme.xhtml")
@@ -174,13 +172,13 @@ defmodule ExDoc.Formatter.EPUBTest do
174172
"CompiledWithDocs.Nested.xhtml"
175173
]
176174

177-
test "before_closing_*_tags required by the user are in the right place",
178-
%{tmp_dir: tmp_dir} = context do
175+
test "generates before_closing_*_tags using functions", %{tmp_dir: tmp_dir} = context do
179176
generate_docs_and_unzip(
180177
context,
181178
doc_config(context,
182179
before_closing_head_tag: &before_closing_head_tag/1,
183-
before_closing_body_tag: &before_closing_body_tag/1
180+
before_closing_body_tag: &before_closing_body_tag/1,
181+
extras: ["test/fixtures/README.md"]
184182
)
185183
)
186184

@@ -193,13 +191,13 @@ defmodule ExDoc.Formatter.EPUBTest do
193191
end
194192
end
195193

196-
test "before_closing_*_tags required by the user are in the right place using map",
197-
%{tmp_dir: tmp_dir} = context do
194+
test "generates before_closing_*_tags using maps", %{tmp_dir: tmp_dir} = context do
198195
generate_docs_and_unzip(
199196
context,
200197
doc_config(context,
201198
before_closing_head_tag: %{epub: "<meta name=StaticDemo>"},
202-
before_closing_body_tag: %{epub: "<p>StaticDemo</p>"}
199+
before_closing_body_tag: %{epub: "<p>StaticDemo</p>"},
200+
extras: ["test/fixtures/README.md"]
203201
)
204202
)
205203

@@ -212,13 +210,13 @@ defmodule ExDoc.Formatter.EPUBTest do
212210
end
213211
end
214212

215-
test "before_closing_*_tags required by the user are in the right place using a MFA",
216-
%{tmp_dir: tmp_dir} = context do
213+
test "generates before_closing_*_tags using MFA", %{tmp_dir: tmp_dir} = context do
217214
generate_docs_and_unzip(
218215
context,
219216
doc_config(context,
220217
before_closing_head_tag: {__MODULE__, :before_closing_head_tag, ["Demo"]},
221-
before_closing_body_tag: {__MODULE__, :before_closing_body_tag, ["Demo"]}
218+
before_closing_body_tag: {__MODULE__, :before_closing_body_tag, ["Demo"]},
219+
extras: ["test/fixtures/README.md"]
222220
)
223221
)
224222

@@ -231,7 +229,7 @@ defmodule ExDoc.Formatter.EPUBTest do
231229
end
232230
end
233231

234-
test "assets required by the user end up in the right place", %{tmp_dir: tmp_dir} = context do
232+
test "generates assets required by the user", %{tmp_dir: tmp_dir} = context do
235233
File.mkdir_p!("test/tmp/epub_assets/hello")
236234
File.touch!("test/tmp/epub_assets/hello/world.png")
237235
File.touch!("test/tmp/epub_assets/hello/world.pdf")
@@ -256,43 +254,30 @@ defmodule ExDoc.Formatter.EPUBTest do
256254
describe "warnings" do
257255
@describetag :warnings
258256

259-
test "multiple warnings are registered when using warnings_as_errors: true", context do
260-
Utils.unset_warned()
261-
262-
output =
263-
capture_io(:stderr, fn ->
264-
generate_docs(
265-
doc_config(context,
266-
skip_undefined_reference_warnings_on: [],
267-
warnings_as_errors: true
257+
for warnings_as_errors <- [true, false] do
258+
test "when warnings_as_errors: #{warnings_as_errors}", context do
259+
Utils.unset_warned()
260+
261+
output =
262+
capture_io(:stderr, fn ->
263+
generate_docs(
264+
doc_config(context,
265+
skip_undefined_reference_warnings_on: [],
266+
warnings_as_errors: unquote(warnings_as_errors)
267+
)
268268
)
269-
)
270-
end)
271-
272-
# TODO: remove check when we require Elixir v1.16
273-
if Version.match?(System.version(), ">= 1.16.0-rc") do
274-
assert output =~ ~S|moduledoc `Warnings.bar/0`|
275-
assert output =~ ~S|typedoc `Warnings.bar/0`|
276-
assert output =~ ~S|doc callback `Warnings.bar/0`|
277-
assert output =~ ~S|doc `Warnings.bar/0`|
278-
end
279-
280-
assert Utils.unset_warned()
281-
end
282-
283-
test "warnings are registered even with warnings_as_errors: false", context do
284-
Utils.unset_warned()
269+
end)
285270

286-
capture_io(:stderr, fn ->
287-
generate_docs(
288-
doc_config(context,
289-
skip_undefined_reference_warnings_on: [],
290-
warnings_as_errors: false
291-
)
292-
)
293-
end)
271+
# TODO: remove check when we require Elixir v1.16
272+
if Version.match?(System.version(), ">= 1.16.0-rc") do
273+
assert output =~ ~S|moduledoc `Warnings.bar/0`|
274+
assert output =~ ~S|typedoc `Warnings.bar/0`|
275+
assert output =~ ~S|doc callback `Warnings.bar/0`|
276+
assert output =~ ~S|doc `Warnings.bar/0`|
277+
end
294278

295-
assert Utils.unset_warned()
279+
assert Utils.unset_warned()
280+
end
296281
end
297282
end
298283
end

0 commit comments

Comments
 (0)