-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove warnings on latest Elixir versions
- Loading branch information
Showing
2 changed files
with
51 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |