summaryrefslogtreecommitdiff
path: root/test/sdbm
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-19 07:47:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-19 07:47:36 +0000
commit226fcd5814a2aea4ee5de9abcf2db972684e9d5e (patch)
treec3f54412f839d8b9f380272c7697214f99573989 /test/sdbm
parent7b253adc68d3c7186d1711dcee363598497d891f (diff)
test_sdbm.rb: open_db_child
* test/sdbm/test_sdbm.rb (TestSDBM#open_db_child): open the db in a child process and handshake using popen. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/sdbm')
-rw-r--r--test/sdbm/test_sdbm.rb65
1 files changed, 26 insertions, 39 deletions
diff --git a/test/sdbm/test_sdbm.rb b/test/sdbm/test_sdbm.rb
index f020166..e59e011 100644
--- a/test/sdbm/test_sdbm.rb
+++ b/test/sdbm/test_sdbm.rb
@@ -1,5 +1,6 @@
require 'test/unit'
require 'tmpdir'
+require_relative '../ruby/envutil'
begin
require 'sdbm'
@@ -33,15 +34,6 @@ class TestSDBM < Test::Unit::TestCase
end
end
- def have_fork?
- begin
- fork{}
- true
- rescue NotImplementedError
- false
- end
- end
-
def test_version
assert(! SDBM.const_defined?(:VERSION))
end
@@ -76,48 +68,43 @@ class TestSDBM < Test::Unit::TestCase
end
=end
- def test_s_open_nolock
- # sdbm 1.8.0 specific
- if not defined? SDBM::NOLOCK
- return
+ def open_db_child(dbname, *opts)
+ opts = [0644, *opts].map(&:inspect).join(', ')
+ args = [EnvUtil.rubybin, "-rsdbm", <<-SRC, dbname]
+ STDOUT.sync = true
+ gdbm = SDBM.open(ARGV.shift, #{opts})
+ puts sdbm.class
+ gets
+ SRC
+ IO.popen(args, "r+") do |f|
+ dbclass = f.gets
+ assert_equal("SDBM", dbclass.chomp)
+ yield
end
- return unless have_fork? # snip this test
+ end
- pid = fork() {
- assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
- SDBM::NOLOCK))
- sleep 2
- }
- sleep 1
- begin
- sdbm2 = nil
+ def test_s_open_nolock
+ dbname = "#{@tmpdir}/#{@prefix}"
+
+ open_db_child(dbname, SDBM::NOLOCK) do
assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
- assert_instance_of(SDBM, sdbm2 = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
+ SDBM.open(dbname, 0644) {|sdbm|
+ assert_instance_of(SDBM, sdbm)
+ }
}
- ensure
- Process.wait pid
- sdbm2.close if sdbm2
end
p Dir.glob("#{@tmpdir}/#{@prefix}*") if $DEBUG
- pid = fork() {
- assert_instance_of(SDBM, sdbm = SDBM.open("#{@tmpdir}/#{@prefix}", 0644))
- sleep 2
- }
- begin
- sleep 1
- sdbm2 = nil
+ open_db_child(dbname) do
assert_no_exception(Errno::EWOULDBLOCK, Errno::EAGAIN, Errno::EACCES) {
# this test is failed on Cygwin98 (???)
- assert_instance_of(SDBM, sdbm2 = SDBM.open("#{@tmpdir}/#{@prefix}", 0644,
- SDBM::NOLOCK))
+ SDBM.open(dbname, 0644, SDBM::NOLOCK) {|sdbm|
+ assert_instance_of(SDBM, sdbm)
+ }
}
- ensure
- Process.wait pid
- sdbm2.close if sdbm2
end
- end
+ end if defined? SDBM::NOLOCK # sdbm 1.8.0 specific
def test_s_open_error
skip "doesn't support to avoid read access by owner on Windows" if /mswin|mingw/ =~ RUBY_PLATFORM