Improve assert library
This commit is contained in:
parent
f0a97e1ba4
commit
ef3d49653d
|
|
@ -1,15 +1,4 @@
|
|||
(define-syntax assert
|
||||
(syntax-rules ()
|
||||
((_ check body)
|
||||
(let ((result body))
|
||||
(when (not (check result))
|
||||
(error "assertion error: " check body result))
|
||||
result))))
|
||||
|
||||
(define-syntax asserts
|
||||
(syntax-rules ()
|
||||
((_ (check ...) body)
|
||||
(let ((result body))
|
||||
(when (not (check result)) (error "assertion error: " check body result)) ...
|
||||
result))))
|
||||
|
||||
((_ check val err-msg)
|
||||
(unless (check val) (error err-msg val)))))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
;; SPDX-License-Identifier: LGPL
|
||||
;; VERSION: 0.1.0
|
||||
;; DESCRIPTION: Assert
|
||||
;; ADDITIONAL_LIBRARIES: retropikzel/assert/pass.sld
|
||||
|
||||
(define-library
|
||||
(retropikzel assert)
|
||||
(import (scheme base)
|
||||
(scheme write))
|
||||
(export assert
|
||||
asserts)
|
||||
(import (scheme base))
|
||||
(export assert)
|
||||
(include "assert.scm"))
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
LGPL
|
||||
|
|
@ -0,0 +1 @@
|
|||
(define-syntax assert (syntax-rules () ((_ check val err-msg) #t)))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
;; SPDX-License-Identifier: LGPL
|
||||
;; VERSION: 0.1.0
|
||||
;; DESCRIPTION: Assert passtrough
|
||||
|
||||
(define-library
|
||||
(retropikzel assert pass)
|
||||
(import (scheme base))
|
||||
(export assert)
|
||||
(include "pass.scm"))
|
||||
|
|
@ -10,12 +10,17 @@
|
|||
|
||||
(test-begin "assert")
|
||||
|
||||
(test-equal 1 (assert number? 1))
|
||||
(define (plus a b)
|
||||
(assert integer? a "a must be integer")
|
||||
(assert integer? b "b must be integer")
|
||||
(+ a b))
|
||||
|
||||
(write (plus 5 5))
|
||||
(newline)
|
||||
(test-equal 10 (plus 5 5))
|
||||
|
||||
(test-equal 'error
|
||||
(guard (condition (else 'error))
|
||||
(assert number? "string")))
|
||||
|
||||
(test-equal 1 (asserts (number? (lambda (i) (= i 1))) 1))
|
||||
(plus 5 'a)))
|
||||
|
||||
(test-end "assert")
|
||||
|
|
|
|||
Loading…
Reference in New Issue