BitterSuite: Filtering student code prior to execution

Warning: This has not yet been tested in BitterSuite 3. This needs to be tested, modified as needed, and verified to a reasonably strong degree that this works correctly before this warning is removed.

NB: The following code assumes that the submission was made in a teaching language, and will not work on submissions in the module language as written.

Create a file called runTests-preprocess in the root of the testing directory (i.e. at the same level as in and provided). Make sure this file is executable (e.g. by using chmod +x runTests-preprocess), and put the following code in it:


filter_code="mzscheme -u"

if [ -e "$" ]; then
        echo "filtering $"
        $mangle < $ | $filter_code > $
elif [ -e "$filter_filename.scm" ]; then
        echo "filtering $filter_filename.scm..."
        $mangle < $filter_filename.scm | $filter_code > $filter_filename.filt.scm
        echo "$ not found: no filtering performed"

# don't let errors from this script stop runTests
exit 0

Change aXqY to the file to be filtered. If you need to filter more than one file, put this script in provided/ and make runTests-preprocess call it for each file which should be filtered. This is left as an exercise for the reader.

In the file provided/, put this code:

#lang scheme

(define (do-read)
  (define cur-read
      (with-handlers ((void (lambda (exn)
                              (begin (fprintf (current-error-port) "read error: ~a\n" (exn-message exn))
    [(eof-object? cur-read) (void)]
    [(void? cur-read) (do-read)]
    [.1. .2. (do-read)]
    [else (write cur-read)


or, equivalently but without repeating the explicit calls to (do-read),

#lang scheme

(let do-read ()
  (let ([cur-read
         (with-handlers ((void (lambda (exn)
                                 (begin (fprintf (current-error-port) 
                                                 "read error: ~a\n" 
                                                 (exn-message exn))
    (unless (eof-object? cur-read)
      (unless (void? cur-read)
          [.1. .2.]
          [else (write cur-read)]))

The ".1." in the above script should be replaced by the filtering condition, and the ".2" should be replaced by the filtering you want to perform. There can also be as many filtering conditions as you want in succession in this cond. For example, if we want to strip out all instances of the statement (define-struct foo ...) we can use the code

    [(and (list? cur-read)
          (>= (length cur-read) 2)
          (equal? (first cur-read) 'define-struct)
          (equal? (second cur-read) 'foo))
with the S-expression starting with and replacing ".1." and (void) replacing ".2." since we simply want to drop this expression instead of transforming it into something else. This will remove any (define-struct foo ...) S-expressions from the student's code while leaving everything else intact.

Now, instead of using (loadcode "") in, you can use (loadcode "") to load the filtered code. Note that the language must be one of the teaching languages explicitly. In beginning student, for example, this would require a (language scheme/beginner) context or for the loadcode to be modified to (loadcode beginner "").

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2010-02-16 - TerryVaskor
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback