(define var
(@@ (8sync agenda) var)))
-\f
-
-;;; Helpers
-;;; =======
-
-(define (speak-it)
- (let ((messages '()))
- (lambda* (#:optional message)
- (if message (set! messages (append messages (list message))))
- messages)))
-
\f
;;; queue helpers
;;; =============
;; the dummy test
-(define speaker (speak-it))
-
(define (dummy-func)
- (speaker "I'm a dummy\n"))
+ (speak "I'm a dummy\n"))
(define (run-dummy)
- (speaker "I bet I can make you say you're a dummy!\n")
+ (speak "I bet I can make you say you're a dummy!\n")
(run-it dummy-func))
-(begin
- (set! speaker (speak-it)) ; reset the speaker
- (start-agenda (make-agenda #:queue (make-q* run-dummy))
- #:stop-condition (true-after-n-times 2))
- (test-equal (speaker)
- '("I bet I can make you say you're a dummy!\n"
- "I'm a dummy\n")))
+(with-fresh-speaker
+ (start-agenda (make-agenda #:queue (make-q* run-dummy))
+ #:stop-condition (true-after-n-times 2))
+ (test-equal (get-spoken)
+ '("I bet I can make you say you're a dummy!\n"
+ "I'm a dummy\n")))
;; should only do the first one after one round though
-(begin
- (set! speaker (speak-it)) ; reset the speaker
- (start-agenda (make-agenda #:queue (make-q* run-dummy))
- #:stop-condition (true-after-n-times 1))
- (test-equal (speaker)
- '("I bet I can make you say you're a dummy!\n")))
+(with-fresh-speaker
+ (start-agenda (make-agenda #:queue (make-q* run-dummy))
+ #:stop-condition (true-after-n-times 1))
+ (test-equal (get-spoken)
+ '("I bet I can make you say you're a dummy!\n")))
;; End tests
(define-module (tests utils)
#:use-module (srfi srfi-64)
- #:export (test-exit))
+ #:export (test-exit
+
+ speak get-spoken with-fresh-speaker))
(define (test-exit)
(exit (= (test-runner-fail-count (test-runner-current)) 0)))
+
+
+\f
+
+;;; display-like helpers
+;;; ====================
+
+(define (speak-it)
+ (let ((messages '()))
+ (lambda* (#:optional message)
+ (if message (set! messages (append messages (list message))))
+ messages)))
+
+(define %speaker (make-parameter (speak-it)))
+
+(define (speak message)
+ "Speak a message into the %speaker parameter"
+ ((%speaker) message))
+
+(define (get-spoken)
+ "Get what's been spoken in the %speaker parameter"
+ ((%speaker)))
+
+(define-syntax-rule (with-fresh-speaker body ...)
+ "Run body with a fresh %speaker"
+ (parameterize ((%speaker (speak-it)))
+ body ...))