[racket] testing student programs

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Sat Oct 16 14:16:29 EDT 2010

I know this has come up on the list before, and I've reread those
threads but am little confused.

Here's a sample student program file:
; volume-of-solid: number number number -> number
; given the length, width, and height of a rectangular prism,
;   produces the volume
(define (volume-of-solid length width height)
 (* length width height))

(check-expect (volume-of-solid 2 3 4) 24)
(check-expect (volume-of-solid 3 5 7) 105)

I'd like to test this file with something like:
#lang racket

(define score 0)

(when (= (volume-of-solid 3 4 5) 60)
  (set! score (add1 score)))

(when (= (volume-of-solid 10 5 4) 200)
  (set! score (add1 score)))
but I can't figure out how to do it safely.

It seems like if I use make-module-evaluator, I'm stuck in the context
of the original student program--that is, Beginning Student Language,
without the ability to accumulate a score or use constructs that
aren't defined in BSL. If I provide the student functions in full
Racket, I don't get the safety of the sandbox, and the student code
could do something not nice to my test system.

Obviously, there's a place here for a really nice macro-based testing
harness that checks for errors in each student function call, lets you
assign points for each test, etc., but I have to figure out how to get
the definitions I want to test safely into a context that lets me
write the code to evaluate them.

Thanks in advance,

Posted on the users mailing list.