+2004-11-26 Daiki Ueno <ueno@unixuser.org>
+
+ * COMPILE (riece-test): Require 'lunit after when ./test is added
+ to load-path.
+
+ * test/test-riece-yank.el (test-riece-yank-strip-space): Use
+ lunit-assert-2 instead of lunit-assert.
+
+ * test/test-riece-url.el (test-riece-url-replace-match): Use
+ lunit-assert-2 instead of lunit-assert.
+ (test-riece-url-regexp-alist): Ditto.
+
+ * test/test-riece-alias.el (test-riece-alias-percent-hack): Use
+ lunit-assert-2 instead of lunit-assert.
+ (test-riece-alias-alist-1): Ditto.
+ (test-riece-alias-alist-2): Ditto.
+ (test-riece-alias-altsep-1): Ditto.
+ (test-riece-alias-altsep-2): Ditto.
+ (test-riece-alias-altsep-3): Ditto.
+ (test-riece-alias-altsep-4): Ditto.
+
+ * test/test-riece-addon.el (test-riece-resolve-addons-1): Use
+ lunit-assert-2 instead of lunit-assert.
+ (test-riece-resolve-addons-2): Ditto.
+
+ * test/lunit.el: Don't treat a failure as an Emacs error signal;
+ count assertions in test-case methods.
+ (lunit-test-result): Add assert-count slot.
+ (lunit-make-test-result): Reset assert-count to 0.
+ (lunit-test-result-run): Count assertions; collect failures at a
+ time after test-case execution.
+ (lunit-test-result-failure): Abolished.
+ (lunit-test-case): Add failures and assert-count slots; define
+ internal accesssors for them.
+ (lunit-make-test-case): Reset assert-count to 0.
+ (lunit-test-case-run): Don't handle failure signals.
+ (lunit-assert): Define as a nop macro.
+ (lunit-assert-2): New macro. Use this instead of lunit-assert.
+ (lunit): Display assertion count.
+
2004-11-25 Daiki Ueno <ueno@unixuser.org>
* Makefile.am (EXTRA_DIST): Add url-riece.el.
;; (luna-define-class silly-test-case (lunit-test-case))
;;
;; (luna-define-method test-1 ((case silly-test-case))
-;; (lunit-assert (integerp "a")))
+;; (lunit-assert-2 case (integerp "a")))
;;
;; (luna-define-method test-2 ((case silly-test-case))
-;; (lunit-assert (stringp "b")))
+;; (lunit-assert-2 case (stringp "b")))
;;
;; (with-output-to-temp-buffer "*Lunit Results*"
;; (lunit (lunit-make-test-suite-from-class 'silly-test-case)))
;; ______________________________________________________________________
-;; Starting test `silly-test-case#test-1'
-;; failure: (integerp "a")
-;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-;; ______________________________________________________________________
-;; Starting test `silly-test-case#test-2'
-;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-;; 2 runs, 1 failures, 0 errors
+;; Running `silly-test-case#test-1'... failure: (integerp "a")
+;; Running `silly-test-case#test-2'...
+;; 2 runs, 2 assertions, 1 failures, 0 errors
;;; Code:
(put 'lunit-error 'error-message "test error")
(put 'lunit-error 'error-conditions '(lunit-error error))
-(put 'lunit-failure 'error-message "test failure")
-(put 'lunit-failure 'error-conditions '(lunit-failure lunit-error error))
-
(eval-and-compile
(luna-define-class lunit-test-result ()
(errors
failures
- listeners))
+ listeners
+ assert-count))
(luna-define-internal-accessors 'lunit-test-result))
"Report the current state of execution.")
(luna-define-generic lunit-test-result-error (result case error)
- "Add error to the list of errors.
-The passed in exception caused the error.")
-
-(luna-define-generic lunit-test-result-failure (result case failure)
- "Add failure to the list of failures.
-The passed in exception caused the failure.")
+ "Add error to the list of errors.")
(luna-define-generic lunit-test-result-add-listener (result listener)
"Add listener to the list of listeners.")
(defun lunit-make-test-result (&rest listeners)
"Return a newly allocated `lunit-test-result' instance with LISTENERS."
- (luna-make-entity 'lunit-test-result :listeners listeners))
+ (luna-make-entity 'lunit-test-result :listeners listeners :assert-count 0))
(luna-define-method lunit-test-result-notify ((result lunit-test-result)
message args)
(lunit-test-result-notify result 'lunit-test-listener-start case)
(condition-case error
(lunit-test-case-run case)
- (lunit-failure
- (lunit-test-result-failure result case (nth 1 error)))
(lunit-error
(lunit-test-result-error result case (cdr error))))
+ (lunit-test-result-set-assert-count-internal
+ result
+ (+ (lunit-test-result-assert-count-internal result)
+ (lunit-test-case-assert-count-internal case)))
+ (let ((failures
+ (lunit-test-case-failures-internal case)))
+ (when failures
+ (lunit-test-result-set-failures-internal
+ result
+ (nconc (lunit-test-result-failures-internal result)
+ (mapcar (lambda (failure)
+ (prog1 (cons case failure)
+ (lunit-test-result-notify
+ result 'lunit-test-listener-failure
+ case failure)))
+ failures)))))
(lunit-test-result-notify result 'lunit-test-listener-end case))
(luna-define-method lunit-test-result-error ((result lunit-test-result)
(lunit-test-result-set-errors-internal result errors))
(lunit-test-result-notify result 'lunit-test-listener-error case error))
-(luna-define-method lunit-test-result-failure ((result lunit-test-result)
- case failure)
- (let ((failures
- (lunit-test-result-failures-internal result)))
- (setq failures (nconc failures (list (cons case failure))))
- (lunit-test-result-set-failures-internal result failures))
- (lunit-test-result-notify result 'lunit-test-listener-failure case failure))
-
(luna-define-method lunit-test-result-add-listener ((result lunit-test-result)
listener)
(let ((listeners
;;; @ test case
;;;
-(luna-define-class lunit-test-case (lunit-test))
+(eval-and-compile
+ (luna-define-class lunit-test-case (lunit-test)
+ (failures
+ assert-count))
+
+ (luna-define-internal-accessors 'lunit-test-case))
(luna-define-generic lunit-test-case-run (case)
"Run the test case.")
"Return a newly allocated `lunit-test-case'.
CLASS is a symbol for class derived from `lunit-test-case'.
NAME is name of the method to be tested."
- (luna-make-entity class :name name))
+ (luna-make-entity class :name name :assert-count 0))
(luna-define-method lunit-test-number-of-tests ((case lunit-test-case))
1)
(error "Method \"%S\" not found" name))
(condition-case error
(funcall (car functions) case)
- (lunit-failure
- (signal (car error)(cdr error)))
(error
(signal 'lunit-error error))))
(lunit-test-case-teardown case)))
(defmacro lunit-assert (condition-expr)
"Verify that CONDITION-EXPR returns non-nil; signal an error if not."
- (let ((condition (eval condition-expr)))
- `(when ,(not condition)
- (signal 'lunit-failure (list ',condition-expr)))))
+ (princ "`lunit-assert' is obsolete; use `lunit-assert-2' instead.\n"))
+
+(defmacro lunit-assert-2 (case condition-expr)
+ "In regard to CASE, verify that CONDITION-EXPR returns non-nil;
+signal an error if not."
+ `(let ((case ,case))
+ (lunit-test-case-set-assert-count-internal
+ case
+ (1+ (lunit-test-case-assert-count-internal case)))
+ (unless ,condition-expr
+ (lunit-test-case-set-failures-internal
+ case
+ (cons ',condition-expr
+ (lunit-test-case-failures-internal case))))))
(luna-define-class lunit-test-printer (lunit-test-listener))
(result
(lunit-make-test-result printer)))
(lunit-test-run test result)
- (let ((failures
+ (let ((assert-count
+ (lunit-test-result-assert-count-internal result))
+ (failures
(lunit-test-result-failures-internal result))
(errors
(lunit-test-result-errors-internal result)))
- (princ (format "%d runs, %d failures, %d errors\n"
+ (princ (format "%d runs, %d assertions, %d failures, %d errors\n"
(lunit-test-number-of-tests test)
+ assert-count
(length failures)
(length errors))))))
(luna-define-method test-riece-alias-percent-hack ((case test-riece-alias))
(let ((riece-alias-percent-hack-mask "*.jp"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-percent-hack "#riece:*.jp")
"%riece"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-percent-hack "%riece")
"#riece:*.jp"))))
(luna-define-method test-riece-alias-alist-1 ((case test-riece-alias))
(let ((riece-alias-alist '(("#riece" . "#r"))))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-identity-string "#riece")
"#r"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-identity-string "#r")
"#riece"))))
(luna-define-method test-riece-alias-alist-2 ((case test-riece-alias))
(let ((riece-alias-alist '(("%riece" . "%r")))
(riece-alias-percent-hack-mask "*.jp"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-identity-string "#riece:*.jp")
"%r"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-identity-string "%r")
"#riece:*.jp"))))
(luna-define-method test-riece-alias-altsep-1 ((case test-riece-alias))
(let ((riece-alias-alternate-separator "@"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#riece")
"#riece"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#riece localhost")
"#riece@localhost"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#ch@nnel")
"#ch@@nnel"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#ch@nnel localhost")
"#ch@@nnel@localhost"))))
(luna-define-method test-riece-alias-altsep-2 ((case test-riece-alias))
(let ((riece-alias-alternate-separator "@@"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#riece")
"#riece"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#riece localhost")
"#riece@@localhost"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#ch@@nnel")
"#ch@@@@nnel"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-abbrev-alternate-separator "#ch@@nnel localhost")
"#ch@@@@nnel@@localhost"))))
(luna-define-method test-riece-alias-altsep-3 ((case test-riece-alias))
(let ((riece-alias-alternate-separator "@"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#riece")
"#riece"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#riece@localhost")
"#riece localhost"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#ch@@nnel")
"#ch@nnel"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#ch@@nnel@localhost")
"#ch@nnel localhost"))))
(luna-define-method test-riece-alias-altsep-4 ((case test-riece-alias))
(let ((riece-alias-alternate-separator "@@"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#riece")
"#riece"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#riece@@localhost")
"#riece localhost"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#ch@@@@nnel")
"#ch@@nnel"))
- (lunit-assert
+ (lunit-assert-2
+ case
(equal
(riece-alias-expand-alternate-separator "#ch@@@@nnel@@localhost")
"#ch@@nnel localhost"))))
\ No newline at end of file