blob: e4d557103eb4d927e78aa8e376d3bf829b93087a [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossum16d27e31996-08-21 16:28:53 +00002# (Force the script to use the latest build.)
3#
4# test_parser.py
5
6import parser, traceback
7
8_numFailed = 0
9
10def testChunk(t, fileName):
11 global _numFailed
Collin Winter6f2df4d2007-07-17 20:59:35 +000012 print('----', fileName, end=' ')
Guido van Rossum16d27e31996-08-21 16:28:53 +000013 try:
Guido van Rossum4117e541998-09-14 16:44:15 +000014 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 Rossumb940e112007-01-10 16:19:56 +000020 except parser.ParserError as err:
Collin Winter6f2df4d2007-07-17 20:59:35 +000021 print()
22 print('parser module raised exception on input file', fileName + ':')
Guido van Rossum4117e541998-09-14 16:44:15 +000023 traceback.print_exc()
24 _numFailed = _numFailed + 1
Guido van Rossum16d27e31996-08-21 16:28:53 +000025 else:
Guido van Rossum4117e541998-09-14 16:44:15 +000026 if tup != parser.ast2tuple(new):
Collin Winter6f2df4d2007-07-17 20:59:35 +000027 print()
28 print('parser module failed on input file', fileName)
Guido van Rossum4117e541998-09-14 16:44:15 +000029 _numFailed = _numFailed + 1
30 else:
Collin Winter6f2df4d2007-07-17 20:59:35 +000031 print('o.k.')
Guido van Rossum16d27e31996-08-21 16:28:53 +000032
33def testFile(fileName):
34 t = open(fileName).read()
35 testChunk(t, fileName)
36
37def test():
38 import sys
39 args = sys.argv[1:]
40 if not args:
Guido van Rossum4117e541998-09-14 16:44:15 +000041 import glob
42 args = glob.glob("*.py")
Fred Drake6baec622000-08-23 20:21:31 +000043 args.sort()
Collin Winter6f2df4d2007-07-17 20:59:35 +000044 list(map(testFile, args))
Guido van Rossum16d27e31996-08-21 16:28:53 +000045 sys.exit(_numFailed != 0)
46
47if __name__ == '__main__':
48 test()