<commit_before>defmodule UtilsTest do
  use ExUnit.Case, async: true
  import ExUnit.CaptureIO

  import PathHelpers

  alias ReleaseManager.Utils

  @example_app_path fixture_path("example_app")
  @old_path         fixture_path("configs/old_relx.config")
  @new_path         fixture_path("configs/new_relx.config")
  @expected_path    fixture_path("configs/merged_relx.config")

  defmacrop with_app(body) do
    quote do
      cwd = File.cwd!
      File.cd! @example_app_path
      unquote(body)
      File.cd! cwd
    end
  end

  test "can merge two relx.config files" do
    old      = @old_path |> Utils.read_terms
    new      = @new_path |> Utils.read_terms
    expected = @expected_path |> Utils.read_terms

    merged = Utils.merge(old, new)

    assert expected == merged
  end

  test "can read terms from string" do
    config   = @expected_path |> File.read!
    expected = @expected_path |> Utils.read_terms
    terms    = Utils.string_to_terms(config)

    assert expected == terms
  end

  test "can run a function in a specific Mix environment" do
    execution_env = Utils.with_env :prod, fn -> Mix.env end
    assert :prod = execution_env
  end

  test "can load the current project configuration for a given environment" do
    with_app do
      [test: config] = Utils.load_config(:prod)
      assert List.keymember?(config, :foo, 0)
    end
  end

  test "can invoke mix to perform a task for a given environment" do
    with_app do
      assert :ok = Utils.mix("clean", :prod)
    end
  end

  test "can get the current elixir library path" do
    elixir_path = Utils.get_elixir_lib_paths |> Enum.filter(&(String.ends_with?("/elixir/ebin", &1)))
    path        = Path.join(elixir_path, "../bin/elixir")
    {result, _} = System.cmd(path, ["--version"])
    version     = result |> String.strip(?\n)
    assert "Elixir #{System.version}" == version
  end

  @tag :expensive<commit_msg>Update test which checks version to handle 1.2 changes<commit_after>defmodule UtilsTest do
  use ExUnit.Case, async: true
  import ExUnit.CaptureIO

  import PathHelpers

  alias ReleaseManager.Utils

  @example_app_path fixture_path("example_app")
  @old_path         fixture_path("configs/old_relx.config")
  @new_path         fixture_path("configs/new_relx.config")
  @expected_path    fixture_path("configs/merged_relx.config")

  defmacrop with_app(body) do
    quote do
      cwd = File.cwd!
      File.cd! @example_app_path
      unquote(body)
      File.cd! cwd
    end
  end

  test "can merge two relx.config files" do
    old      = @old_path |> Utils.read_terms
    new      = @new_path |> Utils.read_terms
    expected = @expected_path |> Utils.read_terms

    merged = Utils.merge(old, new)

    assert expected == merged
  end

  test "can read terms from string" do
    config   = @expected_path |> File.read!
    expected = @expected_path |> Utils.read_terms
    terms    = Utils.string_to_terms(config)

    assert expected == terms
  end

  test "can run a function in a specific Mix environment" do
    execution_env = Utils.with_env :prod, fn -> Mix.env end
    assert :prod = execution_env
  end

  test "can load the current project configuration for a given environment" do
    with_app do
      [test: config] = Utils.load_config(:prod)
      assert List.keymember?(config, :foo, 0)
    end
  end

  test "can invoke mix to perform a task for a given environment" do
    with_app do
      assert :ok = Utils.mix("clean", :prod)
    end
  end

  test "can get the current elixir library path" do
    elixir_path = Utils.get_elixir_lib_paths |> Enum.filter(&(String.ends_with?("/elixir/ebin", &1)))
    path        = Path.join(elixir_path, "../bin/elixir")
    {result, _} = System.cmd(path, ["--version"])
    version     = result |> String.strip(?\n)
    assert String.contains?(version, "Elixir #{System.version}")
  end

  @tag :expensive
{'fraction_non_alphanumeric': 0.10121352956364575, 'fraction_numerical': 0.001549186676994578, 'mean_word_length': 3.035416666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '616098', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1280, 'n_words': 349}