[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup 84002e9 054/340: Add parent relations to specs a
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup 84002e9 054/340: Add parent relations to specs and suites. |
Date: |
Thu, 16 Dec 2021 14:59:03 -0500 (EST) |
branch: elpa/buttercup
commit 84002e9feed4d428c0204b0d79cce138ecfbb021
Author: Jorgen Schaefer <contact@jorgenschaefer.de>
Commit: Jorgen Schaefer <contact@jorgenschaefer.de>
Add parent relations to specs and suites.
Also, add a basic reporter functionality that makes use of this.
Will expand the reporter interface later.
---
buttercup-test.el | 51 +++++++++++++++++++++++++----
buttercup.el | 97 ++++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 123 insertions(+), 25 deletions(-)
diff --git a/buttercup-test.el b/buttercup-test.el
index 5e01ecd..6d2ebd3 100644
--- a/buttercup-test.el
+++ b/buttercup-test.el
@@ -138,22 +138,61 @@
(describe "The `buttercup-suite-add-child' function"
(it "should add an element at the end of the list"
- (let ((suite (make-buttercup-suite :children '(1 2 3))))
+ (let* ((specs (list (make-buttercup-spec)
+ (make-buttercup-spec)
+ (make-buttercup-spec)))
+ (suite (make-buttercup-suite :children specs))
+ (spec (make-buttercup-spec)))
- (buttercup-suite-add-child suite 4)
+ (buttercup-suite-add-child suite spec)
(expect (buttercup-suite-children suite)
:to-equal
- '(1 2 3 4))))
+ (append specs (list spec)))))
(it "should add an element even if the list is empty"
- (let ((suite (make-buttercup-suite :children nil)))
+ (let ((suite (make-buttercup-suite :children nil))
+ (spec (make-buttercup-spec)))
- (buttercup-suite-add-child suite 23)
+ (buttercup-suite-add-child suite spec)
(expect (buttercup-suite-children suite)
:to-equal
- '(23)))))
+ (list spec))))
+
+ (it "should add the parent to the child"
+ (let ((parent (make-buttercup-suite))
+ (child (make-buttercup-suite)))
+
+ (buttercup-suite-add-child parent child)
+
+ (expect (buttercup-suite-parent child)
+ :to-equal
+ parent))))
+
+(describe "The `buttercup-suite-parents' function"
+ (it "should return the list of parents for a suite"
+ (let ((grandparent (make-buttercup-suite))
+ (parent (make-buttercup-suite))
+ (child (make-buttercup-suite)))
+ (buttercup-suite-add-child grandparent parent)
+ (buttercup-suite-add-child parent child)
+
+ (expect (buttercup-suite-parents child)
+ :to-equal
+ (list parent grandparent)))))
+
+(describe "The `buttercup-spec-parents' function"
+ (it "should return the list of parents for a spec"
+ (let ((grandparent (make-buttercup-suite))
+ (parent (make-buttercup-suite))
+ (child (make-buttercup-spec)))
+ (buttercup-suite-add-child grandparent parent)
+ (buttercup-suite-add-child parent child)
+
+ (expect (buttercup-spec-parents child)
+ :to-equal
+ (list parent grandparent)))))
(describe "The `describe' macro"
(it "should expand to a simple call to the describe function"
diff --git a/buttercup.el b/buttercup.el
index 73fe6f0..05837ae 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -217,16 +217,43 @@ MATCHER is either a matcher defined with
(cl-defstruct buttercup-suite
description
children
+ parent
before-each
after-each
before-all
after-all)
+;; Have to define the spec up here instead of with the specs where it
+;; belongs because we `setf' to it here.
+(cl-defstruct buttercup-spec
+ description
+ parent
+ function)
+
(defun buttercup-suite-add-child (parent child)
"Add a CHILD suite to a PARENT suite."
(setf (buttercup-suite-children parent)
(append (buttercup-suite-children parent)
- (list child))))
+ (list child)))
+ (if (buttercup-suite-p child)
+ (setf (buttercup-suite-parent child)
+ parent)
+ (setf (buttercup-spec-parent child)
+ parent)))
+
+(defun buttercup-suite-parents (suite)
+ "Return a list of parents of SUITE."
+ (if (buttercup-suite-parent suite)
+ (cons (buttercup-suite-parent suite)
+ (buttercup-suite-parents (buttercup-suite-parent suite)))
+ nil))
+
+(defun buttercup-spec-parents (spec)
+ "Return a list of parents of SPEC."
+ (if (buttercup-spec-parent spec)
+ (cons (buttercup-spec-parent spec)
+ (buttercup-suite-parents (buttercup-spec-parent spec)))
+ nil))
(defvar buttercup-suites nil
"The list of all currently defined Buttercup suites.")
@@ -257,10 +284,6 @@ form.")
;;;;;;;;;;;;;
;;; Specs: it
-(cl-defstruct buttercup-spec
- description
- function)
-
(defmacro it (description &rest body)
"Define a spec."
(declare (indent 1) (debug (&define sexp def-body)))
@@ -546,7 +569,10 @@ current directory."
(defun buttercup-run ()
(if buttercup-suites
- (mapc #'buttercup--run-suite buttercup-suites)
+ (progn
+ (funcall buttercup-reporter 'buttercup-started buttercup-suites)
+ (mapc #'buttercup--run-suite buttercup-suites)
+ (funcall buttercup-reporter 'buttercup-done buttercup-suites))
(error "No suites defined")))
(defvar buttercup--before-each nil
@@ -559,37 +585,70 @@ Do not change the global value.")
Do not change the global value.")
-(defun buttercup--run-suite (suite &optional level)
- (let* ((level (or level 0))
- (indent (make-string (* 2 level) ?\s))
- (buttercup--before-each (append buttercup--before-each
+(defun buttercup--run-suite (suite)
+ (let* ((buttercup--before-each (append buttercup--before-each
(buttercup-suite-before-each suite)))
(buttercup--after-each (append (buttercup-suite-after-each suite)
buttercup--after-each))
(debug-on-error t))
- (message "%s%s" indent (buttercup-suite-description suite))
+ (funcall buttercup-reporter 'suite-started suite)
(dolist (f (buttercup-suite-before-all suite))
(funcall f))
(dolist (sub (buttercup-suite-children suite))
(cond
((buttercup-suite-p sub)
- (buttercup--run-suite sub (1+ level)))
+ (buttercup--run-suite sub))
((buttercup-spec-p sub)
- (buttercup--run-spec sub (1+ level)))))
+ (buttercup--run-spec sub))))
(dolist (f (buttercup-suite-after-all suite))
(funcall f))
- (message "")))
+ (funcall buttercup-reporter 'suite-done suite)))
-(defun buttercup--run-spec (spec level)
- (message "%s%s"
- (make-string (* 2 level) ?\s)
- (buttercup-spec-description spec))
+(defun buttercup--run-spec (spec)
+ (funcall buttercup-reporter 'spec-started spec)
(buttercup--with-cleanup
(dolist (f buttercup--before-each)
(funcall f))
(funcall (buttercup-spec-function spec))
(dolist (f buttercup--after-each)
- (funcall f))))
+ (funcall f)))
+ (funcall buttercup-reporter 'spec-done spec))
+
+;;;;;;;;;;;;;
+;;; Reporters
+
+(defvar buttercup-reporter #'buttercup-reporter-batch
+ "The reporter function for buttercup test runs.")
+
+(defun buttercup-reporter-batch (event arg)
+ (pcase event
+ (`buttercup-started
+ t)
+
+ (`suite-started
+ (let ((level (length (buttercup-suite-parents arg))))
+ (message "%s%s"
+ (make-string (* 2 level) ?\s)
+ (buttercup-suite-description arg))))
+
+ (`spec-started
+ (let ((level (length (buttercup-spec-parents arg))))
+ (message "%s%s"
+ (make-string (* 2 level) ?\s)
+ (buttercup-spec-description arg))))
+
+ (`spec-done
+ t)
+
+ (`suite-done
+ (when (= 0 (length (buttercup-suite-parents arg)))
+ (message "")))
+
+ (`buttercup-done
+ t)
+
+ (t
+ (error "Unknown event %s" event))))
(provide 'buttercup)
;;; buttercup.el ends here
- [nongnu] elpa/buttercup b1bcedc 032/340: Add docstrings where missing., (continued)
- [nongnu] elpa/buttercup b1bcedc 032/340: Add docstrings where missing., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 821cfa6 005/340: Comment separating built-in matchers from the rest., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 8e30284 024/340: Disabled suites, pending specs., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 89c00aa 009/340: Makefile: Make the emacs command configurable, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7e20ff1 021/340: ROADMAP.md: New file., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 764d6aa 020/340: Tests for the it macro and buttercup-it function., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d5572a6 034/340: Refactoring of the cleanup code., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b75b3e9 036/340: Add a discovery test runner., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7eecb96 038/340: Remove commented-out backtrace code from buttercup.el., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 3483449 045/340: Typo fix., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 84002e9 054/340: Add parent relations to specs and suites.,
ELPA Syncer <=
- [nongnu] elpa/buttercup a7d9813 010/340: Add cl-defstruct compatibility alias., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fd70ccf 002/340: Specs are now structs., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup ba40ff8 027/340: Spies: :and-return-value, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 20b87dd 031/340: Refactoring of spy-on to be more concise and DRY., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup bb31c85 043/340: Edebugable., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5d369cd 007/340: Do not use emacs-snapshot from EVM, that's slow., ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 07b1ee6 008/340: Add compatibility definition for define-error, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 7cdb219 028/340: Spies: :and-call-fake, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5db449f 025/340: Spies, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup d580e5c 011/340: Add build status badge., ELPA Syncer, 2021/12/16