File: test_backtick.rb

package info (click to toggle)
ruby-posix-spawn 0.3.15-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: ruby: 1,055; ansic: 314; makefile: 8
file content (36 lines) | stat: -rw-r--r-- 840 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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