aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-11-13 01:50:19 +0000
committerZachary Turner <zturner@google.com>2015-11-13 01:50:19 +0000
commita87d0ae61b42e06e0b86ac114e3613a9976d2ca0 (patch)
tree57b2eb465a22b565a9c55ea4909f529f50aadd05 /lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp
parent2cab8eec7423e8608f877a98b2a6879dd4fb5b6c (diff)
downloadllvm-a87d0ae61b42e06e0b86ac114e3613a9976d2ca0.zip
llvm-a87d0ae61b42e06e0b86ac114e3613a9976d2ca0.tar.gz
llvm-a87d0ae61b42e06e0b86ac114e3613a9976d2ca0.tar.bz2
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
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp')
-rw-r--r--lldb/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp53
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