From cc02533b2f1ed4d7057e8c47c8d2edd96cb880fe Mon Sep 17 00:00:00 2001 From: Andrey Maltsev Date: Sun, 2 Apr 2023 13:19:49 +0000 Subject: [PATCH] Update test_crashers from Cpython v3.11.2 --- Lib/test/test_crashers.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Lib/test/test_crashers.py diff --git a/Lib/test/test_crashers.py b/Lib/test/test_crashers.py new file mode 100644 index 00000000000..31b712028f8 --- /dev/null +++ b/Lib/test/test_crashers.py @@ -0,0 +1,37 @@ +# Tests that the crashers in the Lib/test/crashers directory actually +# do crash the interpreter as expected +# +# If a crasher is fixed, it should be moved elsewhere in the test suite to +# ensure it continues to work correctly. + +import unittest +import glob +import os.path +import test.support +from test.support.script_helper import assert_python_failure + +CRASHER_DIR = os.path.join(os.path.dirname(__file__), "crashers") +CRASHER_FILES = os.path.join(glob.escape(CRASHER_DIR), "*.py") + +infinite_loops = ["infinite_loop_re.py", "nasty_eq_vs_dict.py"] + +class CrasherTest(unittest.TestCase): + + @unittest.skip("these tests are too fragile") + @test.support.cpython_only + def test_crashers_crash(self): + for fname in glob.glob(CRASHER_FILES): + if os.path.basename(fname) in infinite_loops: + continue + # Some "crashers" only trigger an exception rather than a + # segfault. Consider that an acceptable outcome. + if test.support.verbose: + print("Checking crasher:", fname) + assert_python_failure(fname) + + +def tearDownModule(): + test.support.reap_children() + +if __name__ == "__main__": + unittest.main()