From a87d0ae61b42e06e0b86ac114e3613a9976d2ca0 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 13 Nov 2015 01:50:19 +0000 Subject: Fix a bug in PythonExceptionState and add unittest coverage. I forgot to reset the restore flag when calling member function `Acquire`. The newly added unittest should cover this case. llvm-svn: 253002 --- .../Python/PythonExceptionStateTests.cpp | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp') diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp index 3d7941e..a0a6f98 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp @@ -79,6 +79,33 @@ TEST_F(PythonExceptionStateTest, TestDiscardSemantics) EXPECT_FALSE(PythonExceptionState::HasErrorOccurred()); } +TEST_F(PythonExceptionStateTest, TestResetSemantics) +{ + PyErr_Clear(); + + // Resetting when auto-restore is true should restore. + RaiseException(); + PythonExceptionState error(true); + EXPECT_TRUE(error.IsError()); + EXPECT_FALSE(PythonExceptionState::HasErrorOccurred()); + error.Reset(); + EXPECT_FALSE(error.IsError()); + EXPECT_TRUE(PythonExceptionState::HasErrorOccurred()); + + PyErr_Clear(); + + // Resetting when auto-restore is false should discard. + RaiseException(); + PythonExceptionState error2(false); + EXPECT_TRUE(error2.IsError()); + EXPECT_FALSE(PythonExceptionState::HasErrorOccurred()); + error2.Reset(); + EXPECT_FALSE(error2.IsError()); + EXPECT_FALSE(PythonExceptionState::HasErrorOccurred()); + + PyErr_Clear(); +} + TEST_F(PythonExceptionStateTest, TestManualRestoreSemantics) { PyErr_Clear(); @@ -119,3 +146,29 @@ TEST_F(PythonExceptionStateTest, TestAutoRestoreSemantics) PyErr_Clear(); } + +TEST_F(PythonExceptionStateTest, TestAutoRestoreChanged) +{ + // Test that if we re-acquire with different auto-restore semantics, + // that the new semantics are respected. + PyErr_Clear(); + + RaiseException(); + PythonExceptionState error(false); + EXPECT_TRUE(error.IsError()); + + error.Reset(); + EXPECT_FALSE(error.IsError()); + EXPECT_FALSE(PythonExceptionState::HasErrorOccurred()); + + RaiseException(); + error.Acquire(true); + EXPECT_TRUE(error.IsError()); + EXPECT_FALSE(PythonExceptionState::HasErrorOccurred()); + + error.Reset(); + EXPECT_FALSE(error.IsError()); + EXPECT_TRUE(PythonExceptionState::HasErrorOccurred()); + + PyErr_Clear(); +} \ No newline at end of file -- cgit v1.1