diff tests/database.el @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents 4f79e16b1112
children
line wrap: on
line diff
--- a/tests/database.el	Mon Aug 13 11:01:58 2007 +0200
+++ b/tests/database.el	Mon Aug 13 11:03:08 2007 +0200
@@ -1,24 +1,29 @@
 ;;; Test database functionality
 
-(flet ((delete-database-files (filename)
-	(dolist (fn (list filename (concat filename ".db")))
-	  (condition-case nil (delete-file fn) (file-error nil))))
+(defun test-database (db)
+  (Assert (databasep db))
+  (put-database "key1" "val1" db)
+  (Assert (equal "val1" (get-database "key1" db)))
+  (remove-database "key1" db)
+  (Assert (equal nil (get-database "key1" db)))
+  (close-database db)
+  (Assert (not (database-live-p db)))
+  (Assert (databasep db))
+  (let ((filename (database-file-name db)))
+    (loop for fn in (list filename (concat filename ".db")) do
+      (when (file-exists-p fn)
+	(delete-file fn))))
+  )
 
-       (test-database (db)
-	(Assert (databasep db))
-	(put-database "key1" "val1" db)
-	(Assert (equal "val1" (get-database "key1" db)))
-	(remove-database "key1" db)
-	(Assert (equal nil (get-database "key1" db)))
-	(close-database db)
-	(Assert (not (database-live-p db)))
-	(Assert (databasep db))))
+(let ((filename (expand-file-name "test-emacs" (temp-directory))))
 
-  (let ((filename (expand-file-name "test-harness" (temp-directory))))
+  (when (featurep 'dbm)
+  (let ((db (open-database filename 'dbm)))
+    (test-database db)))
+  
+  (princ "\n")
 
-    (dolist (db-type `(dbm berkeley-db))
-      (when (featurep db-type)
-	(princ "\n")
-	(delete-database-files filename)
-	(test-database (open-database filename db-type))
-	(delete-database-files filename)))))
+  (when (featurep 'berkeley-db)
+    (let ((db (open-database filename 'berkeley-db)))
+      (test-database db)))
+  )