1 [![Build Status](https://travis-ci.org/rocky/emacs-test-simple.png)](https://travis-ci.org/rocky/emacs-test-simple)
5 * 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.
6 * Accomodates both interactive and non-interactive use:
7 * For interactive use one can use `eval-last-sexp`, `eval-region`, and `eval-buffer`
8 * For non-interactive use run as: `emacs --batch --no-site-file --no-splash --load <test-lisp-code.el>`
10 I use this in my [Debugger front end](https://github.com/rocky/emacs-dbgr).
12 Here is an example found in the [examples directory](https://github.com/rocky/emacs-test-simple/tree/master/test).
17 "Greatest Common Divisor of A and B"
25 ((or (= 0 (- b a)) (= a 1)) a)
31 In file `test-gcd.el` in the same directory:
33 (require 'test-simple)
34 (test-simple-start) ;; Zero counters and start the stop watch.
36 ;; Use (load-file) below because we want to always to read the source.
37 ;; Also, we don't want no stinking compiled source.
38 (assert-t (load-file "./gcd.el")
39 "Can't load gcd.el - are you in the right directory?" )
41 (note "degenerate cases")
43 (assert-nil (gcd 5 -1) "using positive numbers")
44 (assert-nil (gcd -4 1) "using positive numbers, switched order")
45 (assert-raises error (gcd "a" 32)
46 "Passing a string value should raise an error")
48 (note "GCD computations")
49 (assert-equal 1 (gcd 3 5) "gcd(3,5)")
50 (assert-equal 8 (gcd 8 32) "gcd(8,32)")
52 (end-tests) ;; Stop the clock and print a summary
54 Edit (with Emacs of course) `test-gcd.el` and run `M-x eval-current-buffer`
56 You should see in buffer `*test-simple*`:
60 0 failures in 6 assertions (0.002646 seconds)
62 Now let's try from a command line:
64 $ emacs --batch --no-site-file --no-splash --load test-gcd.el
65 Loading /src/external-vcs/emacs-test-simple/example/gcd.el (source)...
68 0 failures in 6 assertions (0.000723 seconds)
70 *Author:* Rocky Bernstein <rocky@gnu.org> <br>
71 [![endorse](https://api.coderwall.com/rocky/endorsecount.png)](https://coderwall.com/rocky)