Sha256: b41f4e286ee51a1579f18c964ae0752e9c0cee5ad70718b401814200457c9b32

Contents?: true

Size: 1.22 KB

Versions: 26

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require_relative 'helper'

class KernelTest < MiniTest::Test
  def test_system_method
    fn = '/tmp/test_system_method'
    FileUtils.rm(fn) rescue nil

    counter = 0
    timer = spin { throttled_loop(200) { counter += 1 } }

    system('sleep 0.01')
    assert(counter >= 2)

    system('echo "hello" > ' + fn)
    assert_equal "hello\n", IO.read(fn)
  ensure
    timer&.stop
  end

  def test_Kernel_system_singleton_method
    assert_equal true, Kernel.system("which ruby > /dev/null 2>&1")
    assert_equal false, Kernel.system("azertyuiop > /dev/null 2>&1")
  end

  def patch_open3
    class << Open3
      alias_method :orig_popen2, :popen2
      def popen2(*args)
        raise SystemCallError, 'foo'
      end
    end
  end

  def unpatch_open3
    class << Open3
      alias_method :popen2, :orig_popen2
    end
  end

  def test_system_method_with_system_call_error
    patch_open3
    result = system('foo')
    assert_nil result
  ensure
    unpatch_open3
  end

  def test_backtick_method
    counter = 0
    timer = spin { throttled_loop(200) { counter += 1 } }

    `sleep 0.01`
    assert(counter >= 2)

    result = `echo "hello"`
    assert_equal "hello\n", result
  ensure
    timer&.stop
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
polyphony-0.73.1 test/test_kernel.rb
polyphony-0.73 test/test_kernel.rb
polyphony-0.72 test/test_kernel.rb
polyphony-0.71 test/test_kernel.rb
polyphony-0.70 test/test_kernel.rb
polyphony-0.69 test/test_kernel.rb
polyphony-0.68 test/test_kernel.rb
polyphony-0.67 test/test_kernel.rb
polyphony-0.66 test/test_kernel.rb
polyphony-0.65 test/test_kernel.rb
polyphony-0.64 test/test_kernel.rb
polyphony-0.63 test/test_kernel.rb
polyphony-0.62 test/test_kernel.rb
polyphony-0.61 test/test_kernel.rb
polyphony-0.60 test/test_kernel.rb
polyphony-0.59.1 test/test_kernel.rb
polyphony-0.59 test/test_kernel.rb
polyphony-0.58 test/test_kernel.rb
polyphony-0.57.0 test/test_kernel.rb
polyphony-0.56.0 test/test_kernel.rb