<commit_before>Code.require_file "../test_helper.exs", __DIR__

defmodule Mix.UmbrellaTest do
  use MixTest.Case

  test "compile umbrella" do
    in_fixture "umbrella_dep/deps/umbrella", fn ->
      Mix.Project.in_project(:umbrella, ".", fn _ ->
        Mix.Task.run "deps.get"
        Mix.Task.run "compile"

        assert_received { :mix_shell, :info, ["==> bar"] }
        assert_received { :mix_shell, :info, ["Compiled lib/bar.ex"] }
        assert_received { :mix_shell, :info, ["Generated bar.app"] }
        assert_received { :mix_shell, :info, ["==> foo"] }
        assert_received { :mix_shell, :info, ["Compiled lib/foo.ex"] }
        assert_received { :mix_shell, :info, ["Generated foo.app"] }

        # Ensure foo was loaded and in the same env as Mix.env
        assert_received { :mix_shell, :info, [":foo env is dev"] }
      end)
    end
  end

  test "dependency in umbrella" do
    in_fixture "umbrella_dep/deps/umbrella", fn ->
      Mix.Project.in_project(:umbrella, ".", fn _ ->
        Mix.Task.run "deps"
        assert_received { :mix_shell, :info, ["* bar (apps/bar)"] }
        assert_received { :mix_shell, :info, ["* foo (apps/foo)"] }
      end)
    end
  end

  defmodule UmbrellaDeps do
    def project do
      [ apps_path: "apps",
        deps: [{ :some_dep, path: "deps/some_dep" }] ]
    end
  end

  test "loads umbrella dependencies" do
    Mix.Project.push UmbrellaDeps

    in_fixture "umbrella_dep/deps/umbrella", fn ->
      File.mkdir_p!("deps/some_dep/ebin")
      Mix.Task.run "loadpaths", ["--no-deps-check", "--no-elixir-version-check"]
      assert Path.expand('deps/some_dep/ebin') in :code.get_path
    end
  after
    Mix.Project.pop
  end

  defmodule CycleDeps do
    def project do
      [ app: :umbrella_dep,
        deps: [
          { :bar, path: "deps/umbrella/apps/bar" },
          { :umbrella, path: "deps/umbrella" }
        ] ]
    end
  end

  test "handles dependencies with cycles" do
    Mix.Project.push CycleDeps

    in_fixture "umbrella_dep", fn ->
      assert Enum.map(Mix.Deps.fetched, & &1.app) == [:foo, :bar, :umbrella]
    end
  after
    Mix.Project.pop
  end

  test "list deps for umbrella as dependency" do
    in_fixture("umbrella_dep", fn ->
      Mix.Project.in_project(:umbrella_dep, ".", fn _ ->
        Mix.Task.run "deps"
        assert_received { :mix_shell, :info, ["* umbrella (deps/umbrella)"] }
        assert_received { :mix_shell, :info, ["* foo (apps/foo)"] }
      end)
    end)
  end

  test "compile for umbrella as dependency" do
    in_fixture "umbrella_dep", fn ->
      Mix.Project.in_project(:umbrella_dep, ".", fn _ ->
        Mix.Task.run "deps.compile"
        assert "hello world" == Bar.bar
      end)
    end<commit_msg>Add a test case for overriden deps with cycles in umbrellas<commit_after>Code.require_file "../test_helper.exs", __DIR__

defmodule Mix.UmbrellaTest do
  use MixTest.Case

  test "compile umbrella" do
    in_fixture "umbrella_dep/deps/umbrella", fn ->
      Mix.Project.in_project(:umbrella, ".", fn _ ->
        Mix.Task.run "deps.get"
        Mix.Task.run "compile"

        assert_received { :mix_shell, :info, ["==> bar"] }
        assert_received { :mix_shell, :info, ["Compiled lib/bar.ex"] }
        assert_received { :mix_shell, :info, ["Generated bar.app"] }
        assert_received { :mix_shell, :info, ["==> foo"] }
        assert_received { :mix_shell, :info, ["Compiled lib/foo.ex"] }
        assert_received { :mix_shell, :info, ["Generated foo.app"] }

        # Ensure foo was loaded and in the same env as Mix.env
        assert_received { :mix_shell, :info, [":foo env is dev"] }
      end)
    end
  end

  test "dependency in umbrella" do
    in_fixture "umbrella_dep/deps/umbrella", fn ->
      Mix.Project.in_project(:umbrella, ".", fn _ ->
        Mix.Task.run "deps"
        assert_received { :mix_shell, :info, ["* bar (apps/bar)"] }
        assert_received { :mix_shell, :info, ["* foo (apps/foo)"] }
      end)
    end
  end

  defmodule UmbrellaDeps do
    def project do
      [ apps_path: "apps",
        deps: [{ :some_dep, path: "deps/some_dep" }] ]
    end
  end

  test "loads umbrella dependencies" do
    Mix.Project.push UmbrellaDeps

    in_fixture "umbrella_dep/deps/umbrella", fn ->
      File.mkdir_p!("deps/some_dep/ebin")
      Mix.Task.run "loadpaths", ["--no-deps-check", "--no-elixir-version-check"]
      assert Path.expand('deps/some_dep/ebin') in :code.get_path
    end
  after
    Mix.Project.pop
  end

  defmodule CycleDeps do
    def project do
      [ app: :umbrella_dep,
        deps: [
          { :bar, path: "deps/umbrella/apps/bar" },
          { :umbrella, path: "deps/umbrella" }
        ] ]
    end
  end

  test "handles dependencies with cycles" do
    Mix.Project.push CycleDeps

    in_fixture "umbrella_dep", fn ->
      assert Enum.map(Mix.Deps.fetched, & &1.app) == [:foo, :bar, :umbrella]
    end
  after
    Mix.Project.pop
  end

  test "handles dependencies with cycles and overriden deps" do
    Mix.Project.push UmbrellaDeps

    in_fixture "umbrella_dep/deps/umbrella", fn ->
      Mix.Project.in_project :umbrella, ".", fn _ ->
        File.write!("apps/foo/mix.exs", """)
        defmodule Foo.Mix do
          use Mix.Project

          def project do
            [ app: :foo,
              version: "0.1.0",
              deps: [{ :bar, in_umbrella: true }] ]
          end
        end
        """

        File.write!("apps/bar/mix.exs", """)
        defmodule Bar.Mix do
          use Mix.Project

          def project do
            [ app: :foo,
              version: "0.1.0",
              deps: [{ :a, path: "deps/a" },
                     { :b, path: "deps/b" }] ]
          end
        end
        """

        assert Enum.map(Mix.Deps.fetched, & &1.app) == [:a, :b, :bar, :foo]
      end
    end
  after
    Mix.Project.pop
  end

  test "list deps for umbrella as dependency" do
    in_fixture("umbrella_dep", fn ->
      Mix.Project.in_project(:umbrella_dep, ".", fn _ ->
        Mix.Task.run "deps"
        assert_received { :mix_shell, :info, ["* umbrella (deps/umbrella)"] }
        assert_received { :mix_shell, :info, ["* foo (apps/foo)"] }
      end)
    end)
  end

  test "compile for umbrella as dependency" do
    in_fixture "umbrella_dep", fn ->
      Mix.Project.in_project(:umbrella_dep, ".", fn _ ->
        Mix.Task.run "deps.compile"
        assert "hello world" == Bar.bar
      end)
    end
{'fraction_non_alphanumeric': 0.14030453697949036, 'fraction_numerical': 0.0013983840894965817, 'mean_word_length': 2.295954941116231, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3499006', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2259, 'n_words': 513}