Guido van Rossum | f06ee5f | 1996-11-27 19:52:01 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | 16d27e3 | 1996-08-21 16:28:53 +0000 | [diff] [blame] | 2 | # (Force the script to use the latest build.) |
| 3 | # |
| 4 | # test_parser.py |
| 5 | |
| 6 | import parser, traceback |
| 7 | |
| 8 | _numFailed = 0 |
| 9 | |
| 10 | def testChunk(t, fileName): |
| 11 | global _numFailed |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 12 | print('----', fileName, end=' ') |
Guido van Rossum | 16d27e3 | 1996-08-21 16:28:53 +0000 | [diff] [blame] | 13 | try: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 14 | ast = parser.suite(t) |
| 15 | tup = parser.ast2tuple(ast) |
| 16 | # this discards the first AST; a huge memory savings when running |
| 17 | # against a large source file like Tkinter.py. |
| 18 | ast = None |
| 19 | new = parser.tuple2ast(tup) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 20 | except parser.ParserError as err: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 21 | print() |
| 22 | print('parser module raised exception on input file', fileName + ':') |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 23 | traceback.print_exc() |
| 24 | _numFailed = _numFailed + 1 |
Guido van Rossum | 16d27e3 | 1996-08-21 16:28:53 +0000 | [diff] [blame] | 25 | else: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 26 | if tup != parser.ast2tuple(new): |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 27 | print() |
| 28 | print('parser module failed on input file', fileName) |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 29 | _numFailed = _numFailed + 1 |
| 30 | else: |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 31 | print('o.k.') |
Guido van Rossum | 16d27e3 | 1996-08-21 16:28:53 +0000 | [diff] [blame] | 32 | |
| 33 | def testFile(fileName): |
| 34 | t = open(fileName).read() |
| 35 | testChunk(t, fileName) |
| 36 | |
| 37 | def test(): |
| 38 | import sys |
| 39 | args = sys.argv[1:] |
| 40 | if not args: |
Guido van Rossum | 4117e54 | 1998-09-14 16:44:15 +0000 | [diff] [blame] | 41 | import glob |
| 42 | args = glob.glob("*.py") |
Fred Drake | 6baec62 | 2000-08-23 20:21:31 +0000 | [diff] [blame] | 43 | args.sort() |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 44 | list(map(testFile, args)) |
Guido van Rossum | 16d27e3 | 1996-08-21 16:28:53 +0000 | [diff] [blame] | 45 | sys.exit(_numFailed != 0) |
| 46 | |
| 47 | if __name__ == '__main__': |
| 48 | test() |