diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-08 11:51:28 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-11-08 11:51:28 +0000 |
commit | ddb9acd9f83d28185a0e43fd7a4a3598157b99cf (patch) | |
tree | 22eaef08ab83b2779be5c42b285dd87851d47a3a /test/gdbm | |
parent | c2c0707949d8b09441a46f7011cd4ed6bb5f9e86 (diff) |
* test/dbm/test_dbm.rb: split tests for read only database.
* test/gdbm/test_gdbm.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/gdbm')
-rw-r--r-- | test/gdbm/test_gdbm.rb | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/test/gdbm/test_gdbm.rb b/test/gdbm/test_gdbm.rb index 64f135b683..523febef00 100644 --- a/test/gdbm/test_gdbm.rb +++ b/test/gdbm/test_gdbm.rb @@ -10,8 +10,8 @@ if defined? GDBM require 'tmpdir' require 'fileutils' - class TestGDBM < Test::Unit::TestCase - def TestGDBM.uname_s + class TestGDBM_RDONLY < Test::Unit::TestCase + def TestGDBM_RDONLY.uname_s require 'rbconfig' case RbConfig::CONFIG['target_os'] when 'cygwin' @@ -31,7 +31,6 @@ if defined? GDBM @tmpdir = Dir.mktmpdir("tmptest_gdbm") @prefix = "tmptest_gdbm_#{$$}" @path = "#{@tmpdir}/#{@prefix}_" - assert_instance_of(GDBM, @gdbm = GDBM.new(@path)) # prepare to make readonly GDBM file GDBM.open("#{@tmpdir}/#{@prefix}_rdonly", 0400) {|gdbm| @@ -40,7 +39,6 @@ if defined? GDBM assert_instance_of(GDBM, @gdbm_rdonly = GDBM.new("#{@tmpdir}/#{@prefix}_rdonly", nil)) end def teardown - assert_nil(@gdbm.close) assert_nil(@gdbm_rdonly.close) ObjectSpace.each_object(GDBM) do |obj| obj.close unless obj.closed? @@ -48,6 +46,34 @@ if defined? GDBM FileUtils.remove_entry_secure @tmpdir end + def test_delete_rdonly + if /^CYGWIN_9/ !~ SYSTEM + assert_raise(GDBMError) { + @gdbm_rdonly.delete("foo") + } + + assert_nil(@gdbm_rdonly.delete("bar")) + end + end + end + + class TestGDBM < Test::Unit::TestCase + SYSTEM = TestGDBM_RDONLY::SYSTEM + + def setup + @tmpdir = Dir.mktmpdir("tmptest_gdbm") + @prefix = "tmptest_gdbm_#{$$}" + @path = "#{@tmpdir}/#{@prefix}_" + assert_instance_of(GDBM, @gdbm = GDBM.new(@path)) + end + def teardown + assert_nil(@gdbm.close) + ObjectSpace.each_object(GDBM) do |obj| + obj.close unless obj.closed? + end + FileUtils.remove_entry_secure @tmpdir + end + def check_size(expect, gdbm=@gdbm) assert_equal(expect, gdbm.size) n = 0 @@ -438,15 +464,8 @@ if defined? GDBM assert_equal(2, @gdbm.size) assert_nil(@gdbm.delete(key)) - - if /^CYGWIN_9/ !~ SYSTEM - assert_raise(GDBMError) { - @gdbm_rdonly.delete("foo") - } - - assert_nil(@gdbm_rdonly.delete("bar")) - end end + def test_delete_with_block key = 'no called block' @gdbm[key] = 'foo' |