Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Unit tests for GNU emacs that work interactively and in batch
branch: master
Failed to load latest commit information.
example Assign FSF Copyright and boilerplate.
test Reduce boilerplate verbiage
.gitignore
.travis.yml Try travis build with emacs23-nox
AUTHORS Rework test-unit into something even simpler.
COPYING Use GPL3
Carton Try using Carton packaging
ChangeLog Assign FSF Copyright and boilerplate.
INSTALL One more change
Makefile.am Assign FSF Copyright and boilerplate.
NEWS 1.0 release
README.md grammar typo
THANKS Thanks to Lars expez
autogen.sh autoreconf, don't force update
common.mk Much improved. "make check-short" added. Give elapsed time in microse…
compute-lispdir.sh install-from-git.sh: forgot to set protocol. rest: Attempt to figure …
configure.ac 1.0 release
copyright_exceptions Assign FSF Copyright and boilerplate.
elisp-comp This emacs package doesn't need any other of my emacs packages
install-from-git.sh Put back in git clone of emacs-test-simple
make-check-filter.rb
test-simple.el Bump version #

README.md

Build Status

test-simple.el is :

  • 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>

I use this in my Debugger front end.

Here is an example found in the examples directory.

In file gcd.el:

(defun gcd(a b)
  "Greatest Common Divisor of A and B"
  ;; Make a < b
  (if (> a b)
      (let ((c a))
    (setq a b)
    (setq b c)))
  (cond
   ((< a 0) nil)
   ((or (= 0 (- b a)) (= a 1)) a)
   (t (gcd (- b a) a))
   )
)

In file test-gcd.el in the same directory:

(require 'test-simple)
(test-simple-start) ;; Zero counters and start the stop watch.

;; Use (load-file) below because we want to always to read the source.
;; Also, we don't want no stinking compiled source.
(assert-t (load-file "./gcd.el")
      "Can't load gcd.el - are you in the right directory?" )

(note "degenerate cases")

(assert-nil (gcd 5 -1) "using positive numbers")
(assert-nil (gcd -4 1) "using positive numbers, switched order")
(assert-raises error (gcd "a" 32)
           "Passing a string value should raise an error")

(note "GCD computations")
(assert-equal 1 (gcd 3 5) "gcd(3,5)")
(assert-equal 8 (gcd 8 32) "gcd(8,32)")

(end-tests) ;; Stop the clock and print a summary

Edit (with Emacs of course) test-gcd.el and run M-x eval-current-buffer

You should see in buffer *test-simple*:

test-gcd.el
......
0 failures in 6 assertions (0.002646 seconds)

Now let's try from a command line:

$ emacs --batch --no-site-file --no-splash --load test-gcd.el
Loading /src/external-vcs/emacs-test-simple/example/gcd.el (source)...
*scratch*
......
0 failures in 6 assertions (0.000723 seconds)

Author: Rocky Bernstein rocky@gnu.org
endorse

Something went wrong with that request. Please try again.