Skip to content

Commit 1511fbc

Browse files
committed
Improve coverage
1 parent b88db58 commit 1511fbc

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

lib/ex_doc/formatter/html.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ defmodule ExDoc.Formatter.HTML do
371371
group = GroupMatcher.match_extra(groups, input)
372372
title = title || title_text || filename_to_title(input)
373373

374-
source_path = Path.relative_to(input, ".")
374+
source_path = input |> Path.relative_to(File.cwd!()) |> String.replace_leading("./", "")
375375

376376
source_url =
377377
if url = config.source_url_pattern do

test/ex_doc/formatter/html_test.exs

+28-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ defmodule ExDoc.Formatter.HTMLTest do
3737
assets: "test/tmp/html_assets",
3838
output: output_dir(),
3939
source_beam: beam_dir(),
40+
source_url: "https://github.com/elixir-lang/elixir",
4041
logo: "test/fixtures/elixir.png",
4142
extras: [
4243
"test/fixtures/LICENSE",
@@ -349,6 +350,9 @@ defmodule ExDoc.Formatter.HTMLTest do
349350

350351
assert content =~ "<p><strong>raw content</strong></p>"
351352

353+
assert content =~
354+
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/README.md#L1" title="View Source"}
355+
352356
content = File.read!("#{output_dir()}/plaintextfiles.html")
353357

354358
assert content =~
@@ -359,21 +363,39 @@ defmodule ExDoc.Formatter.HTMLTest do
359363
assert plain_text_file =~
360364
~R{<pre>\nThis is plain\n text and nothing\n.+\s+good bye\n</pre>}s
361365

362-
assert plain_text_file =~ ~R{\n## Neither formatted\n}
363-
assert plain_text_file =~ ~R{\n `t:term/0`\n}
366+
assert plain_text_file =~ ~s{\n## Neither formatted\n}
367+
assert plain_text_file =~ ~s{\n `t:term/0`\n}
364368

365-
plain_text_file = File.read!("#{output_dir()}/license.html")
369+
license = File.read!("#{output_dir()}/license.html")
366370

367-
assert plain_text_file =~
371+
assert license =~
368372
~s{<pre>\nLicensed under the Apache License, Version 2.0 (the &quot;License&quot;)}
369373

370374
content = File.read!("#{output_dir()}/livebookfile.html")
371375

372376
assert content =~
373-
~R{<p>Read <code class="inline">.livemd</code> files generated by <a href="https://github.com/livebook-dev/livebook">livebook</a>.}
377+
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/LivebookFile.livemd#L1" title="View Source"}
374378

375379
assert content =~
376-
~R{<img src="https://livebook.dev/badge/v1/blue.svg" alt="Run in Livebook" width="150" />}
380+
~s{<p>Read <code class="inline">.livemd</code> files generated by <a href="https://github.com/livebook-dev/livebook">livebook</a>.}
381+
382+
assert content =~
383+
~s{<img src="https://livebook.dev/badge/v1/blue.svg" alt="Run in Livebook" width="150" />}
384+
end
385+
386+
test "with absolute and dot-relative paths for extra" do
387+
config = doc_config(extras: ["./test/fixtures/README.md", Path.expand("test/fixtures/LivebookFile.livemd")])
388+
generate_docs(config)
389+
390+
content = File.read!("#{output_dir()}/readme.html")
391+
392+
assert content =~
393+
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/README.md#L1" title="View Source"}
394+
395+
content = File.read!("#{output_dir()}/livebookfile.html")
396+
397+
assert content =~
398+
~s{<a href="https://github.com/elixir-lang/elixir/blob/master/test/fixtures/LivebookFile.livemd#L1" title="View Source"}
377399
end
378400

379401
test "without any other content" do

0 commit comments

Comments
 (0)