branch: elpa/buttercup commit e6fd5f5b406e7f647ee8061487b73fe34aff4cb0 Author: Jorgen Schaefer <cont...@jorgenschaefer.de> Commit: Jorgen Schaefer <cont...@jorgenschaefer.de>
Track pending specs separately Mark the status of a spec as pending when the spec is defined, not just when it is run. This allows reporters to report pending specs right from the start. Fixes #30 --- buttercup.el | 86 +++++++++++++++++++++++++++++++------------------ tests/test-buttercup.el | 18 ++++++++--- 2 files changed, 68 insertions(+), 36 deletions(-) diff --git a/buttercup.el b/buttercup.el index 7e5a521..c8b4400 100644 --- a/buttercup.el +++ b/buttercup.el @@ -293,6 +293,15 @@ MATCHER is either a matcher defined with (setq nspecs (1+ nspecs)))) nspecs)) +(defun buttercup-suites-total-specs-pending (suite-list) + "Return the number of specs marked as pending in all suites in SUITE-LIST." + (let ((nspecs 0)) + (dolist (spec-or-suite (buttercup--specs-and-suites suite-list)) + (when (and (buttercup-spec-p spec-or-suite) + (eq (buttercup-spec-status spec-or-suite) 'pending)) + (setq nspecs (1+ nspecs)))) + nspecs)) + (defun buttercup-suites-total-specs-failed (suite-list) "Return the number of failed specs in all suites in SUITE-LIST." (let ((nspecs 0)) @@ -377,8 +386,7 @@ form.") (declare (indent 1) (debug (&define sexp def-body))) (if body `(buttercup-it ,description (lambda () ,@body)) - `(buttercup-it ,description (lambda () - (signal 'buttercup-pending "PENDING"))))) + `(buttercup-xit ,description))) (defun buttercup-it (description body-function) "Function to handle an `it' form." @@ -461,14 +469,18 @@ A disabled suite is not run." A disabled spec is not run." (declare (indent 1)) - `(buttercup-xit ,description (lambda () ,@body))) + `(buttercup-xit ,description)) -(defun buttercup-xit (description function) +(defun buttercup-xit (description &optional function) "Like `buttercup-it', but mark the spec as disabled. A disabled spec is not run." (buttercup-it description (lambda () - (signal 'buttercup-pending "PENDING")))) + (signal 'buttercup-pending "PENDING"))) + (let ((spec (car (last (buttercup-suite-children + buttercup--current-suite))))) + (setf (buttercup-spec-status spec) + 'pending))) ;;;;;;;;; ;;; Spies @@ -729,13 +741,12 @@ Do not change the global value.") (funcall buttercup-reporter 'suite-started suite) (dolist (f (buttercup-suite-before-all suite)) (buttercup--update-with-funcall suite f)) - (when (eq (buttercup-suite-status suite) 'passed) - (dolist (sub (buttercup-suite-children suite)) - (cond - ((buttercup-suite-p sub) - (buttercup--run-suite sub)) - ((buttercup-spec-p sub) - (buttercup--run-spec sub))))) + (dolist (sub (buttercup-suite-children suite)) + (cond + ((buttercup-suite-p sub) + (buttercup--run-suite sub)) + ((buttercup-spec-p sub) + (buttercup--run-spec sub)))) (dolist (f (buttercup-suite-after-all suite)) (buttercup--update-with-funcall suite f)) (funcall buttercup-reporter 'suite-done suite))) @@ -745,8 +756,7 @@ Do not change the global value.") (buttercup--with-cleanup (dolist (f buttercup--before-each) (buttercup--update-with-funcall spec f)) - (when (eq (buttercup-spec-status spec) 'passed) - (buttercup--update-with-funcall spec (buttercup-spec-function spec))) + (buttercup--update-with-funcall spec (buttercup-spec-function spec)) (dolist (f buttercup--after-each) (buttercup--update-with-funcall spec f))) (funcall buttercup-reporter 'spec-done spec)) @@ -765,15 +775,13 @@ Do not change the global value.") description pending-description)))) (cond ((buttercup-suite-p suite-or-spec) - (when (eq (buttercup-suite-status suite-or-spec) 'passed) - (setf (buttercup-suite-status suite-or-spec) status) - (setf (buttercup-suite-failure-description suite-or-spec) description) - (setf (buttercup-suite-failure-stack suite-or-spec) stack))) + (setf (buttercup-suite-status suite-or-spec) status) + (setf (buttercup-suite-failure-description suite-or-spec) description) + (setf (buttercup-suite-failure-stack suite-or-spec) stack)) (t - (when (eq (buttercup-spec-status suite-or-spec) 'passed) - (setf (buttercup-spec-status suite-or-spec) status) - (setf (buttercup-spec-failure-description suite-or-spec) description) - (setf (buttercup-spec-failure-stack suite-or-spec) stack)))))) + (setf (buttercup-spec-status suite-or-spec) status) + (setf (buttercup-spec-failure-description suite-or-spec) description) + (setf (buttercup-spec-failure-stack suite-or-spec) stack))))) ;;;;;;;;;;;;; ;;; Reporters @@ -825,8 +833,13 @@ Calls either `buttercup-reporter-batch' or (`buttercup-started (setq buttercup-reporter-batch--start-time (float-time) buttercup-reporter-batch--failures nil) - (buttercup--print "Running %s specs.\n\n" - (buttercup-suites-total-specs-defined arg))) + (let ((defined (buttercup-suites-total-specs-defined arg)) + (pending (buttercup-suites-total-specs-pending arg))) + (if (> pending 0) + (buttercup--print "Running %s out of %s specs.\n\n" + (- defined pending) + defined) + (buttercup--print "Running %s specs.\n\n" defined)))) (`suite-started (let ((level (length (buttercup-suite-parents arg)))) @@ -882,13 +895,24 @@ Calls either `buttercup-reporter-batch' or (t (buttercup--print "FAILED: %S\n" description))) (buttercup--print "\n"))) - (buttercup--print "Ran %s specs, %s failed, in %.1f seconds.\n" - (buttercup-suites-total-specs-defined arg) - (buttercup-suites-total-specs-failed arg) - (- (float-time) - buttercup-reporter-batch--start-time)) - (when (> (buttercup-suites-total-specs-failed arg) 0) - (error ""))) + (let ((defined (buttercup-suites-total-specs-defined arg)) + (pending (buttercup-suites-total-specs-pending arg)) + (failed (buttercup-suites-total-specs-failed arg)) + (duration (- (float-time) + buttercup-reporter-batch--start-time))) + (if (> pending 0) + (buttercup--print + "Ran %s out of %s specs, %s failed, in %.1f seconds.\n" + (- defined pending) + defined + failed + duration) + (buttercup--print "Ran %s specs, %s failed, in %.1f seconds.\n" + defined + failed + duration)) + (when (> failed 0) + (error "")))) (_ (error "Unknown event %s" event))))) diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el index deb0784..fee0b09 100644 --- a/tests/test-buttercup.el +++ b/tests/test-buttercup.el @@ -344,11 +344,10 @@ :to-equal '(buttercup-it "description" (lambda () body)))) - (it "without argument should expand to a pending signal raiser." + (it "without argument should expand to xit." (expect (macroexpand '(it "description")) :to-equal - '(buttercup-it "description" - (lambda () (signal 'buttercup-pending "PENDING")))))) + '(buttercup-xit "description")))) (describe "The `buttercup-it' function" (it "should fail if not called from within a describe form" @@ -470,7 +469,7 @@ (it "expands directly to a function call" (expect (macroexpand '(xit "bla bla" (+ 1 1))) :to-equal - '(buttercup-xit "bla bla" (lambda () (+ 1 1)))))) + '(buttercup-xit "bla bla")))) (describe "The `buttercup-xit' function" (it "should be a no-op" @@ -487,7 +486,15 @@ (error "should not happen"))) (expect (buttercup-spec-function (car (buttercup-suite-children buttercup--current-suite))) - :to-throw 'buttercup-pending)))) + :to-throw 'buttercup-pending))) + + (it "should mark the suite as pending" + (let ((buttercup--current-suite (make-buttercup-suite))) + (buttercup-xit "bla bla" (lambda ())) + (expect (buttercup-spec-status + (car (last (buttercup-suite-children + buttercup--current-suite)))) + :to-be 'pending)))) ;;;;;;;;; ;;; Spies @@ -722,3 +729,4 @@ (list '(t / 1 0))))) (error "Expected erroring buttercup--funcall not to return %S" res))) +