Skip to content

Commit

Permalink
Pass xref's compile args to compile task (#10852)
Browse files Browse the repository at this point in the history
  • Loading branch information
szajbus authored and josevalim committed Apr 3, 2021
1 parent 5b3ef77 commit b49bac3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/mix/lib/mix/tasks/xref.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ defmodule Mix.Tasks.Xref do

@impl true
def run(args) do
{opts, args} = OptionParser.parse!(args, strict: @switches)
Mix.Task.run("compile", args)
Mix.Task.reenable("xref")

{opts, args} = OptionParser.parse!(args, strict: @switches)

case args do
["callers", callee] ->
callers(callee, opts)
Expand Down
32 changes: 32 additions & 0 deletions lib/mix/test/mix/tasks/xref_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,38 @@ defmodule Mix.Tasks.XrefTest do
end)
end

test "compiles project first by default" do
in_fixture("no_mixfile", fn ->
File.write!("lib/a.ex", """
defmodule A do
def a, do: :ok
end
""")

Mix.Tasks.Xref.run(["graph"])

assert "Compiling" <> _ = receive_until_no_messages([])
end)
end

test "passes args over to compile task" do
in_fixture("no_mixfile", fn ->
File.write!("lib/a.ex", """
defmodule A do
def a, do: :ok
end
""")

Mix.Task.run("compile")
Mix.Task.reenable("compile")
Mix.shell().flush()

Mix.Tasks.Xref.run(["graph", "--no-compile"])

refute String.starts_with?(receive_until_no_messages([]), "Compiling")
end)
end

defp assert_graph(opts \\ [], expected) do
in_fixture("no_mixfile", fn ->
File.write!("lib/a.ex", """
Expand Down

0 comments on commit b49bac3

Please sign in to comment.