Git Product home page Git Product logo

emacs-test-simple's Introduction

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)

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 [email protected]
endorse

emacs-test-simple's People

Contributors

elbeardmorez avatar expez avatar mar-kolya avatar rocky avatar rubikitch avatar syohex avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.