|
| 1 | +defmodule Localize.ReadmeLinksTest do |
| 2 | + @moduledoc """ |
| 3 | + The README's links to source files carry the version in their path, and |
| 4 | + nothing regenerates them — unlike the `mix.exs` package links, which |
| 5 | + interpolate `@version`. They were left pointing at the previous release |
| 6 | + twice in a row, once serving a LICENSE that predated the change the release |
| 7 | + was about, so the check is here rather than in a reviewer's memory. |
| 8 | +
|
| 9 | + """ |
| 10 | + |
| 11 | + use ExUnit.Case, async: true |
| 12 | + |
| 13 | + @source_links ~r{https://github\.com/elixir-localize/localize/blob/v([0-9]+\.[0-9]+\.[0-9]+)/} |
| 14 | + |
| 15 | + test "every versioned source link points at the current version" do |
| 16 | + version = Localize.MixProject.project()[:version] |
| 17 | + readme = File.read!(Path.join(__DIR__, "../../README.md")) |
| 18 | + |
| 19 | + stale = |
| 20 | + @source_links |
| 21 | + |> Regex.scan(readme) |
| 22 | + |> Enum.map(fn [_match, pinned] -> pinned end) |
| 23 | + |> Enum.uniq() |
| 24 | + |> Enum.reject(&(&1 == version)) |
| 25 | + |
| 26 | + assert stale == [], |
| 27 | + "README links to v#{Enum.join(stale, ", v")} but the package is v#{version}. " <> |
| 28 | + "Update the blob/v… paths in README.md to v#{version}." |
| 29 | + end |
| 30 | + |
| 31 | + test "guide and module links resolve to hexdocs rather than GitHub" do |
| 32 | + # A GitHub blob link drops the reader out of the rendered documentation |
| 33 | + # into raw markdown. Only genuine source files with no hexdocs page — the |
| 34 | + # licence, the skill definition — belong on GitHub. |
| 35 | + readme = File.read!(Path.join(__DIR__, "../../README.md")) |
| 36 | + |
| 37 | + offenders = |
| 38 | + ~r{https://github\.com/elixir-localize/localize/blob/v[0-9.]+/([^\s\)]+)} |
| 39 | + |> Regex.scan(readme) |
| 40 | + |> Enum.map(fn [_match, path] -> path end) |
| 41 | + |> Enum.reject(&(&1 in ["LICENSE.md", "skills/localize/SKILL.md"])) |
| 42 | + |
| 43 | + assert offenders == [], |
| 44 | + "These README links go to GitHub but have a rendered hexdocs page: " <> |
| 45 | + Enum.join(offenders, ", ") |
| 46 | + end |
| 47 | +end |
0 commit comments