diff options
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp')
-rw-r--r-- | lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
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 |