Skip to content

Commit e43d35e

Browse files
Sascha Wolfalexocode
authored andcommitted
Mix - Format: Add a failing test for .formatter.exs in a different folder
The new test case builds on the "can read exported configuration from dependencies"-test. It tests that `mix format` can be called with `--dot-formatter ../.formatter.exs` when the `../.formatter.exs` contains `import_deps: [:my_dep]`. The `my_dep` dependency in turn can be found in `../deps/my_dep`. Right now this test fails. It seems like `mix format` tries to load the dependency from the workdir instead rather than from the same folder the provided `.formatter.exs` resides. TL;DR: mix format tries to load dependencies from the wrong folder, when passing a `.formatter.exs` in another folder
1 parent 408bbbc commit e43d35e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

lib/mix/test/mix/tasks/format_test.exs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,45 @@ defmodule Mix.Tasks.FormatTest do
219219
end
220220
end
221221

222+
test "can read exported configuration from dependencies with .formatter.exs in a different folder", context do
223+
Mix.Project.push(__MODULE__.FormatWithDepsApp)
224+
225+
in_tmp context.test, fn ->
226+
File.write!(".formatter.exs", """
227+
[import_deps: [:my_dep]]
228+
""")
229+
230+
File.mkdir_p!("deps/my_dep/")
231+
232+
File.write!("deps/my_dep/.formatter.exs", """
233+
[export: [locals_without_parens: [my_fun: 2]]]
234+
""")
235+
236+
File.mkdir_p!("subfolder")
237+
238+
File.cd!("subfolder", fn ->
239+
File.write!("a.ex", """
240+
my_fun :foo, :bar
241+
""")
242+
243+
Mix.Tasks.Format.run(["--dot-formatter", "../.formatter.exs", "a.ex"])
244+
245+
assert File.read!("a.ex") == """
246+
my_fun :foo, :bar
247+
"""
248+
end)
249+
250+
manifest_path = Path.join(Mix.Project.manifest_path(), "cached_formatter_deps")
251+
assert File.regular?(manifest_path)
252+
253+
# Let's check that the manifest gets updated if it's stale.
254+
File.touch!(manifest_path, {{1970, 1, 1}, {0, 0, 0}})
255+
256+
Mix.Tasks.Format.run(["subfolder/a.ex"])
257+
assert File.stat!(manifest_path).mtime > {{1970, 1, 1}, {0, 0, 0}}
258+
end
259+
end
260+
222261
test "validates dependencies in :import_deps", context do
223262
Mix.Project.push(__MODULE__.FormatWithDepsApp)
224263

0 commit comments

Comments
 (0)