| 1 | n/a | # Tests that the crashers in the Lib/test/crashers directory actually |
|---|
| 2 | n/a | # do crash the interpreter as expected |
|---|
| 3 | n/a | # |
|---|
| 4 | n/a | # If a crasher is fixed, it should be moved elsewhere in the test suite to |
|---|
| 5 | n/a | # ensure it continues to work correctly. |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | import unittest |
|---|
| 8 | n/a | import glob |
|---|
| 9 | n/a | import os.path |
|---|
| 10 | n/a | import test.support |
|---|
| 11 | n/a | from test.support.script_helper import assert_python_failure |
|---|
| 12 | n/a | |
|---|
| 13 | n/a | CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers") |
|---|
| 14 | n/a | CRASHER_FILES = os.path.join(CRASHER_DIR, "*.py") |
|---|
| 15 | n/a | |
|---|
| 16 | n/a | infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"] |
|---|
| 17 | n/a | |
|---|
| 18 | n/a | class CrasherTest(unittest.TestCase): |
|---|
| 19 | n/a | |
|---|
| 20 | n/a | @unittest.skip("these tests are too fragile") |
|---|
| 21 | n/a | @test.support.cpython_only |
|---|
| 22 | n/a | def test_crashers_crash(self): |
|---|
| 23 | n/a | for fname in glob.glob(CRASHER_FILES): |
|---|
| 24 | n/a | if os.path.basename(fname) in infinite_loops: |
|---|
| 25 | n/a | continue |
|---|
| 26 | n/a | # Some "crashers" only trigger an exception rather than a |
|---|
| 27 | n/a | # segfault. Consider that an acceptable outcome. |
|---|
| 28 | n/a | if test.support.verbose: |
|---|
| 29 | n/a | print("Checking crasher:", fname) |
|---|
| 30 | n/a | assert_python_failure(fname) |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | |
|---|
| 33 | n/a | def tearDownModule(): |
|---|
| 34 | n/a | test.support.reap_children() |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | if __name__ == "__main__": |
|---|
| 37 | n/a | unittest.main() |
|---|