[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3056b86 13/26: Merge pull request #9 from rubikitch/test-r
From: |
Rocky Bernstein |
Subject: |
[elpa] master 3056b86 13/26: Merge pull request #9 from rubikitch/test-runner |
Date: |
Thu, 25 May 2017 02:22:14 -0400 (EDT) |
branch: master
commit 3056b86708dd45be99831add75c4754b2bf09d6c
Merge: 01f08e3 e904e38
Author: R. Bernstein <address@hidden>
Commit: R. Bernstein <address@hidden>
Merge pull request #9 from rubikitch/test-runner
I improved noninteractive test. Thanks!
---
.travis.yml | 12 +++++++++---
README.md | 18 +++++++++++++++++-
example/gcd-tests.el | 1 +
test-simple.el | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 80 insertions(+), 5 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 9280a20..743fe94 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,8 +1,14 @@
language: emacs
-install:
- # Install emacs.
- - "sudo apt-get install emacs23-nox"
+env:
+ - EMACS=emacs24
+install:
+ - if [ "$EMACS" = 'emacs24' ]; then
+ sudo add-apt-repository -y ppa:cassou/emacs &&
+ sudo apt-get -qq update &&
+ sudo apt-get -qq -f install &&
+ sudo apt-get -qq install emacs24 emacs24-el;
+ fi
# run the tests
script: /bin/sh ./autogen.sh && make check
diff --git a/README.md b/README.md
index 6b4b965..9481052 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
* Simple -- no need for context macros, enclosing specifications, or required
test tags. But if you want, you still can add custom assert failure messages or
add notes before a group of tests.
* Accomodates both interactive and non-interactive use:
* For interactive use one can use `eval-last-sexp`, `eval-region`, and
`eval-buffer`
- * For non-interactive use run as: `emacs --batch --no-site-file --no-splash
--load <test-lisp-code.el>`
+ * For non-interactive use run as: `emacs --batch --no-site-file --no-splash
--load <test-lisp-code.el>`, or `test-simple-run`
I use this in my [Debugger front end](https://github.com/rocky/emacs-dbgr).
@@ -67,5 +67,21 @@ Now let's try from a command line:
......
0 failures in 6 assertions (0.000723 seconds)
+
+You can run noninteractive tests inside Emacs by `test-simple-run`.
+Add the following at a test file:
+
+ ;;;; (test-simple-run "emacs -batch -L %s -l %s" (file-name-directory
(locate-library "test-simple.elc")) buffer-file-name)
+
+Press C-x C-e at the `test-simple-run` line to run this test file.
+Then press C-x C-z, which is customizable by `test-simple-runner-key`, to run
it more.
+If you have installed `bpr` package, use it by default because it only pops up
window when the running program exits abnormally.
+
+`test-simple-run` can be called interactively.
+In this case, the command line is set above as the simplest case.
+But you run test with dependency, you must use the sexp comment form.
+
+ ;;;; (test-simple-run "emacs -batch -L %s -L %s -l %s"
(file-name-directory (locate-library "test-simple.elc")) (file-name-directory
(locate-library "foo")) buffer-file-name)
+
*Author:* Rocky Bernstein <address@hidden> <br>
[![endorse](https://api.coderwall.com/rocky/endorsecount.png)](https://coderwall.com/rocky)
diff --git a/example/gcd-tests.el b/example/gcd-tests.el
index 8ffdce8..173074d 100644
--- a/example/gcd-tests.el
+++ b/example/gcd-tests.el
@@ -19,6 +19,7 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see
;; <http://www.gnu.org/licenses/>.
+;;;; (test-simple-run "emacs -batch -L %s -l %s" (file-name-directory
(locate-library "test-simple.elc")) buffer-file-name)
(require 'test-simple)
(test-simple-start)
diff --git a/test-simple.el b/test-simple.el
index 72cdca0..e257855 100644
--- a/test-simple.el
+++ b/test-simple.el
@@ -1,4 +1,4 @@
-;;; test-simple.el --- Simple Unit Test Framework for Emacs Lisp
+;;; test-simple.el --- Simple Unit Test Framework for Emacs Lisp -*-
lexical-binding: t -*-
;; Rewritten from Phil Hagelberg's behave.el by rocky
;; Copyright (C) 2015 Free Software Foundation, Inc
@@ -97,6 +97,26 @@
)
(require 'cl)
+(defgroup test-simple nil
+ "Simple Unit Test Framework for Emacs Lisp"
+ :group 'lisp)
+
+(defcustom test-simple-runner-interface (if (fboundp 'bpr-spawn)
+ 'bpr-spawn
+ 'compile)
+ "Function with one string argument when running tests non-interactively.
+Command line started with `emacs --batch' is passed as the argument.
+
+`bpr-spawn', which is in bpr package, is preferable because of no window popup.
+If bpr is not installed, fall back to `compile'."
+ :type 'function
+ :group 'test-simple)
+
+(defcustom test-simple-runner-key "C-x C-z"
+ "Key to run non-interactive test after defining command line by
`test-simple-run'."
+ :type 'string
+ :group 'test-simple)
+
(defvar test-simple-debug-on-error nil
"If non-nil raise an error on the first failure.")
@@ -330,5 +350,37 @@ funnel down to this one, ASSERT-TYPE is an optional type."
(goto-char (point-max))
(test-simple-msg (test-simple-summary-line test-info)))
+;;;###autoload
+(defun test-simple-run (&rest command-line-formats)
+ "Register command line to run tests non-interactively and bind key to run
test.
+After calling this function, you can run test by key specified by
`test-simple-runner-key'.
+
+It is preferable to write at the first line of test files as a comment, e.g,
+;;;; (test-simple-run \"emacs -batch -L %s -l %s\" (file-name-directory
(locate-library \"test-simple.elc\")) buffer-file-name)
+
+Calling this function interactively, COMMAND-LINE-FORMATS is set above."
+ (interactive)
+ (setq command-line-formats
+ (or command-line-formats
+ (list "emacs -batch -L %s -l %s"
+ (file-name-directory (locate-library "test-simple.elc"))
+ buffer-file-name)))
+ (let ((func (lambda ()
+ (interactive)
+ (funcall test-simple-runner-interface
+ (apply 'format command-line-formats)))))
+ (global-set-key (kbd test-simple-runner-key) func)
+ (funcall func)))
+
+(defun test-simple-noninteractive-kill-emacs-hook ()
+ "Emacs exits abnormally when noninteractive test fails."
+ (when (and noninteractive test-simple-info
+ (<= 1 (test-info-failure-count test-simple-info)))
+ (let (kill-emacs-hook)
+ (kill-emacs 1))))
+(when noninteractive
+ (add-hook 'kill-emacs-hook 'test-simple-noninteractive-kill-emacs-hook))
+
+
(provide 'test-simple)
;;; test-simple.el ends here
- [elpa] master 8204b89 10/26: .travis.yml: Drop support of Emacs23 (Test in Emacs24), (continued)
- [elpa] master 8204b89 10/26: .travis.yml: Drop support of Emacs23 (Test in Emacs24), Rocky Bernstein, 2017/05/25
- [elpa] master 35ef95d 09/26: Mention test-simple-run in README.md, Rocky Bernstein, 2017/05/25
- [elpa] master 613fe8b 19/26: Version 1.2.0 sync with elpa, Rocky Bernstein, 2017/05/25
- [elpa] master 604942d 24/26: Merge pull request #12 from syohex/cl-lib, Rocky Bernstein, 2017/05/25
- [elpa] master a2383c7 26/26: Bump version .., Rocky Bernstein, 2017/05/25
- [elpa] master e18adb1 25/26: Merge commit '604942d36021a8b14877a0a640234a09c79e0927', Rocky Bernstein, 2017/05/25
- [elpa] master 187808a 21/26: TAP output in batch mode now goes to stdout, not stderr, Rocky Bernstein, 2017/05/25
- [elpa] master 0d2969f 23/26: Use cl-lib instead of cl.el, Rocky Bernstein, 2017/05/25
- [elpa] master e904e38 12/26: Mention M-x test-simple-run in README.md, Rocky Bernstein, 2017/05/25
- [elpa] master 4c40e8d 15/26: A spelling typo, Rocky Bernstein, 2017/05/25
- [elpa] master 3056b86 13/26: Merge pull request #9 from rubikitch/test-runner,
Rocky Bernstein <=
- [elpa] master 95e58b5 18/26: Why didn't I do this before?!, Rocky Bernstein, 2017/05/25