Commit 34106069 authored by Sean Whitton's avatar Sean Whitton

Merge tag 'v1.13'

parents b0dfa3d6 079ef3e4
[bumpversion]
current_version = 1.12
current_version = 1.13
parse = (?P<major>\d+)\.(?P<minor>.*)
serialize = {major}.{minor}
files = buttercup.el buttercup-pkg.el
......
......@@ -6,6 +6,7 @@ env:
- EVM_EMACS=emacs-24.5-travis
- EVM_EMACS=emacs-25.1-travis
- EVM_EMACS=emacs-25.2-travis
- EVM_EMACS=emacs-26.1-travis
before_install:
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > travis.sh && source ./travis.sh
- evm install "$EVM_EMACS" --use --skip
......
(define-package "buttercup" "1.12"
(define-package "buttercup" "1.13"
"Behavior-Driven Emacs Lisp Testing")
......@@ -2,7 +2,7 @@
;; Copyright (C) 2015-2017 Jorgen Schaefer <contact@jorgenschaefer.de>
;; Version: 1.12
;; Version: 1.13
;; Author: Jorgen Schaefer <contact@jorgenschaefer.de>
;; Package-Requires: ((emacs "24.3"))
;; URL: https://github.com/jorgenschaefer/emacs-buttercup
......@@ -700,8 +700,8 @@ See also `buttercup-define-matcher'."
(cons (buttercup-suite-or-spec-parent suite-or-spec)
(buttercup-suite-or-spec-parents (buttercup-suite-or-spec-parent suite-or-spec)))))
(define-obsolete-function-alias 'buttercup-suite-parents 'buttercup-suite-or-spec-parents "emacs-buttercup 1.12")
(define-obsolete-function-alias 'buttercup-spec-parents 'buttercup-suite-or-spec-parents "emacs-buttercup 1.12")
(define-obsolete-function-alias 'buttercup-suite-parents 'buttercup-suite-or-spec-parents "emacs-buttercup 1.10")
(define-obsolete-function-alias 'buttercup-spec-parents 'buttercup-suite-or-spec-parents "emacs-buttercup 1.10")
(defun buttercup-suites-total-specs-defined (suite-list)
"Return the number of specs defined in all suites in SUITE-LIST."
......@@ -743,7 +743,7 @@ See also `buttercup-define-matcher'."
(defun buttercup-suite-full-name (suite)
"Return the full name of SUITE, which includes the names of the parents."
(mapconcat #'buttercup-suite-description
(nreverse (cons suite (buttercup-suite-parents suite)))
(nreverse (cons suite (buttercup-suite-or-spec-parents suite)))
" "))
(defun buttercup-spec-full-name (spec)
......@@ -915,27 +915,55 @@ FUNCTION is a function containing the body instructions passed to
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Disabled Suites: xdescribe
(defmacro xdescribe (description &rest body)
"Like `describe', but mark the suite as disabled.
(defun buttercup--disable-specs (forms)
"Process FORMS to make any suites or specs pending."
(when (eq (car forms) :var)
(setq forms (cddr forms)))
(let (retained inner)
(dolist (form forms (nreverse retained))
(pcase form
;; Make it pending by just keeping the description
(`(it ,description . ,_)
(push (list 'it description) retained))
(`(xit ,description . ,_)
(push (list 'it description) retained))
;; Just make nested describes into xdescribes and handle them
;; in another macro invocation
(`(describe . ,tail)
(push (cons 'xdescribe tail) retained))
(`(xdescribe . ,tail)
(push (cons 'xdescribe tail) retained))
;; Special case to ignore before-* and after-* forms
(`(before-each . ,_)) ; nop
(`(after-each . ,_)) ; nop
(`(before-all . ,_)) ; nop
(`(after-all . ,_)) ; nop
;; Any list starting with a list, like a let varlist.
((and (pred consp)
ls
(guard (consp (car ls))))
(dolist (elt (buttercup--disable-specs ls))
(push elt retained)))
;; Any function call list
(`(,_ . ,tail)
(dolist (elt (buttercup--disable-specs tail))
(push elt retained)))
;; non-cons items
((and elt (guard (not (consp elt))))) ; nop
(_
(error "Unrecognized form in `xdescribe': `%s'" (pp-to-string form)))
))))
A disabled suite is not run.
(defmacro xdescribe (description &rest body)
"Like `describe', but mark any specs as disabled.
DESCRIPTION is a string. BODY is a sequence of instructions,
mainly calls to `describe', `it' and `before-each'."
(declare (indent 1))
`(buttercup-xdescribe ,description (lambda () ,@body)))
(defun buttercup-xdescribe (description function)
"Like `buttercup-describe', but mark the suite as disabled.
A disabled suite is not run.
DESCRIPTION has the same meaning as in `xdescribe'. FUNCTION
is ignored.
`describe'."
(ignore function)
(buttercup-describe description (lambda ()
(signal 'buttercup-pending "PENDING"))))
`(describe ,description
,@(buttercup--disable-specs body)
;; make sure the suite is marked as pending
(signal 'buttercup-pending "PENDING")))
;;;;;;;;;;;;;;;;;;;;;;
;;; Pending Specs: xit
......@@ -1254,18 +1282,26 @@ current directory."
(buttercup-run)))
;;;###autoload
(defun buttercup-run-markdown ()
"Run all test suites defined in Markdown files passed as arguments.
A suite must be defined within a Markdown \"lisp\" code block."
(let ((lisp-buffer (generate-new-buffer "elisp")))
(dolist (file command-line-args-left)
(with-current-buffer (find-file-noselect file)
(goto-char (point-min))
(let ((case-fold-search t))
(while (re-search-forward
"```\\(?:emacs-\\|e\\)?lisp\n\\(\\(?:.\\|\n\\)*?\\)```"
nil t)
(let ((code (match-string 1)))
(defun buttercup-run-markdown-buffer (&rest markdown-buffers)
"Run all test suites defined in MARKDOWN-BUFFERS.
A suite must be defined within a Markdown \"lisp\" code block.
If MARKDOWN-BUFFERS is empty (nil), use the current buffer."
(interactive)
(unless markdown-buffers
(setq markdown-buffers (list (current-buffer))))
(let ((lisp-buffer (generate-new-buffer "elisp"))
(case-fold-search t)
code
buttercup-suites)
(dolist (markdown-buffer markdown-buffers)
(with-current-buffer markdown-buffer
(save-excursion
(save-match-data
(goto-char (point-min))
(while (re-search-forward
"```\\(?:emacs-\\|e\\)?lisp\n\\(\\(?:.\\|\n\\)*?\\)```"
nil t)
(setq code (match-string 1))
(with-current-buffer lisp-buffer
(insert code)))))))
(with-current-buffer lisp-buffer
......@@ -1274,6 +1310,20 @@ A suite must be defined within a Markdown \"lisp\" code block."
(point-max)))
(buttercup-run)))
;;;###autoload
(defun buttercup-run-markdown ()
"Run all test suites defined in Markdown files passed as arguments.
A suite must be defined within a Markdown \"lisp\" code block."
(apply #'buttercup-run-markdown-buffer (mapcar #'find-file-noselect
command-line-args-left)))
;;;###autoload
(defun buttercup-run-markdown-file (file)
"Run all test suites defined in Markdown FILE.
A suite must be defined within a Markdown \"lisp\" code block."
(interactive "fMarkdown file: ")
(buttercup-run-markdown-buffer (find-file-noselect file)))
(eval-when-compile
;; Defined below in a dedicated section
(defvar buttercup-reporter))
......@@ -1402,13 +1452,13 @@ EVENT and ARG are described in `buttercup-reporter'."
(buttercup--print "Running %s specs.\n\n" defined))))
(`suite-started
(let ((level (length (buttercup-suite-parents arg))))
(let ((level (length (buttercup-suite-or-spec-parents arg))))
(buttercup--print "%s%s\n"
(make-string (* 2 level) ?\s)
(buttercup-suite-description arg))))
(`spec-started
(let ((level (length (buttercup-spec-parents arg))))
(let ((level (length (buttercup-suite-or-spec-parents arg))))
(buttercup--print "%s%s"
(make-string (* 2 level) ?\s)
(buttercup-spec-description arg))))
......@@ -1428,7 +1478,7 @@ EVENT and ARG are described in `buttercup-reporter'."
(error "Unknown spec status %s" (buttercup-spec-status arg)))))
(`suite-done
(when (= 0 (length (buttercup-suite-parents arg)))
(when (= 0 (length (buttercup-suite-or-spec-parents arg)))
(buttercup--print "\n")))
(`buttercup-done
......@@ -1483,7 +1533,7 @@ colors.
EVENT and ARG are described in `buttercup-reporter'."
(pcase event
(`spec-done
(let ((level (length (buttercup-spec-parents arg))))
(let ((level (length (buttercup-suite-or-spec-parents arg))))
(cond
((eq (buttercup-spec-status arg) 'passed)
(buttercup--print (buttercup-colorize "\r%s%s\n" 'green)
......
......@@ -298,10 +298,11 @@ walks through the `after-each` functions similarly.
## Disabling Suites
Suites and specs can be disabled with the `xdescribe` and `xit`
macros, respectively. These suites and any specs inside them are
skipped when run and thus their results will not appear in the
results.
Suites and specs can be disabled by marking them as pending with the
`xdescribe` and `xit` macros, respectively. Any suites or specs inside
a `xdescribe' suite is also pending. Pending suites and specs will be
listed as pending in the results, but the containing code will not be
run.
```Emacs-Lisp
(xdescribe "A spec"
......@@ -316,7 +317,7 @@ results.
## Pending Specs
Pending specs do not run.
Pending specs do not run, but will be listed in the results.
Any spec declared with `xit` is marked as pending.
......
......@@ -306,7 +306,7 @@
;;; Suites: describe
(describe "The `describe' macro"
(it "should expand to a simple call to the describe function"
(it "should expand to a simple call to the buttercup-describe function"
(expect (macroexpand '(describe "description" (+ 1 1)))
:to-equal
'(buttercup-describe "description" (lambda () (+ 1 1)))))
......@@ -461,19 +461,36 @@
(it "expands directly to a function call"
(expect (macroexpand '(xdescribe "bla bla" (+ 1 1)))
:to-equal
'(buttercup-xdescribe "bla bla" (lambda () (+ 1 1))))))
(describe "The `buttercup-xdescribe' function"
(it "should be a no-op"
(expect (buttercup-xdescribe
"bla bla"
(lambda () (error "Should not happen")))
:not :to-throw))
'(buttercup-describe "bla bla"
(lambda ()
(signal 'buttercup-pending "PENDING")))))
(it "changes contained it-specs to pending specs"
(expect (macroexpand-all
'(xdescribe "bla bla"
(let ((a 1) b (c 2) (d (it "nested" (+ 1 1))))
(it "spec1" (+ 1 1))
(describe "inner suite"
(it "inner spec"))
(xit "spec2" (+ 1 1)))))
:to-equal
'(buttercup-describe
"bla bla"
#'(lambda ()
(buttercup-xit "nested")
(buttercup-xit "spec1")
(buttercup-describe
"inner suite"
#'(lambda ()
(buttercup-xit "inner spec")
(signal 'buttercup-pending "PENDING")))
(buttercup-xit "spec2")
(signal 'buttercup-pending "PENDING")))))
(it "should add a pending suite"
(let ((buttercup--current-suite nil)
(buttercup-suites nil))
(buttercup-xdescribe
(xdescribe
"bla bla"
(lambda () nil))
(expect (buttercup-suite-status (car buttercup-suites))
......@@ -960,6 +977,9 @@
(expect (length (cdr specs)) :to-equal 1)
(expect (cl-caadr specs) :to-equal "should fontify special keywords")))))
;; Local Variables:
;; indent-tabs-mode: nil
;; sentence-end-double-space: nil
;; End:
(provide 'test-buttercup)
;;; test-buttercup.el ends here
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment