Revision: 6684
Author: ek.kato
Date: Thu Aug 5 04:17:48 2010
Log: * scm/util.scm (try-load)
- Return #t if succeeded instead of #<undef>.
* test/utiltest-misc.scm
- (test-try-load)
- (test-try-require)
- New test.
http://code.google.com/p/uim/source/detail?r=6684
Modified:
/trunk/scm/util.scm
/trunk/test/util/test-misc.scm
=======================================
--- /trunk/scm/util.scm Wed Aug 4 23:36:19 2010
+++ /trunk/scm/util.scm Thu Aug 5 04:17:48 2010
@@ -255,7 +255,6 @@
(let ((paths (string-split (load-path) ":")))
(map (lambda (x) (string-append x "/" file)) paths)))))
-;; TODO: write test
;; returns succeeded or not
(define try-load
(lambda (file)
@@ -266,12 +265,13 @@
(rest (cdr paths)))
;; to suppress error message, check file existence first
(if (file-readable? path)
- (load path)
+ (begin
+ (load path)
+ #t)
(if (not (null? rest))
(loop (car rest) (cdr rest))
#f)))))))
-;; TODO: write test
;; returns succeeded or not
(define try-require
(lambda (file)
=======================================
--- /trunk/test/util/test-misc.scm Tue Jul 27 22:42:55 2010
+++ /trunk/test/util/test-misc.scm Thu Aug 5 04:17:48 2010
@@ -262,4 +262,16 @@
(assert-uim-equal 5 '(clamp 10 -5 5))
#f)
+(define (test-try-load)
+ (assert-uim-true-value '(try-load "anthy.scm"))
+ (assert-uim-false '(try-load "nonexistent.scm"))
+ (assert-uim-false '(try-load "scim.scm")) ;; try broken scim.scm
+ #f)
+
+(define (test-try-require)
+ (assert-uim-true-value '(try-require "anthy.scm"))
+ (assert-uim-false '(try-require "nonexistent.scm"))
+ (assert-uim-false '(try-require "scim.scm")) ;; try broken scim.scm
+ #f)
+
(provide "test/util/test-misc")