racket / rackunit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to have rackunit render picts inside the "check-info stack"?

aymanosman opened this issue · comments

Screen Shot 2020-12-26 at 23 13 00

Problem

The "check-info stack" facility is unable to display visual data.

Motivation

While working on a graph algorithm, I found myself wanting to visualize the graphs I was computing. rackunit makes it convenient to associate extra information with a test case failure through the "check-info stack". I've always used that facility to associate textual data with my test cases, but now I found myself wanting to add visual data to that.

Workaround

Since I can only display text in test failures, I simply included the dot representation of the graph, like so:

Screen Shot 2020-12-27 at 14 31 33

It looks like rackunit is explicitly turning values into strings via info-value->string which isn't compatible with actually seeing certain values. For example, in this code, the first line prints "#(struct:object...." while the second shows the image.

#lang racket
(require 2htdp/image)
(displayln (~a (circle 50 "solid" "blue")))
(displayln (circle 50 "solid" "blue"))

picts need a bit more help; they have to be printed to show up. In this code, the first two show "#" and the last two show the picts themselves.

#lang racket
(require pict)
(write (circle 50))
(display (format "~a" (circle 50)))
(print (circle 50))
(printf "~v" (circle 50))

It would be good if rackunit would print the values so that they'd show up in uses like this one, at least.

#lang racket
(require pict rackunit)
(check-equal? (circle 50) (circle 40))

which currently prints as:

Welcome to DrRacket, version 7.9.0.17--2020-12-24(dd1061f0/d) [cs].
Language: racket, with debugging; memory limit: 128 MB.
--------------------
. FAILURE
name:       check-equal?
location:   unsaved-editor:3:0
actual:     #<pict>
expected:   #<pict>
--------------------

Thanks for the pointers @rfindler.

It looks like it wouldn't be too difficult to support this use case. Here are the results of some quick hacking:

Screen Shot 2020-12-27 at 18 44 37

All I did was change the check-info-stack->string function to print-check-info-stack and propogate those changes all the way.

It looks promising, if you'd be interested in a patch.