<commit_before>require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "Kernel#`" do
  before :each do
    @original_external = Encoding.default_external
  end

  after :each do
    Encoding.default_external = @original_external
  end

  it "is a private method" do
    Kernel.should have_private_instance_method(:`)
  end

  it "returns the standard output of the executed sub-process" do
    ip = 'world'
    `echo disc #{ip}`.should == "disc world\n"
  end

  it "lets the standard error stream pass through to the inherited stderr" do
    cmd = ruby_cmd('STDERR.print "error stream"')
    -> {
      `#{cmd}`.should == ""
    }.should output_to_fd("error stream", STDERR)
  end

  it "produces a String in the default external encoding" do
    Encoding.default_external = Encoding::SHIFT_JIS
    `echo disc`.encoding.should equal(Encoding::SHIFT_JIS)
  end

  it "raises an Errno::ENOENT if the command is not executable" do
    -> { `nonexistent_command` }.should raise_error(Errno::ENOENT)
  end

  platform_is_not :windows do
    it "sets $? to the exit status of the executed sub-process" do
      ip = 'world'
      `echo disc #{ip}`
      $?.should be_kind_of(Process::Status)
      $?.should_not.stopped?<commit_msg>Fix issue with Kernel#` when invalid UTF-8 bytes are given<commit_after>require_relative '../../spec_helper'
require_relative 'fixtures/classes'

describe "Kernel#`" do
  before :each do
    @original_external = Encoding.default_external
  end

  after :each do
    Encoding.default_external = @original_external
  end

  it "is a private method" do
    Kernel.should have_private_instance_method(:`)
  end

  it "returns the standard output of the executed sub-process" do
    ip = 'world'
    `echo disc #{ip}`.should == "disc world\n"
  end

  it "lets the standard error stream pass through to the inherited stderr" do
    cmd = ruby_cmd('STDERR.print "error stream"')
    -> {
      `#{cmd}`.should == ""
    }.should output_to_fd("error stream", STDERR)
  end

  it "produces a String in the default external encoding" do
    Encoding.default_external = Encoding::SHIFT_JIS
    `echo disc`.encoding.should equal(Encoding::SHIFT_JIS)
  end

  it "raises an Errno::ENOENT if the command is not executable" do
    -> { `nonexistent_command` }.should raise_error(Errno::ENOENT)
  end

  it "handles invalid UTF-8 bytes in command" do
    `echo "testing\xC2 a non UTF-8 string"`.should == "testing\xC2 a non UTF-8 string\n"
  end

  platform_is_not :windows do
    it "sets $? to the exit status of the executed sub-process" do
      ip = 'world'
      `echo disc #{ip}`
      $?.should be_kind_of(Process::Status)
      $?.should_not.stopped?
{'fraction_non_alphanumeric': 0.10748702742772424, 'fraction_numerical': 0.002223869532987398, 'mean_word_length': 3.4833887043189367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3368548', 'n_tokens_mistral': 873, 'n_tokens_neox': 839, 'n_words': 272}