sema-test 0.1.0

Test framework for Sema — define, run, and report test results

API reference 8 exports

Exported declarations from this release. Parameter names and descriptions come directly from its source.

test/assert-contains

Source :53
(test/assert-contains haystack needle)
Assert that a list contains an element or a string contains a substring.
View source definition
(define (test/assert-contains haystack needle)
  "Assert that a list contains an element or a string contains a substring."
  (let ((found (cond
                 ((string? haystack) (string/contains? haystack needle))
                 ((list? haystack)   (any #(equal? % needle) haystack))
                 (#t (error (format "test/assert-contains: expected list or string, got ~a" haystack))))))
    (when (not found)
      (error (format "expected ~a to contain ~a" haystack needle)))
    #t))

test/assert-equal

Source :17
(test/assert-equal expected actual)
Assert that expected and actual are deeply equal.
View source definition
(define (test/assert-equal expected actual)
  "Assert that expected and actual are deeply equal."
  (when (not (equal? expected actual))
    (error (format "expected ~a, got ~a" expected actual)))
  #t)

test/assert-false

Source :29
(test/assert-false value)
Assert that value is falsy.
View source definition
(define (test/assert-false value)
  "Assert that value is falsy."
  (when value
    (error (format "expected falsy value, got ~a" value)))
  #t)

test/assert-near

Source :45
(test/assert-near expected actual tolerance)
Assert that expected and actual differ by at most tolerance.
View source definition
(define (test/assert-near expected actual tolerance)
  "Assert that expected and actual differ by at most tolerance."
  (let ((diff (abs (- expected actual))))
    (when (> diff tolerance)
      (error (format "expected ~a ≈ ~a (tolerance ~a), diff was ~a"
                     expected actual tolerance diff)))
    #t))

test/assert-throws

Source :35
(test/assert-throws thunk)
Assert that calling thunk raises an error.
View source definition
(define (test/assert-throws thunk)
  "Assert that calling thunk raises an error."
  (let ((threw #f))
    (try
      (begin (thunk) nil)
      (catch e (set! threw #t)))
    (when (not threw)
      (error "expected an error to be thrown, but none was"))
    #t))

test/assert-true

Source :23
(test/assert-true value)
Assert that value is truthy.
View source definition
(define (test/assert-true value)
  "Assert that value is truthy."
  (when (not value)
    (error "expected truthy value, got falsy"))
  #t)

test/run

Source :96
(test/run . test-fns)
Run test functions, print a report, return {:passed :failed :total}.
View source definition
(define (test/run . test-fns)
  "Run test functions, print a report, return {:passed :failed :total}."
  (let* ((results (map run-one test-fns))
         (passed  (length (filter #(get % :passed) results)))
         (total   (length results))
         (failed  (- total passed)))
    (println "")
    (for-each print-result results)
    (println "")
    (if (= failed 0)
      (println (format "All ~a tests passed ✓" total))
      (println (format "~a/~a tests failed ✗" failed total)))
    {:passed passed :failed failed :total total}))

test/run!

Source :110
(test/run! . test-fns)
Run test functions and exit with code 1 if any fail.
View source definition
(define (test/run! . test-fns)
  "Run test functions and exit with code 1 if any fail."
  (let ((summary (apply test/run test-fns)))
    (when (> (get summary :failed) 0)
      (exit 1))
    summary)))
About this reference

Generated with sema-reader 1.37.0 without executing package code. These are source declarations; dynamic exports, aliases, and runtime changes are not inferred.

Archive SHA-256 01f807b672d56b94aedcf5d828415013bced59438e8e0a5c3abd1e117012d42b