On Tue, Apr 2, 2019 at 1:04 PM Tom Gillespie <tgb...@gmail.com> wrote:
>
> Are you using emacs racket-mode?

I am, almost exclusively. Exception and check failure locations can be a
pain, but they work in general.

> On Tue, Apr 2, 2019 at 3:41 PM zeRusski <vladilen.ko...@gmail.com> wrote:
>>
>> If I have many test chunks spread around my code and some code change
throws an exception or a contract violation it is impossible to tell which
test triggered it. The only thing in the context is (submod "file.rkt"
test):1:1.

Let's make this concrete. If I create a /tmp/somefile.rkt in Emacs:

#lang racket/base
(define f (λ _ (error 'FAIL)))
(module+ test
  (require rackunit)
  (define OK (string->unreadable-symbol "OK"))
  (define-simple-check (check-OK val)
    (eq? val OK))
  (check-OK OK)
  (check-OK #f)
  (check-OK (f)))

and hit C-c C-c with my cursor inside the test sub-module, it prints this
in my Racket REPL:

--------------------
; FAILURE
; /tmp/somefile.rkt:9:2
name:       check-OK
location:   somefile.rkt:9:2
params:     '(#f)
--------------------
; error: FAIL
; Context:
;  (submod "/tmp/somefile.rkt" test):1:1 [running body]

The first check succeeds silently.

The second check fails because #f is not OK. The location is accurate and
automatically linked to the source.

The third check is never invoked. While evaluating the argument, f throws
an exception and the REPL gives no useful context. I think you're asking
specifically about this case. If the error is in the code being tested and
not in the test itself, I'd want to know where the exception was raised.

In Emacs, hitting C-u C-c C-c inside the test sub-module exposes the
context I'm looking for:

; ...
--------------------
; error: FAIL
; Context (errortrace):
;    /tmp/somefile.rkt:2:15: (error (quote FAIL))
; ...

If I'm generating tests with macros, getting the source locations right can
be a hassle. Sometimes, it's easier to just add with-check-info:

#lang racket/base
(define f (λ _ (error 'FAIL)))
(module+ test
  (require rackunit)
  (define OK (string->unreadable-symbol "OK"))
  (define-syntax-rule (check-OK-form expr)
    (let ([val expr])
      (with-check-info (['input 'expr] ['expected OK] ['actual val])
        (check eq? val OK))))
  (check-OK-form OK)
  (check-OK-form (values #f))
  (check-OK-form (f)))

Even without a C-u prefix, the input can help locate the offending check:

--------------------
; FAILURE
; /tmp/somefile.rkt:9:8
input:      (values #f)
expected:   OK
actual:     #f
name:       check
location:   somefile.rkt:9:8
--------------------
; error: FAIL
; Context:
;  (submod "/tmp/somefile.rkt" test):1:1 [running body]

Most of the time, this is enough for me and I have a habit of polishing
cannon balls.

Eric

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to