<commit_before>require "test_helper"

class ProcessWrapperTest < MiniTest::Unit::TestCase
  def setup
    @command = "cat"
    @text = ["Hello", "world!"]
    @output_fd = StringIO.new(@text.join("\n"))
    @pw = FreeLing::Analyzer::ProcessWrapper.new(@command, @output_fd)
  end

  def test_command_and_output_fd_can_be_read_from_instance
    assert_equal @command, @pw.command
    assert_equal @output_fd, @pw.output_fd
  end

  def test_command_can_be_changed_once_wrapper_was_created
    assert_equal @command, @pw.command
    @pw.command = "cat -n"
    assert_equal "cat -n", @pw.command
  end

  def test_run_returns_an_enumerator
    enum = @pw.run
    assert_instance_of Enumerator, enum
  end

  def test_run_returns_process_output_per_line
    assert_equal @text, @pw.run.to_a
  end

  def test_run_twice_without_rewinding_output_fd
    assert_equal @text, @pw.run.to_a
    assert @pw.output_fd.eof?
    assert_equal [], @pw.run.to_a
  end

  def test_run_twice_but_rewind_output_fd_after_first_run
    assert_equal @text, @pw.run.to_a
    assert @pw.output_fd.eof?
    @pw.output_fd.rewind
    assert_equal @text, @pw.run.to_a
  end

  def test_another_command
    @pw.command = "cat -n"
    assert_equal ["     1\tHello", "     2\tworld!"], @pw.run.to_a
  end
end
<commit_msg>Test invalid command<commit_after>require "test_helper"

class ProcessWrapperTest < MiniTest::Unit::TestCase
  def setup
    @command = "cat"
    @text = ["Hello", "world!"]
    @output_fd = StringIO.new(@text.join("\n"))
    @pw = FreeLing::Analyzer::ProcessWrapper.new(@command, @output_fd)
  end

  def test_command_and_output_fd_can_be_read_from_instance
    assert_equal @command, @pw.command
    assert_equal @output_fd, @pw.output_fd
  end

  def test_command_can_be_changed_once_wrapper_was_created
    assert_equal @command, @pw.command
    @pw.command = "cat -n"
    assert_equal "cat -n", @pw.command
  end

  def test_run_returns_an_enumerator
    enum = @pw.run
    assert_instance_of Enumerator, enum
  end

  def test_run_returns_process_output_per_line
    assert_equal @text, @pw.run.to_a
  end

  def test_run_twice_without_rewinding_output_fd
    assert_equal @text, @pw.run.to_a
    assert @pw.output_fd.eof?
    assert_equal [], @pw.run.to_a
  end

  def test_run_twice_but_rewind_output_fd_after_first_run
    assert_equal @text, @pw.run.to_a
    assert @pw.output_fd.eof?
    @pw.output_fd.rewind
    assert_equal @text, @pw.run.to_a
  end

  def test_another_command
    @pw.command = "cat -n"
    assert_equal ["     1\tHello", "     2\tworld!"], @pw.run.to_a
  end

  def test_invalid_command
    @pw.command = "inexistant_command"
    assert_raises(Errno::ENOENT) { @pw.run }
  end
end

{'fraction_non_alphanumeric': 0.10329507589781563, 'fraction_numerical': 0.001480932987782303, 'mean_word_length': 3.8597122302158273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5690896', 'n_tokens_mistral': 1030, 'n_tokens_neox': 1011, 'n_words': 183}