Sha256: 0d74e62a12d6b5dc65fe34ec4bbdc7abe41cf7c489d4b4f133d52e62f8538d3b

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

describe FontProcessor::ExternalStdOutCommand do
  it "should be able to execute a normal binary and get it's output" do
    result = FontProcessor::ExternalStdOutCommand.run('echo asdf', :expect_output => true)
    expect(result).to eq "asdf\n"
  end

  it "should be able to kill a hanging binary" do
    result = FontProcessor::ExternalStdOutCommand.run('cat', :timeout => 1)
    expect(result).to be_nil
  end

  it "should be able to execute a normal binary and get it's stderr with it's stdout" do
    result = FontProcessor::ExternalStdOutCommand.run('cat asdfjhasdjfkhasdkjfhasjdkhf', :expect_output => true)
    expect(result).to include("No such file or directory")
  end
end

describe FontProcessor::ExternalJSONProgram do
  it "should be able to execute a program that takes and receives JSON" do
    result = FontProcessor::ExternalJSONProgram.run('more', {:param1 => 'test'})
    expect(result.key?('param1')).to be true
  end
  it "should be able to kill a hanging binary" do
    expect { FontProcessor::ExternalJSONProgram.run('sleep 2', :timeout => 1) }.to raise_error(FontProcessor::ExternalProgramError, "sleep 2: Took longer than 1 seconds to respond")
  end
  it "should be able to handle a binary that outputs to stderr first" do
    FontProcessor::ExternalJSONProgram.run('python -c "import sys;sys.stdin.read();sys.stderr.write(\'e\ne\');sys.stdout.write(\'{\\"1\\": [\'+\'1,\'*((65535/2)+1)+\'2]}\n\')"', {})
    # If this didn't hang then we are good, otherwise we have a problem
    expect(1).to eq 1
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fontprocessor-27.1.3 spec/lib/fontprocessor/external_execution_spec.rb