A testing framework for guile.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
COPYING
README.org
example.scm
test.scm

README.org

guile-unit

Guile-unit is a simple unit testing framework for guile. It provides a very simple interface for writing unit tests.

Its main goal is to provide a language which is as expressive as possible in terms of specifying the desired behavior of a function. The design is inspired by BDD.

Example

A test suite is defined by using the define-test-suite macro. Whereas a test suite is a composition of test cases. Test cases are defined by using the should macro.

A test suite for testing the following program

(define delta 0.00001)

(define (sqrt x)
  (let optimize ((g 1.))
    (if (<= (abs (- g (/ x g))) delta)
        g
        (optimize (/ (+ (/ x g) g) 2)))))

could look like this.

(use-modules (test))

(define-test-suite sqrt-tests
  (should determine the square root of a
          ((given that a is 9)
           (when the-result is (sqrt a))
           (assert that the-result is lower than (+ 3 delta))
           (assert that the-result is greater than (- 3 delta))))
  (should determine the square root of b
          ((given that (a is 7) and (b is (* 7 7)))
           (when the-result is (sqrt b))
           (assert that the-result is lower than (+ a delta))
           (assert that the-result is greater than (- a delta)))))

(run-test-suites sqrt-tests)

For now the output of the example from above is the following.

ToDo

make assertions composable

add assertion for floating point numbers

make whole framework side-effect free

License

GNU GPL v3+

See COPYING for the full license text.