Skip to content

Commit

Permalink
Remove warnings on latest Elixir versions
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 15, 2025
1 parent f9f2cde commit 922b6b1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
45 changes: 0 additions & 45 deletions test/support/file_helpers.exs

This file was deleted.

52 changes: 51 additions & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
Code.require_file("support/file_helpers.exs", __DIR__)
# Copied from https://github.com/elixir-ecto/ecto/blob/v2.2/integration_test/support/file_helpers.exs
defmodule Support.FileHelpers do
import ExUnit.Assertions

@doc """
Returns the `tmp_path` for tests.
"""
def tmp_path do
Path.expand("../../tmp", __DIR__)
end

@doc """
Executes the given function in a temp directory
tailored for this test case and test.
"""
defmacro in_tmp(fun) do
path =
Path.join([
tmp_path(),
"#{__CALLER__.module}",
"#{elem(__CALLER__.function || raise("no function"), 0)}"
])

quote do
path = unquote(path)
File.rm_rf!(path)
File.mkdir_p!(path)
File.cd!(path, fn -> unquote(fun).(path) end)
end
end

@doc """
Asserts a file was generated.
"""
def assert_file(file) do
assert File.regular?(file), "Expected #{file} to exist, but does not"
end

@doc """
Asserts a file was generated and that it matches a given pattern.
"""
def assert_file(file, callback) when is_function(callback, 1) do
assert_file(file)
callback.(File.read!(file))
end

def assert_file(file, match) do
assert_file(file, &assert(&1 =~ match))
end
end

Mix.shell(Mix.Shell.Process)
ExUnit.start()

0 comments on commit 922b6b1

Please sign in to comment.