         def flatten2(arg), do: List.flatten(arg)
       end
     end
-    """, """
+    """
+
+    warning = """
     warning: function List.old_flatten/1 is undefined or private. Did you mean one of:
 
           * flatten/1

      lib/a.ex:15

    """
  end

  test "warnings: imports" do
    assert_no_warnings """
    defmodule A do
      import Record

      def a(a, b), do: extract(a, b)
      def b(arg), do: is_record(arg)
    end
    """
  end

  test "warnings: aliases" do
    assert_warnings """
    defmodule A do
      alias Enum, as: E

      def a(a, b), do: E.map2(a, b)
      def b, do: &E.map2/2
    end
    """, """
    warning: function Enum.map2/2 is undefined or private. Did you mean one of:

          * map/2

      "lib/d.ex"
      "lib/d.ex" -> "lib/a.ex" [label="(compile)"]
    }
    """)
  end

  test "graph: source" do
    assert_graph(~w[--source lib/a.ex], """
    lib/a.ex
    └── lib/b.ex
        └── lib/a.ex
    """)
  end

  test "graph: invalid source" do
    assert_raise Mix.Error, "Source could not be found: lib/a2.ex", fn ->
      assert_graph(~w[--source lib/a2.ex], "")
    end
  end

  test "graph: sink" do
    assert_graph(~w[--sink lib/b.ex], """
    lib/a.ex
    └── lib/b.ex
        └── lib/a.ex
    lib/d.ex
    └── lib/a.ex (compile)
    """)
  end

  test "graph: invalid sink" do
    assert_raise Mix.Error, "Sink could not be found: lib/b2.ex", fn ->
      assert_graph(~w[--sink lib/b2.ex], "")
    end
  end

  test "graph: sink and source is error" do
    assert_raise Mix.Error, "mix xref graph expects only one of --source and --sink", fn ->
      assert_graph(~w[--source lib/a.ex --sink lib/b.ex], "")
    end
  end

  test "graph: with dynamic module" do
    in_fixture "no_mixfile", fn ->
      File.write!("lib/a.ex", """
      B.define()
      """)

      File.write!("lib/b.ex", """
      defmodule B do
        def define do
          defmodule A do
          end
        end
      end
      """)

      assert Mix.Task.run("xref", ["graph"]) == :ok

      expected = """
      Compiling 2 files (.ex)
      Generated sample app
      lib/a.ex
      lib/b.ex
      """

      assert ^expected = receive_until_no_messages([])
    end
  end

  defp assert_graph(opts \\ [], dot \\ false, expected) do
    in_fixture "no_mixfile", fn ->
      File.write!("lib/a.ex", """
      defmodule A do
        def a do
          B.a
