about summary refs log tree commit homepage
path: root/test/test_process.rb
blob: 7f7b0148493c993a032ef444327a6717d7f25261 (plain)
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
37
38
39
# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require './test/helper'
require 'dtas/process'
class TestProcess < Minitest::Unit::TestCase
  include DTAS::Process

  def test_encoding
    assert_equal Encoding::BINARY, qx('echo HIHIH').encoding
    s = ""
    a = qx('echo HIHIHI; echo >&2 BYEBYE', err_str: s)
    assert_equal Encoding::BINARY, a.encoding
  end

  def test_qx_env
    assert_equal "WORLD\n", qx({"HELLO" => "WORLD"}, 'echo $HELLO')
  end

  def test_qx_err
    err = "/dev/null"
    assert_equal "", qx('echo HELLO >&2', err: err)
    assert_equal "/dev/null", err
  end

  def test_qx_err_str
    s = ""
    assert_equal "", qx('echo HELLO >&2', err_str: s)
    assert_equal "HELLO\n", s
  end

  def test_qx_raise
    assert_raises(RuntimeError) { qx('false') }
  end

  def test_qx_no_raise
    status = qx('false', no_raise: true)
    refute status.success?, status.inspect
  end
end