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