我想通过一个测试语法异常的宏来扩展 srfi-78。我想要这样的东西:
#! /usr/bin/env scheme-script
#!r6rs
(import (rnrs) (srfi :78 lightweight-testing))
; the macros I want to test
(define-syntax some-macros
(syntax-rules ()
[(_) 'ok]))
; the extension to srfi-78
(define-syntax check-exception
(syntax-rules ()
; ... some code ...
))
; tests
; prints "correct" or someting like that
(check (some-macros) => 'ok)
; should print "correct" (i. e. the test passed)
(check-exception (some-macros 'arg))
; should print "error"
; (i. e. the exception was not thrown as expected)
(check-exception (some-macros))
有可能吗?如果不是,您将如何为宏编写测试?
我test-read-eval-string
从 srfi-64 得知。它接受一个字符串,将其转换为一个表单并在初始环境中评估该表单。我想要一个在当前环境中评估给定形式并捕获异常的宏。