Sha256: 299f1ef37db36ab26b03e9eec9ec29fc351d922358ac55303dce10f039ab82d4

Contents?: true

Size: 840 Bytes

Versions: 7

Compression:

Stored size: 840 Bytes

Contents

require 'test_helper'

class BacktickTest < Minitest::Test
  include POSIX::Spawn

  def test_backtick_simple
    out = `exit`
    assert_equal '', out
    assert_equal 0, $?.exitstatus
  end

  def test_backtick_output
    out = `echo 123`
    assert_equal "123\n", out
    assert_equal 0, $?.exitstatus, 0
  end

  def test_backtick_failure
    out = `nosuchcmd 2> /dev/null`
    assert_equal '', out
    assert_equal 127, $?.exitstatus
  end

  def test_backtick_redirect
    out = `nosuchcmd 2>&1`
    regex = %r{/bin/sh: (1: )?nosuchcmd: (command )?not found}
    assert regex.match(out), "Got #{out.inspect}, expected match of pattern #{regex.inspect}"
    assert_equal 127, $?.exitstatus, 127
  end

  def test_backtick_huge
    out = `yes | head -50000`
    assert_equal 100000, out.size
    assert_equal 0, $?.exitstatus
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
posix-spawn-0.3.15 test/test_backtick.rb
posix-spawn-0.3.14 test/test_backtick.rb
posix-spawn-0.3.13 test/test_backtick.rb
posix-spawn-0.3.12 test/test_backtick.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/posix-spawn-0.3.11/test/test_backtick.rb
posix-spawn-0.3.11 test/test_backtick.rb
posix-spawn-0.3.10 test/test_backtick.rb