Location of RackUnit Source Inside Macros

I am creating a rack test suite, where are the actual test-case and check-equal? the function is defined in the macro. The code looks something like this:

 #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) 

However, when I run this code, I get the following 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 

If line 11 is a check-equal? function line check-equal? inside the macro: (check-equal? case1 case2)))]))

Is there a way that I can show an error in a line where my-test=? : (my-test=? 'a 'b))) ?

+7
macros racket rackunit
source share
1 answer

Can you put the syntax location directly in the check-equal? expression check-equal? to get the right behavior. Here is an example:

 (define-syntax (my-test=? stx) (syntax-case stx () [(_ case1 case2) (quasisyntax (test-case "tests" #,(syntax/loc stx (check-equal? case1 case2))))])) 

Placing syntax in an external expression does not automatically propagate as a whole.

With this change, the location is indicated as “15: 4” for me (as opposed to “11: 9”), where the expression (my-test=? 'a 'b) is encountered.

+6
source share

All Articles