From: Christopher Allan Webber Date: Mon, 2 Jan 2017 17:34:13 +0000 (-0600) Subject: tests: Add "speaker" utility. X-Git-Tag: v0.4.0~38 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=f0863bf36133288ed55eb97a3732d581be45c231;p=8sync.git tests: Add "speaker" utility. * tests/utils.scm (speak-it, %speaker, speak, get-spoken, with-fresh-speaker): New variables. * tests/test-agenda.scm (speak-it): Remove in favor of new speaker from utils.scm. Update to use new speaker. --- diff --git a/tests/test-agenda.scm b/tests/test-agenda.scm index 013bce7..ae53e55 100644 --- a/tests/test-agenda.scm +++ b/tests/test-agenda.scm @@ -30,17 +30,6 @@ (define var (@@ (8sync agenda) var))) - - -;;; Helpers -;;; ======= - -(define (speak-it) - (let ((messages '())) - (lambda* (#:optional message) - (if message (set! messages (append messages (list message)))) - messages))) - ;;; queue helpers ;;; ============= @@ -270,30 +259,26 @@ ;; 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 diff --git a/tests/utils.scm b/tests/utils.scm index 5d4e3cf..e20b5b8 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -20,7 +20,36 @@ (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))) + + + + +;;; 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 ...))