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

defmodule IEx.ServerTest do
  use IEx.Case

  setup do
    IEx.Options.set :colors, enabled: false
    :ok
  end

  # Options

  test "prefix option" do
    assert capture_io(fn ->
      boot([prefix: "pry"])
    end) =~ "pry(1)> "
  end

  test "delegate_locals_to option" do
    assert capture_io("sort([:foo, :bar])", fn ->
      boot([delegate_locals_to: Enum])
    end) =~ "[:bar, :foo]"
  end

  # Take over

  test "allows take over of the shell during boot" do
    assert capture_io("Y\na+b", fn ->
      server = self
      boot([], fn ->
        opts = [prefix: "dbg", binding: [a: 1, b: 2]]
        IEx.Server.take_over("iex:13", opts, 1000, server)
      end)
    end) =~ "dbg(1)> "
  end

  test "does not operate if callback during boot fails" do
    assert capture_io(fn ->
      boot([], fn -> exit(0) end)
    end) == nil
  end

  test "take over fails when there is no shell" do
    assert IEx.Server.take_over("iex:13", [], 10) == { :error, :no_iex }
  end

  test "take over fails when evaluator is requesting take over" do
    Process.put(:evaluator, self)
    assert IEx.Server.take_over("iex:13", [], 10, self) == { :error, :self }
  end

  test "pry wraps around take over" do
    require IEx
    assert capture_io(fn ->
      assert IEx.pry == { :error, :no_iex }
    end) =~ "Is an IEx shell running?"
  end

  # Helpers

  defp boot(opts, callback // fn -> end) do<commit_msg>Fix the build, we no longer fail when taking over itself<commit_after>Code.require_file "../test_helper.exs", __DIR__

defmodule IEx.ServerTest do
  use IEx.Case

  setup do
    IEx.Options.set :colors, enabled: false
    :ok
  end

  # Options

  test "prefix option" do
    assert capture_io(fn ->
      boot([prefix: "pry"])
    end) =~ "pry(1)> "
  end

  test "delegate_locals_to option" do
    assert capture_io("sort([:foo, :bar])", fn ->
      boot([delegate_locals_to: Enum])
    end) =~ "[:bar, :foo]"
  end

  # Take over

  test "allows take over of the shell during boot" do
    assert capture_io("Y\na+b", fn ->
      server = self
      boot([], fn ->
        opts = [prefix: "dbg", binding: [a: 1, b: 2]]
        IEx.Server.take_over("iex:13", opts, 1000, server)
      end)
    end) =~ "dbg(1)> "
  end

  test "does not operate if callback during boot fails" do
    assert capture_io(fn ->
      boot([], fn -> exit(0) end)
    end) == nil
  end

  test "take over fails when there is no shell" do
    assert IEx.Server.take_over("iex:13", [], 10) == { :error, :no_iex }
  end

  test "pry wraps around take over" do
    require IEx
    assert capture_io(fn ->
      assert IEx.pry == { :error, :no_iex }
    end) =~ "Is an IEx shell running?"
  end

  # Helpers

  defp boot(opts, callback // fn -> end) do
{'fraction_non_alphanumeric': 0.1414756446991404, 'fraction_numerical': 0.012177650429799427, 'mean_word_length': 2.6509803921568627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '1534493', 'n_tokens_mistral': 1037, 'n_tokens_neox': 984, 'n_words': 311}