Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invoke reporter #38

Merged
merged 2 commits into from
Feb 23, 2020
Merged

Conversation

cxxxr
Copy link
Contributor

@cxxxr cxxxr commented Feb 22, 2020

具体的には以下のようなユーザー側での拡張がしたい

(defpackage #:tests/reporter
  (:use #:cl
        #:rove/core/stats
        #:rove/core/result
        #:rove/reporter
        #:rove/utils/reporter))
(in-package #:tests/reporter)

(defclass test-result ()
  ((name :initarg :name :accessor test-result-name)
   (assertions :initarg :assertions :accessor test-result-assertions)))

(defclass accumulator-reporter (reporter)
  ((assertions :initform '()
               :accessor accumulator-assertions)
   (test-name :initform nil
              :accessor accumulator-test-name)
   (test-results :initform '()
                 :accessor accumulator-test-results)))

(defmethod record ((reporter accumulator-reporter) (object assertion))
  (push object (accumulator-assertions reporter)))

(defmethod test-begin :after ((reporter accumulator-reporter) test-name &optional count)
  (declare (ignore count))
  (setf (accumulator-test-name reporter) test-name)
  (setf (accumulator-assertions reporter) '())
  (values))

(defmethod test-finish ((reporter accumulator-reporter) test-name)
  (multiple-value-bind (passedp context) (call-next-method)
    (when (toplevel-stats-p reporter)
      (format-failure-tests (reporter-stream reporter) context))
    passedp)
  (push (make-instance 'test-result
                       :name test-name
                       :assertions (accumulator-assertions reporter))
        (accumulator-test-results reporter)))

(defmethod rove/reporter:invoke-reporter :around ((reporter accumulator-reporter) function)
  (call-next-method)
  reporter)

(rove/reporter/registry:add-reporter :accumulator 'accumulator-reporter)

呼出側

(rove:run-test
 'test-name
 :style :accumulator)

@fukamachi fukamachi merged commit b8f12e6 into fukamachi:master Feb 23, 2020
@fukamachi
Copy link
Owner

ありがとう!

@kazk kazk mentioned this pull request Oct 6, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants