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

describe "Process.exec" do
  it "raises Errno::ENOENT for an empty string" do
    -> { Process.exec "" }.should raise_error(Errno::ENOENT)
  end

  it "raises Errno::ENOENT for a command which does not exist" do
    -> { Process.exec "bogus-noent-script.sh" }.should raise_error(Errno::ENOENT)
  end

  it "raises an ArgumentError if the command includes a null byte" do
    -> { Process.exec "\000" }.should raise_error(ArgumentError)
  end

  unless File.executable?(__FILE__) # Some FS (e.g. vboxfs) locate all files executable
    platform_is_not :windows do
      it "raises Errno::EACCES when the file does not have execute permissions" do
        -> { Process.exec __FILE__ }.should raise_error(Errno::EACCES)
      end
    end

    platform_is :windows do
      it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do
        -> { Process.exec __FILE__ }.should raise_error(SystemCallError) { |e|
          [Errno::EACCES, Errno::ENOEXEC].should include(e.class)
        }
      end
    end
  end

  platform_is_not :openbsd do
    it "raises Errno::EACCES when passed a directory" do
      -> { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EACCES)
    end
  end

  platform_is :openbsd do
    it "raises Errno::EISDIR when passed a directory" do
      -> { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EISDIR)
    end
  end

  it "runs the specified command, replacing current process" do
    ruby_exe('Process.exec "echo hello"; puts "fail"', escape: true).should == "hello\n"
  end

  it "sets the current directory when given the :chdir option" do
    tmpdir = tmp("")[0..-2]
    platform_is_not :windows do
      ruby_exe("Process.exec(\"pwd\", chdir: #{tmpdir.inspect})", escape: true).should == "#{tmpdir}\n"
    end
    platform_is :windows do
      ruby_exe("Process.exec(\"cd\", chdir: #{tmpdir.inspect})", escape: true).tr('\\', '/').should == "#{tmpdir}\n"
    end<commit_msg>spec/ruby/core/process/exec_spec.rb: remove a guard for openbsd<commit_after>require_relative '../../spec_helper'

describe "Process.exec" do
  it "raises Errno::ENOENT for an empty string" do
    -> { Process.exec "" }.should raise_error(Errno::ENOENT)
  end

  it "raises Errno::ENOENT for a command which does not exist" do
    -> { Process.exec "bogus-noent-script.sh" }.should raise_error(Errno::ENOENT)
  end

  it "raises an ArgumentError if the command includes a null byte" do
    -> { Process.exec "\000" }.should raise_error(ArgumentError)
  end

  unless File.executable?(__FILE__) # Some FS (e.g. vboxfs) locate all files executable
    platform_is_not :windows do
      it "raises Errno::EACCES when the file does not have execute permissions" do
        -> { Process.exec __FILE__ }.should raise_error(Errno::EACCES)
      end
    end

    platform_is :windows do
      it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do
        -> { Process.exec __FILE__ }.should raise_error(SystemCallError) { |e|
          [Errno::EACCES, Errno::ENOEXEC].should include(e.class)
        }
      end
    end
  end

  it "raises Errno::EACCES when passed a directory" do
    -> { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EACCES)
  end

  it "runs the specified command, replacing current process" do
    ruby_exe('Process.exec "echo hello"; puts "fail"', escape: true).should == "hello\n"
  end

  it "sets the current directory when given the :chdir option" do
    tmpdir = tmp("")[0..-2]
    platform_is_not :windows do
      ruby_exe("Process.exec(\"pwd\", chdir: #{tmpdir.inspect})", escape: true).should == "#{tmpdir}\n"
    end
    platform_is :windows do
      ruby_exe("Process.exec(\"cd\", chdir: #{tmpdir.inspect})", escape: true).tr('\\', '/').should == "#{tmpdir}\n"
    end
{'fraction_non_alphanumeric': 0.12865648459746312, 'fraction_numerical': 0.0025886616619207868, 'mean_word_length': 3.356257046223224, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '4479404', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1240, 'n_words': 373}