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