Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ https://github.com/wojtekmach/mix_install_examples/blob/main/phoenix.exs

### Expected behavior

<!--
Describe the expected behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the template uses both "behavior" (US spelling) and "behaviour" (UK spelling, also technical term in Erlang/Elixir).

Maybe we could update towards one or the other for local consistency.

-->
36 changes: 36 additions & 0 deletions test/phoenix/source_files_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
defmodule Phoenix.SourceFilesTest do
use ExUnit.Case, async: true

@repo_root Path.expand("../..", __DIR__)
@git_repo? File.dir?(Path.join(@repo_root, ".git")) and System.find_executable("git") != nil
@excluded_exts ~w(.br .foo .gz .ico .lock .map .pem .png)
@excluded_files ~w(test/fixtures/hello.txt)

@tag skip: if(not @git_repo?, do: "git or .git repository not available")
test "all tracked text files in the repository end with a single newline" do
{output, 0} = System.cmd("git", ["ls-files", "-z"], cd: @repo_root)

target_files =
output
|> String.split("\0", trim: true)
|> Enum.reject(fn file ->
file in @excluded_files or Enum.any?(@excluded_exts, &String.ends_with?(file, &1))
end)
|> Enum.map(&Path.expand(&1, @repo_root))
|> Enum.filter(&File.regular?/1)

assert target_files != [], "No tracked files found in the repository"

offending =
target_files
|> Enum.reject(fn file ->
content = File.read!(file)
content == "" or content =~ ~r/\S\n\z/
end)
|> Enum.map(&Path.relative_to(&1, @repo_root))

assert offending == [],
"Expected the following files to end with a single trailing newline:\n\n" <>
Enum.map_join(offending, "\n", &" - #{&1}")
end
end
Loading