1 #!/usr/bin/env python 2 3 import micropython.cmd 4 import rsvp 5 import sys 6 import os 7 from glob import glob 8 import operator 9 10 # Main program. 11 12 if __name__ == "__main__": 13 args = sys.argv[1:] 14 path = sys.path[:] 15 path.append("tests") 16 17 # Process all tests. 18 19 try: 20 _f = args.index("-f") 21 filenames = args[_f+1:] 22 except ValueError: 23 filenames = glob(os.path.join("tests", "*.py")) 24 25 filenames.sort() 26 27 results = [] 28 29 for filename in filenames: 30 print "Processing", filename 31 32 try: 33 p = micropython.cmd.get_program(path, args) 34 m = p.get_importer().load_from_file(filename) 35 36 # Report any errors. 37 38 except micropython.ProcessingError, exc: 39 print repr(exc) 40 if "-tb" in args: 41 raise 42 43 else: 44 rm = rsvp.machine(p) 45 success = rm.test(m) 46 print "Test successful?", success 47 results.append((filename, success)) 48 49 print 50 print "Failed tests:" 51 for result in results: 52 if not result[1]: 53 print result[0] 54 55 print 56 print "All successful?" 57 print reduce(operator.and_, [x[1] for x in results], 1) and "Yes" or "No" 58 59 # vim: tabstop=4 expandtab shiftwidth=4