forked from qt-creator/qt-creator
AutoTest: Correct states handling when parsing boost tests
Do not miss to reset the parser state after a macro for a test case or suite has been handled. In case of an early return (usually when having incomplete or incorrect code) the wrong state may be taken into account otherwise. Change-Id: I2a981db9166fc6a21c2590406768ecaeee2852f2 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -98,31 +98,43 @@ void BoostCodeParser::handleIdentifier()
|
|||||||
|
|
||||||
if (identifier == "BOOST_AUTO_TEST_SUITE") {
|
if (identifier == "BOOST_AUTO_TEST_SUITE") {
|
||||||
handleSuiteBegin(false);
|
handleSuiteBegin(false);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_FIXTURE_TEST_SUITE") {
|
} else if (identifier == "BOOST_FIXTURE_TEST_SUITE") {
|
||||||
handleSuiteBegin(true);
|
handleSuiteBegin(true);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_AUTO_TEST_SUITE_END") {
|
} else if (identifier == "BOOST_AUTO_TEST_SUITE_END") {
|
||||||
handleSuiteEnd();
|
handleSuiteEnd();
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_TEST_CASE") {
|
} else if (identifier == "BOOST_TEST_CASE") {
|
||||||
handleTestCase(TestCaseType::Functions);
|
handleTestCase(TestCaseType::Functions);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_PARAM_TEST_CASE") {
|
} else if (identifier == "BOOST_PARAM_TEST_CASE") {
|
||||||
m_currentState.setFlag(BoostTestTreeItem::Parameterized);
|
m_currentState.setFlag(BoostTestTreeItem::Parameterized);
|
||||||
handleTestCase(TestCaseType::Parameter);
|
handleTestCase(TestCaseType::Parameter);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_AUTO_TEST_CASE") {
|
} else if (identifier == "BOOST_AUTO_TEST_CASE") {
|
||||||
handleTestCase(TestCaseType::Auto);
|
handleTestCase(TestCaseType::Auto);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_FIXTURE_TEST_CASE") {
|
} else if (identifier == "BOOST_FIXTURE_TEST_CASE") {
|
||||||
|
m_currentState.setFlag(BoostTestTreeItem::Fixture);
|
||||||
handleTestCase(TestCaseType::Fixture);
|
handleTestCase(TestCaseType::Fixture);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_DATA_TEST_CASE") {
|
} else if (identifier == "BOOST_DATA_TEST_CASE") {
|
||||||
handleTestCase(TestCaseType::Data);
|
handleTestCase(TestCaseType::Data);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_DATA_TEST_CASE_F") {
|
} else if (identifier == "BOOST_DATA_TEST_CASE_F") {
|
||||||
m_currentState.setFlag(BoostTestTreeItem::Fixture);
|
m_currentState.setFlag(BoostTestTreeItem::Fixture);
|
||||||
handleTestCase(TestCaseType::Data);
|
handleTestCase(TestCaseType::Data);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_AUTO_TEST_CASE_TEMPLATE") {
|
} else if (identifier == "BOOST_AUTO_TEST_CASE_TEMPLATE") {
|
||||||
m_currentState.setFlag(BoostTestTreeItem::Templated);
|
m_currentState.setFlag(BoostTestTreeItem::Templated);
|
||||||
handleTestCase(TestCaseType::Auto);
|
handleTestCase(TestCaseType::Auto);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_FIXTURE_TEST_CASE_TEMPLATE") {
|
} else if (identifier == "BOOST_FIXTURE_TEST_CASE_TEMPLATE") {
|
||||||
m_currentState.setFlag(BoostTestTreeItem::Fixture);
|
m_currentState.setFlag(BoostTestTreeItem::Fixture);
|
||||||
m_currentState.setFlag(BoostTestTreeItem::Templated);
|
m_currentState.setFlag(BoostTestTreeItem::Templated);
|
||||||
handleTestCase(TestCaseType::Auto);
|
handleTestCase(TestCaseType::Auto);
|
||||||
|
m_currentState = BoostTestTreeItem::Enabled;
|
||||||
} else if (identifier == "BOOST_TEST_DECORATOR") {
|
} else if (identifier == "BOOST_TEST_DECORATOR") {
|
||||||
handleDecorator();
|
handleDecorator();
|
||||||
}
|
}
|
||||||
@@ -155,12 +167,10 @@ void BoostCodeParser::handleSuiteBegin(bool isFixture)
|
|||||||
if (skipCommentsUntil(T_RPAREN)) {
|
if (skipCommentsUntil(T_RPAREN)) {
|
||||||
// we have no decorators (or we have them before this macro)
|
// we have no decorators (or we have them before this macro)
|
||||||
m_suites << BoostTestInfo{m_currentSuite, m_currentState, m_lineNo};
|
m_suites << BoostTestInfo{m_currentSuite, m_currentState, m_lineNo};
|
||||||
m_currentState = BoostTestTreeItem::Enabled;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleDecorators();
|
handleDecorators();
|
||||||
m_suites << BoostTestInfo{m_currentSuite, m_currentState, m_lineNo};
|
m_suites << BoostTestInfo{m_currentSuite, m_currentState, m_lineNo};
|
||||||
m_currentState = BoostTestTreeItem::Enabled;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +203,7 @@ void BoostCodeParser::handleTestCase(TestCaseType testCaseType)
|
|||||||
const QList<QByteArray> parts = content.split(',');
|
const QList<QByteArray> parts = content.split(',');
|
||||||
if (parts.size() == 0)
|
if (parts.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
token = m_tokens.at(m_currentIndex);
|
||||||
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
||||||
|
|
||||||
const QByteArray functionName = parts.first();
|
const QByteArray functionName = parts.first();
|
||||||
@@ -201,7 +212,6 @@ void BoostCodeParser::handleTestCase(TestCaseType testCaseType)
|
|||||||
else
|
else
|
||||||
locationAndType.m_name = QString::fromUtf8(functionName);
|
locationAndType.m_name = QString::fromUtf8(functionName);
|
||||||
m_testCases.append(locationAndType);
|
m_testCases.append(locationAndType);
|
||||||
m_currentState = BoostTestTreeItem::Enabled;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (m_currentState.testFlag(BoostTestTreeItem::Fixture)) {
|
} else if (m_currentState.testFlag(BoostTestTreeItem::Fixture)) {
|
||||||
@@ -216,7 +226,6 @@ void BoostCodeParser::handleTestCase(TestCaseType testCaseType)
|
|||||||
token = m_tokens.at(m_currentIndex);
|
token = m_tokens.at(m_currentIndex);
|
||||||
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
||||||
m_testCases.append(locationAndType);
|
m_testCases.append(locationAndType);
|
||||||
m_currentState = BoostTestTreeItem::Enabled;
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case TestCaseType::Auto:
|
case TestCaseType::Auto:
|
||||||
@@ -226,7 +235,6 @@ void BoostCodeParser::handleTestCase(TestCaseType testCaseType)
|
|||||||
token = m_tokens.at(m_currentIndex);
|
token = m_tokens.at(m_currentIndex);
|
||||||
|
|
||||||
if (testCaseType == TestCaseType::Fixture) { // skip fixture class parameter
|
if (testCaseType == TestCaseType::Fixture) { // skip fixture class parameter
|
||||||
m_currentState |= BoostTestTreeItem::Fixture;
|
|
||||||
if (!skipCommentsUntil(T_COMMA))
|
if (!skipCommentsUntil(T_COMMA))
|
||||||
return;
|
return;
|
||||||
if (!skipCommentsUntil(T_IDENTIFIER))
|
if (!skipCommentsUntil(T_IDENTIFIER))
|
||||||
@@ -240,14 +248,12 @@ void BoostCodeParser::handleTestCase(TestCaseType testCaseType)
|
|||||||
if (skipCommentsUntil(T_RPAREN)) {
|
if (skipCommentsUntil(T_RPAREN)) {
|
||||||
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
||||||
m_testCases.append(locationAndType);
|
m_testCases.append(locationAndType);
|
||||||
m_currentState = BoostTestTreeItem::Enabled;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!m_currentState.testFlag(BoostTestTreeItem::Templated))
|
if (!m_currentState.testFlag(BoostTestTreeItem::Templated))
|
||||||
handleDecorators();
|
handleDecorators();
|
||||||
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
locationAndType = locationAndTypeFromToken(token, m_source, m_currentState, m_suites);
|
||||||
m_testCases.append(locationAndType);
|
m_testCases.append(locationAndType);
|
||||||
m_currentState = BoostTestTreeItem::Enabled;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user