#!/usr/bin/env python # -*-Python-*- # This is a simple script that takes a sequence of command-line arguments # that are names of test input files, and for each value F.trk in this # sequence, runs # java tracker.Main F.trk F.out # Then if F is a file whose name begins with 'bad', the script checks that # it exits with a nonzero exit code and prints an error message in the proper # form. Otherwise, it runs # diff -b F.std F.out # to check for the right output. It counts up and reports the number of # failures and successes. # # Feel free to adapt it to your needs. import sys, os, re count = fail = 0 for test in sys.argv[1:]: base = os.path.splitext(test)[0] name = os.path.basename(base) count += 1 if re.match (r'bad', name): if os.system("java tracker.Main %s %s.out /dev/null 2>ERRS" % (test, base)) == 0: print "%s: FAILED (no error)" % name fail += 1 elif os.system("grep -i 'error' ERRS >/dev/null") != 0: print "%s: FAILED (no error message)" % name continue if os.system("java tracker.Main %s %s.out /dev/null 2>&1" % (test, base)) != 0: print "%s: FAILED (execution)" % name fail += 1 continue if os.system("diff -b %s.std %s.out >/dev/null" % (base, base)) == 0: print "%s: OK" % name else: print "%s: FAILED (output)" % name fail += 1 if fail == 0: print "Passed all %d tests." % (count,) else: print "Failed %d out of %d tests." % (fail, count) sys.exit(1)