Validating Files Submitted by Students

Note: Performing filtering in this fashion is no longer recommended. The BitterSuiteFilter language should be used instead. This page will just remain as an illustration of how to write an external-command script, nothing more.

This is the kind of check normally done better by a submission filter; however, systems like Marmoset and MarkUs currently have no such filtering option. So, the following script targetting Scheme files with non-textual elements can try to give meaningful error messages early in the test output that can try to explain more mystifying failures later.

The following code can be used in a test.exe file in (language external). The arguments passed to it via (args ...) should be all of the files being expected for the current assignment with the extension (.ss or .scm) omitted. For example, (args temp quadratic area grades mpg).

#!/usr/bin/env bash

# Since we won't make use of standard output for diff testing,
# start the script by re-executing self with standard input
# directed to fd4.  This way, we don't have to write to it below
# explicitly.
if [ -z "$SOMEREALLYUNUSUALENVVAR" ]; then
   export SOMEREALLYUNUSUALENVVAR=boogedy
   exec "$0" "$@" 1>&4
fi

if [[ $# -eq 0 ]]; then
   echo "$(basename $0) requires at least one command-line argument" >&2
   exit 1
fi

notexistcounter=0
wxmecounter=0

# Find out what expected files have been submitted; out of those,
# check if any appear to be in WXME format.
for filenamebase in "$@"; do
   if [ -e "$submitdir/$filenamebase.ss" ]; then
      filename="$submitdir/$filenamebase.ss"
   elif [ -e "$submitdir/$filenamebase.scm" ]; then
      filename="$submitdir/$filenamebase.scm"
   else
      notexist[$notexistcounter]="$filenamebase.ss"
      (( notexistcounter++ ))
      continue
   fi

   if head -n 1 "$filename" | grep WXME >/dev/null 2>&1; then
      wxme[$wxmecounter]=$(basename "$filename")
      (( wxmecounter++ ))
   fi
done


# Now output status information about any problem files.
noerrors=true

if [[ $notexistcounter -gt 0 ]]; then
   noerrors=false
   echo -n 'The following files were not submitted:'
   i=0
   while [[ $i -lt $notexistcounter ]]; do
      echo -n " ${notexist[$i]}"
      (( i++ ))
   done
   echo -n '.  '
fi

if [[ $wxmecounter -gt 0 ]]; then
   noerrors=false
   echo -n 'The following files appear to be in a special PLT Scheme format'
   echo -n ' which contains representations of non-textual elements:'
   i=0
   while [[ $i -lt $wxmecounter ]]; do
      echo -n " ${wxme[$i]}"
      (( i++ ))
   done
   echo -n '.  Common causes include (but are not limited to): '
   echo -n '* copying from the interactions window to the definitions window '
   echo -n '* commenting out sections of code with boxes '
   echo -n '* adding elements using the Insert menu.  '
   echo -n 'Please fix and submit again.  Contact a tutor if you need assistance.  '
fi

if $noerrors; then
   echo -n 'All files appear to be submitted in a valid format.'
fi

# Give a newline to be nice.
echo

echo "$(( ($# - notexistcounter - wxmecounter) * 100 ))/$#" >&3
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2010-08-18 - 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