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

defmodule ExUnit.CLIFormatterTest do
  use ExUnit.Case, sync: false

  defp exec_test(file) do
    cmd("#{elixir_path} #{file}")
  end

  defp elixir_path do
    File.expand_path("../../../../../bin/elixir", __FILE__)
  end

  defp cmd(command) do
    port = Port.open({ :spawn, to_char_list(command) },
      [:stream, :binary, :exit_status, :hide])
    do_cmd(port, "")
  end

  defp do_cmd(port, acc) do
    receive do
      { ^port, { :data, data } } ->
        do_cmd(port, acc <> data)
      { ^port, { :exit_status, status } } ->
        acc
    end
  end

  test :print_stacktrace_when_raising_not_at_assertion do
    File.write "raising_test.exs", """
    ExUnit.start
    defmodule RaisingTest do
      use ExUnit.Case
      ExUnit.configure formatter: ExUnit.CLIFormatter

      test :raise do
        Enum.each { :will_fail }
        assert true
      end
    end
    """

    out_put = exec_test("raising_test.exs")
    assert out_put =~ %r/stacktrace:/
  after
    File.rm("raising_test.exs")
  end

  test :hide_stacktrace_when_raising_at_assertion do
    File.write "failure_test.exs", """
    ExUnit.start
    defmodule FailureTest do
      use ExUnit.Case
      ExUnit.configure formatter: ExUnit.CLIFormatter

      test :fail do
        assert false
      end
    end
    """

    out_put = exec_test("failure_test.exs")
    assert out_put =~ %r/at\ #{File.expand_path("failure_test.exs")}:7/
  after
    File.rm("failure_test.exs")
  end
end<commit_msg>Use System.cmd instead of Port.open<commit_after>Code.require_file "../../test_helper.exs", __FILE__

defmodule ExUnit.CLIFormatterTest do
  use ExUnit.Case, sync: false

  defp exec_test(file) do
    System.cmd("#{elixir_path} #{file}")
  end

  defp elixir_path do
    File.expand_path("../../../../../bin/elixir", __FILE__)
  end

  test :print_stacktrace_when_raising_not_at_assertion do
    File.write "raising_test.exs", """
    ExUnit.start formatter: ExUnit.CLIFormatter
    defmodule RaisingTest do
      use ExUnit.Case

      test :raise do
        Enum.each { :will_fail }
        assert true
      end
    end
    """

    out_put = exec_test("raising_test.exs")
    assert out_put =~ %r/stacktrace:/
  after
    File.rm("raising_test.exs")
  end

  test :hide_stacktrace_when_raising_at_assertion do
    File.write "failure_test.exs", """
    ExUnit.start formatter: ExUnit.CLIFormatter
    defmodule FailureTest do
      use ExUnit.Case

      test :fail do
        assert false
      end
    end
    """

    out_put = exec_test("failure_test.exs")
    assert out_put =~ %r/at\ #{File.expand_path("failure_test.exs")}:6/
  after
    File.rm("failure_test.exs")
  end
end
{'fraction_non_alphanumeric': 0.1217008797653959, 'fraction_numerical': 0.0007331378299120235, 'mean_word_length': 2.6778975741239894, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '1362342', 'n_tokens_mistral': 975, 'n_tokens_neox': 958, 'n_words': 200}