From ac0f1d2a964739c9f198d582f370c26cb370a94c Mon Sep 17 00:00:00 2001 From: Sven Gehring Date: Thu, 8 Aug 2019 14:38:59 +0200 Subject: [PATCH] Make index redirect warning case-sensitive (#1077) --- lib/ex_doc/formatter/html.ex | 11 ++++++++++- test/ex_doc/formatter/html_test.exs | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/ex_doc/formatter/html.ex b/lib/ex_doc/formatter/html.ex index ffc32ef99..692d3b686 100644 --- a/lib/ex_doc/formatter/html.ex +++ b/lib/ex_doc/formatter/html.ex @@ -375,7 +375,7 @@ defmodule ExDoc.Formatter.HTML do end defp generate_redirect(filename, config, redirect_to) do - unless File.regular?("#{config.output}/#{redirect_to}") do + unless case_sensitive_file_regular?("#{config.output}/#{redirect_to}") do IO.puts(:stderr, "warning: #{filename} redirects to #{redirect_to}, which does not exist") end @@ -383,6 +383,15 @@ defmodule ExDoc.Formatter.HTML do File.write!("#{config.output}/#{filename}", content) end + defp case_sensitive_file_regular?(path) do + if File.regular?(path) do + files = path |> Path.dirname() |> File.ls!() + Path.basename(path) in files + else + false + end + end + def filter_list(:module, nodes) do Enum.filter(nodes, &(not (&1.type in [:exception, :task]))) end diff --git a/test/ex_doc/formatter/html_test.exs b/test/ex_doc/formatter/html_test.exs index 987c543e4..69c827294 100644 --- a/test/ex_doc/formatter/html_test.exs +++ b/test/ex_doc/formatter/html_test.exs @@ -100,12 +100,12 @@ defmodule ExDoc.Formatter.HTMLTest do test "warns when generating an index.html file with an invalid redirect" do output = capture_io(:stderr, fn -> - generate_docs(doc_config(main: "Unknown")) + generate_docs(doc_config(main: "Randomerror")) end) - assert output == "warning: index.html redirects to Unknown.html, which does not exist\n" + assert output == "warning: index.html redirects to Randomerror.html, which does not exist\n" assert File.regular?("#{output_dir()}/index.html") - refute File.regular?("#{output_dir()}/Unknown.html") + assert File.regular?("#{output_dir()}/RandomError.html") end test "warns on undefined functions" do