Sto costruendo un set di test di unità rack, in cui la funzione effettiva test-case
e check-equal?
è definita in una macro. Il codice simile a questa:RackUna posizione di origine all'interno di macro
#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)
Tuttavia, quando si esegue questo codice ottengo il seguente output:
--------------------
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
Dove la linea 11 è la linea della funzione check-equal?
all'interno della macro: (check-equal? case1 case2)))]))
C'è un modo in cui posso rackunit per mostrare l'errore sulla linea in cui viene utilizzato my-test=?
: (my-test=? 'a 'b)))
?
Sì, questo [mi ha fatto inciampare prima] (http://www.greghendershott.com/2014/01/using-syntax-loc.html). Si scopre che la frase "oggetto di sintassi immediata" nella documentazione è significativa! –