Skip to content

Commit 058ccf7

Browse files
authored
Clean up tmp files (#5623)
1 parent c2c675a commit 058ccf7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

installer/test/mix_helper.exs

+18-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ defmodule MixHelper do
1515
end
1616

1717
def in_tmp(which, function) do
18-
path = Path.join([tmp_path(), random_string(10), to_string(which)])
18+
path = Path.join([tmp_path(), random_string(10) <> to_string(which)])
1919

2020
try do
2121
File.rm_rf!(path)
@@ -28,19 +28,22 @@ defmodule MixHelper do
2828

2929
def in_tmp_project(which, function) do
3030
conf_before = Application.get_env(:phoenix, :generators) || []
31-
path = Path.join([tmp_path(), random_string(10), to_string(which)])
31+
path = Path.join([tmp_path(), random_string(10) <> to_string(which)])
3232

3333
try do
3434
File.rm_rf!(path)
3535
File.mkdir_p!(path)
36+
3637
File.cd!(path, fn ->
3738
File.touch!("mix.exs")
39+
3840
File.write!(".formatter.exs", """
3941
[
4042
import_deps: [:phoenix, :ecto, :ecto_sql],
4143
inputs: ["*.exs"]
4244
]
4345
""")
46+
4447
function.()
4548
end)
4649
after
@@ -51,7 +54,7 @@ defmodule MixHelper do
5154

5255
def in_tmp_umbrella_project(which, function) do
5356
conf_before = Application.get_env(:phoenix, :generators) || []
54-
path = Path.join([tmp_path(), random_string(10), to_string(which)])
57+
path = Path.join([tmp_path(), random_string(10) <> to_string(which)])
5558

5659
try do
5760
apps_path = Path.join(path, "apps")
@@ -61,9 +64,11 @@ defmodule MixHelper do
6164
File.mkdir_p!(apps_path)
6265
File.mkdir_p!(config_path)
6366
File.touch!(Path.join(path, "mix.exs"))
67+
6468
for file <- ~w(config.exs dev.exs test.exs prod.exs) do
6569
File.write!(Path.join(config_path, file), "import Config\n")
6670
end
71+
6772
File.cd!(apps_path, function)
6873
after
6974
Application.put_env(:phoenix, :generators, conf_before)
@@ -94,13 +99,17 @@ defmodule MixHelper do
9499
def assert_file(file, match) do
95100
cond do
96101
is_list(match) ->
97-
assert_file file, &(Enum.each(match, fn(m) -> assert &1 =~ m end))
102+
assert_file(file, &Enum.each(match, fn m -> assert &1 =~ m end))
103+
98104
is_binary(match) or is_struct(match, Regex) ->
99-
assert_file file, &(assert &1 =~ match)
105+
assert_file(file, &assert(&1 =~ match))
106+
100107
is_function(match, 1) ->
101108
assert_file(file)
102109
match.(File.read!(file))
103-
true -> raise inspect({file, match})
110+
111+
true ->
112+
raise inspect({file, match})
104113
end
105114
end
106115

@@ -118,6 +127,7 @@ defmodule MixHelper do
118127
def with_generator_env(app_name \\ :phoenix, new_env, fun) do
119128
config_before = Application.fetch_env(app_name, :generators)
120129
Application.put_env(app_name, :generators, new_env)
130+
121131
try do
122132
fun.()
123133
after
@@ -150,7 +160,8 @@ defmodule MixHelper do
150160
def flush do
151161
receive do
152162
_ -> flush()
153-
after 0 -> :ok
163+
after
164+
0 -> :ok
154165
end
155166
end
156167
end

0 commit comments

Comments
 (0)