-(define (test-%run-and-friends async-request expected-when)
- (let* ((fake-kont (speak-it))
- (run-request ((@@ (eightsync agenda) setup-async-request)
- fake-kont async-request)))
- (test-equal (car async-request) '*async-request*)
- (test-equal (run-request-when run-request) expected-when)
- ;; we're using speaker as a fake continuation ;p
- ((run-request-proc run-request))
- (test-equal (fake-kont)
- '("applesauce"))))
-
-(test-%run-and-friends (%run (string-concatenate '("apple" "sauce")))
+(define-syntax-rule (run-in-fake-agenda
+ code-to-run)
+ (let ((agenda (make-agenda)))
+ (parameterize ((%current-agenda agenda))
+ (call-with-prompt
+ (agenda-prompt-tag agenda)
+ (lambda ()
+ (list '*normal-result* code-to-run))
+ (lambda (kont async-request)
+ (list '*caught-kont*
+ kont async-request
+ ((@@ (8sync agenda) setup-async-request)
+ kont async-request)))))))
+
+(define (test-%run-and-friends run-result expected-when)
+ (match run-result
+ (('*caught-kont* kont async-request setup-request)
+ (let* ((fake-kont (speak-it))
+ (run-request ((@@ (8sync agenda) setup-async-request)
+ fake-kont async-request)))
+ (test-equal (car async-request) '*async-request*)
+ (test-equal (run-request-when run-request) expected-when)
+ ;; we're using speaker as a fake continuation ;p
+ ((run-request-proc run-request))
+ (test-equal (fake-kont)
+ '("applesauce"))))))
+
+(test-%run-and-friends (run-in-fake-agenda
+ (%8sync (string-concatenate '("apple" "sauce"))))