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
This commit is contained in:
Zachary Turner
2015-11-13 01:50:19 +00:00
parent 2cab8eec74
commit a87d0ae61b
3 changed files with 66 additions and 0 deletions

View File

@@ -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();
}