Permalink
Browse files

Use `read-char-spec' for `selftest-ask'.

  • Loading branch information...
1 parent e4b4aa7 commit e1e18481cfc4a4a875e573018671771db8052d2e @hober committed Jun 19, 2009
Showing with 16 additions and 14 deletions.
  1. +6 −3 README.markdown
  2. +10 −11 selftest.el
View
9 README.markdown
@@ -2,9 +2,6 @@ This is a simple library for managing your personal unit tests. If
you're unfamiliar with the concept, please read [this blog post][].
[Michal Wallace][] came up with the idea. Here's how he describes them:
- [this blog post]: http://withoutane.com/rants/2007/08/personal-unit-tests
- [Michal Wallace]: http://withoutane.com/
-
> The way I see it, there are certain things I ought to be doing to be
> productive and effective no matter what my goals are. These are things
> that are relatively easy to set up, but take discipline and awareness
@@ -23,3 +20,9 @@ Here's an example use of `selftest.el`:
:when 'always)
The command `selftest-run` may be used to run all of your tests.
+
+This library relies on [read-char-spec.el][].
+
+[Michal Wallace]: http://withoutane.com/
+[read-char-spec.el]: http://edward.oconnor.cx/elisp/read-char-spec.el
+[this blog post]: http://withoutane.com/rants/2007/08/personal-unit-tests
View
21 selftest.el
@@ -1,6 +1,6 @@
;;; selftest.el --- Personal unit tests
-;; Copyright (C) 2007 Edward O'Connor
+;; Copyright (C) 2007, 2008, 2009 Edward O'Connor
;; Author: Edward O'Connor <hober0@gmail.com>
;; Keywords: convenience
@@ -43,9 +43,13 @@
;; 2007-09-14: Added automatic Twitter posting.
;; Uses (a patched version of) twit.el, which see.
;; 2008-01-08: Added ability to filter when each test should be taken.
+;; 2009-06-19: Use `read-char-spec' for `selftest-ask' UI.
;;; Code:
+;; Latest version at http://edward.oconnor.cx/elisp/read-char-spec.el
+(require 'read-char-spec)
+
(defvar selftest-tests '())
(defvar selftest-twitter-results t
@@ -54,16 +58,11 @@ Requires twit.el, which is available on the EmacsWiki.")
(defun selftest-ask (prompt)
"Like `y-or-n-p', but asks (with PROMPT) for pass, fail, or skip."
- (setq prompt (format "%s (pass, fail, or skip)? " prompt))
- (let* ((answers '(("pass" . :pass) ("fail" . :fail) ("skip" . :skip)
- ("p" . :pass) ("f" . :fail) ("s" . :skip)
- ("y" . :pass) ("n" . :fail)))
- (answer ""))
- (while (string-equal answer "")
- (setq answer (completing-read prompt answers nil t)))
- ;; "And just in case my point you have missed
- ;; Somehow I preferred (CDR (ASSQ KEY A-LIST))"
- (cdr (assoc answer answers))))
+ (read-char-spec prompt '((?p :pass "You passed this test")
+ (?f :fail "You failed this test")
+ (?y :pass "You passed this test")
+ (?n :fail "You failed this test")
+ (?s :skip "You're skipping this test"))))
(defmacro define-selftest (slug question &rest params)
"Defines a new personal unit test named SLUG.

0 comments on commit e1e1848

Please sign in to comment.