<commit_before>require 'spec_helper'
require 'tempfile'

require 'rprogram/system'

describe System do
  subject { System }

  it "should determine the native architecture" do
    subject.arch.should_not be_empty
  end

  it "should determine the native platform" do
    subject.platform.should_not be_empty
  end

  it "should have a list of directories that contain programs" do
    subject.paths.should_not be_empty

    subject.paths.any? { |dir| dir.directory? }.should == true
  end

  it "should be able to find programs" do
    subject.find_program('dir').should be_executable
  end

  it "should be able to find programs by multiple names" do
    subject.find_program_by_names('ls','dir').should be_executable
  end

  describe "run" do
    let(:dir) { subject.find_program('dir') }
    let(:cat) { subject.find_program('cat') }

    it "should return true when programs succeed" do
      subject.run(dir).should == true
    end

    it "should return false when programs fail" do
      subject.run(dir,'-zzzzzz').should == false
    end

    unless System.ruby_1_8?
      it "should allow passing spawn options as the last argument" do
        output = Tempfile.new('rprogram_compat_run')

        subject.run(dir, '-l', :out => [output.path, 'w'])

        output.read.should_not be_empty
      end
    else
      it "should raise an exception when passing exec options" do
        lambda {
          subject.run(dir, '-l', :out => ['foo', 'w'])
        }.should raise_error
      end
    end


    unless (System.ruby_1_8? || (System.windows? && !System.jruby?))
      it "should allow running programs with IO.popen" do
        io = subject.run(cat,'-n', :popen => 'w+')
        data = 'hello'

        io.puts(data)<commit_msg>They are called exec options.<commit_after>require 'spec_helper'
require 'tempfile'

require 'rprogram/system'

describe System do
  subject { System }

  it "should determine the native architecture" do
    subject.arch.should_not be_empty
  end

  it "should determine the native platform" do
    subject.platform.should_not be_empty
  end

  it "should have a list of directories that contain programs" do
    subject.paths.should_not be_empty

    subject.paths.any? { |dir| dir.directory? }.should == true
  end

  it "should be able to find programs" do
    subject.find_program('dir').should be_executable
  end

  it "should be able to find programs by multiple names" do
    subject.find_program_by_names('ls','dir').should be_executable
  end

  describe "run" do
    let(:dir) { subject.find_program('dir') }
    let(:cat) { subject.find_program('cat') }

    it "should return true when programs succeed" do
      subject.run(dir).should == true
    end

    it "should return false when programs fail" do
      subject.run(dir,'-zzzzzz').should == false
    end

    unless System.ruby_1_8?
      it "should allow passing exec options as the last argument" do
        output = Tempfile.new('rprogram_compat_run')

        subject.run(dir, '-l', :out => [output.path, 'w'])

        output.read.should_not be_empty
      end
    else
      it "should raise an exception when passing exec options" do
        lambda {
          subject.run(dir, '-l', :out => ['foo', 'w'])
        }.should raise_error
      end
    end


    unless (System.ruby_1_8? || (System.windows? && !System.jruby?))
      it "should allow running programs with IO.popen" do
        io = subject.run(cat,'-n', :popen => 'w+')
        data = 'hello'

        io.puts(data)
{'fraction_non_alphanumeric': 0.10780669144981413, 'fraction_numerical': 0.002287675150128682, 'mean_word_length': 2.904017857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1415081', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1041, 'n_words': 337}