blob: bc2dd701a80ba56ba6b8dbae6bf7ea28e6a9d80d [file] [log] [blame]
Jeremy Hylton4336eda2004-08-07 19:25:33 +00001import compiler
2import os
3import test.test_support
4import unittest
5
6class CompilerTest(unittest.TestCase):
7
8 def testCompileLibrary(self):
9 # A simple but large test. Compile all the code in the
10 # standard library and its test suite. This doesn't verify
11 # that any of the code is correct, merely the compiler is able
12 # to generate some kind of code for it.
13
14 libdir = os.path.dirname(unittest.__file__)
15 testdir = os.path.dirname(test.test_support.__file__)
16
17 for dir in [libdir, testdir]:
Tim Peters2a5f6562004-08-08 16:37:37 +000018 for basename in os.listdir(dir):
19 if not basename.endswith(".py"):
Jeremy Hylton4336eda2004-08-07 19:25:33 +000020 continue
Tim Peters2a5f6562004-08-08 16:37:37 +000021 path = os.path.join(dir, basename)
Tim Petersb6ecc162004-08-08 16:32:54 +000022 if test.test_support.verbose:
Tim Peters2a5f6562004-08-08 16:37:37 +000023 print "compiling", path
24 f = open(path)
Jeremy Hylton4336eda2004-08-07 19:25:33 +000025 buf = f.read()
26 f.close()
Tim Peters0955f292004-08-08 16:43:59 +000027 if "badsyntax" in basename:
28 self.assertRaises(SyntaxError, compiler.compile,
29 buf, basename, "exec")
30 else:
31 compiler.compile(buf, basename, "exec")
Jeremy Hylton4336eda2004-08-07 19:25:33 +000032
33def test_main():
34 test.test_support.requires("compiler")
35 test.test_support.run_unittest(CompilerTest)
36
37if __name__ == "__main__":
38 test_main()