Sha256: c1eda58c993dc8e50fd6d1c95d5eac64084eb6d548f97f5938369ced0a7c046b

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require_relative "setup"
require "test/cmd"

class Lock::File::ReadmeTest < Test::Unit::TestCase
  def test_lockfile_blocking_variant
    r = ruby(readme_example("1_lockfile_blocking_variant.rb"))
    ["Lock acquired by parent process \(.+\)\n",
     "Child process waiting on lock \(.+\)\n",
     "Lock acquired by child process \(.+\)\n"
    ].each { assert_match Regexp.new(_1), r.stdout }
  end

  def test_lockfile_nonblocking_variant
    r = ruby(readme_example("2_lockfile_nonblocking_variant.rb"))
    ["Lock acquired by parent process \(.+\)\n",
     "(Lock would block\n){3,4}",
     "Lock acquired by child process \(.+\)\n"
    ].each { assert_match Regexp.new(_1), r.stdout }
  end

  def test_ffi_lockf_blocking_variant
    assert_equal "Lock acquired\nLock released\n",
                 ruby(readme_example("3_ffilockf_blocking_variant.rb")).stdout
  end

  def test_ffi_lockf_nonblocking_variant
    assert_equal "Lock acquired\nLock released\n",
                 ruby(readme_example("4_ffilockf_nonblocking_variant.rb")).stdout
  end

  private

  def ruby(*argv)
    cmd("ruby", *argv)
  end

  def readme_example(example_name)
    File.join(__dir__, "..", "share", "lockf.rb", "examples", example_name)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lockf.rb-2.0.0 test/readme_test.rb