我正在构建一组rackunit测试,其中实际的test-case和check-equal?函数是在宏中定义的。代码如下所示:
#lang racket
(require rackunit
rackunit/text-ui)
(define-syntax (my-test=? stx)
(syntax-case stx ()
[(_ case1 case2)
(syntax/loc stx
(test-case "tests"
(check-equal? case1 case2)))]))
(define tests
(test-suite "tests"
(my-test=? 'a 'b)))
(run-tests tests)但是,当我运行这段代码时,我得到了以下输出:
--------------------
tests > tests
tests
FAILURE
name: check-equal?
location: unsaved-editor:11:9
actual: 'a
expected: 'b
. Check failure
--------------------
0 success(es) 1 failure(s) 0 error(s) 1 test(s) run其中第11行是宏内的check-equal?函数行:(check-equal? case1 case2)))]))
有什么方法可以在使用my-test=?的行上显示错误:(my-test=? 'a 'b)))?
发布于 2015-08-26 19:33:09
您可以将语法位置直接放在check-equal?表达式上,以获得所需的行为。下面是一个例子:
(define-syntax (my-test=? stx)
(syntax-case stx ()
[(_ case1 case2)
(quasisyntax
(test-case "tests"
#,(syntax/loc stx (check-equal? case1 case2))))]))通常,将语法位置放在外部表达式上并不会自动传播。
通过此更改,我将位置报告为"15:4“(相对于"11:9"),而”11:9“是(my-test=? 'a 'b)表达式出现的地方。
https://stackoverflow.com/questions/32233757
复制相似问题