summaryrefslogtreecommitdiff
path: root/test/dbm
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-16 12:03:23 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-16 12:03:23 +0000
commiteeb5c7e18e91e43502cf30d6f395364543fbf109 (patch)
tree4da2856011a54af689eb21374201bff0ead231e1 /test/dbm
parenta694dea2d8d4778bdfdfb6018647c6b022e0d9e5 (diff)
* ext/dbm/dbm.c (fdbm_initialize): accept optional 3rd argument to
specify an open flag. (Init_dbm): define open flags: DBM::READER, DBM::WRITER, DBM::WRCREAT and DBM::NEWDB. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6326 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/dbm')
-rw-r--r--test/dbm/test_dbm.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/test/dbm/test_dbm.rb b/test/dbm/test_dbm.rb
index f919890..2de73d1 100644
--- a/test/dbm/test_dbm.rb
+++ b/test/dbm/test_dbm.rb
@@ -11,7 +11,7 @@ if defined? DBM
require 'fileutils'
class TestDBM < Test::Unit::TestCase
- TMPROOT = "#{Dir.tmpdir}/ruby-gdbm.#{$$}"
+ TMPROOT = "#{Dir.tmpdir}/ruby-dbm.#{$$}"
def setup
Dir.mkdir TMPROOT
@@ -21,8 +21,31 @@ if defined? DBM
FileUtils.rm_rf TMPROOT if File.directory?(TMPROOT)
end
+ def test_reader_open
+ DBM.open("#{TMPROOT}/a") {}
+ v = DBM.open("#{TMPROOT}/a", nil, DBM::READER) {|d|
+ # Errno::EPERM is raised on Solaris which use ndbm.
+ # DBMError is raised on Debian which use gdbm.
+ assert_raises(Errno::EPERM, DBMError) { d["k"] = "v" }
+ true
+ }
+ assert(v)
+ end
+
+ def test_newdb_open
+ DBM.open("#{TMPROOT}/a") {|dbm|
+ dbm["k"] = "v"
+ }
+ v = DBM.open("#{TMPROOT}/a", nil, DBM::NEWDB) {|d|
+ assert_equal(0, d.length)
+ assert_nil(d["k"])
+ true
+ }
+ assert(v)
+ end
+
def test_freeze
- DBM.open("#{TMPROOT}/a.dbm") {|d|
+ DBM.open("#{TMPROOT}/a") {|d|
d.freeze
assert_raises(TypeError) { d["k"] = "v" }
}