branch: elpa/buttercup commit 159fe3c376c3c2e458fef61e90303c15c27f747f Author: Ola Nilsson <ola.nils...@gmail.com> Commit: Ola Nilsson <ola.nils...@gmail.com>
Really fix the buttercup-run tests The fix in 672bce1276c47e7c09eae66593168b83f445a8c7 was not enough. `buttercup-suites' was not correctly scoped, and somehow the global value was overwritten. The result being an incorrect number of run tests being reported at the end of the test run. I have no clue why let-binding `buttercup-suites' in each spec works better, but it does. To get it all to work on Emacs 24.3 I had to drop some of the cl-flet for less elegant solutions. --- tests/test-buttercup.el | 57 +++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el index bbcb1f3..db3df09 100644 --- a/tests/test-buttercup.el +++ b/tests/test-buttercup.el @@ -995,36 +995,41 @@ :to-throw))))) (describe "The `buttercup-run' function" - :var (buttercup-suites parent-suite child-suite spec) - (cl-flet (((reporter (event arg) (ignore event arg)))) - (before-each - (setq parent-suite (make-buttercup-suite :description "parent-suite") - child-suite (make-buttercup-suite :description "child-suite") - spec (make-buttercup-spec :description "spec") - buttercup-suites (list parent-suite)) - (buttercup-suite-add-child parent-suite child-suite) - (buttercup-suite-add-child child-suite spec) - (spy-on 'reporter)) - (it "should raise an error if at least one spec failed" - (setf (buttercup-spec-status spec) 'failed) - (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) - (buttercup-reporter 'reporter)) - (expect (buttercup-run) :to-throw))) - (it "should call the reporter twice with events buttercup-started and -done" - (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) - (buttercup-reporter 'reporter)) + :var (parent-suite child-suite spec reporter) + (before-each + (ignore reporter) + (setf (symbol-function 'reporter) (lambda (event arg) (ignore event arg))) + (setq parent-suite (make-buttercup-suite :description "parent-suite") + child-suite (make-buttercup-suite :description "child-suite") + spec (make-buttercup-spec :description "spec")) + (buttercup-suite-add-child parent-suite child-suite) + (buttercup-suite-add-child child-suite spec) + (spy-on 'reporter)) + (it "should raise an error if at least one spec failed" + (setf (buttercup-spec-status spec) 'failed) + (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) + (buttercup-reporter 'reporter)) + (let ((buttercup-suites (list parent-suite))) + (expect (buttercup-run) :to-throw)))) + (it "should call the reporter twice with events buttercup-started and -done" + (cl-letf (((symbol-function 'buttercup--run-suite) #'ignore) + (buttercup-reporter 'reporter)) + (let ((buttercup-suites (list parent-suite))) (expect (buttercup-run) :not :to-throw) (expect 'reporter :to-have-been-called-times 2) (expect 'reporter :to-have-been-called-with 'buttercup-started buttercup-suites) (expect 'reporter :to-have-been-called-with 'buttercup-done buttercup-suites))) - (it "should call `buttercup--run-suite once per suite" - (cl-flet (((runner (suite) (ignore suite)))) - (spy-on 'runner) - (cl-letf (((symbol-function 'buttercup--run-suite) #'runner) - (buttercup-reporter 'reporter) - (buttercup-suites (make-list 5 parent-suite))) - (expect (buttercup-run) :not :to-throw) - (expect 'runner :to-have-been-called-times 5)))))) + ) + (it "should call `buttercup--run-suite once per suite" + (let ((buttercup-suites (list parent-suite)) runner) + (ignore runner) + (setf (symbol-function 'runner) (lambda (suite) (ignore suite))) + (spy-on 'runner) + (cl-letf (((symbol-function 'buttercup--run-suite) #'runner) + (buttercup-reporter 'reporter) + (buttercup-suites (make-list 5 parent-suite))) + (expect (buttercup-run) :not :to-throw) + (expect 'runner :to-have-been-called-times 5))))) (describe "The `buttercup--print' function" (before-each