forked from qt-creator/qt-creator
AutoTest: Fix parsing of more complicated newRow() calls
If the name for the test row consists of more than a single string literal we only used the first part. In turn this test data could not get executed explicitly. Change-Id: I442c9058e036323cf1a21c21f200fcbfcf916fd8 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
committed by
Christian Stenger
parent
a14e7db1a4
commit
dd7a080eb1
@@ -203,6 +203,26 @@ bool TestDataFunctionVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString TestDataFunctionVisitor::extractNameFromAST(CPlusPlus::StringLiteralAST *ast, bool *ok) const
|
||||||
|
{
|
||||||
|
auto token = m_currentDoc->translationUnit()->tokenAt(ast->literal_token);
|
||||||
|
if (!token.isStringLiteral()) {
|
||||||
|
*ok = false;
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
*ok = true;
|
||||||
|
QString name = QString::fromUtf8(token.spell());
|
||||||
|
if (ast->next) {
|
||||||
|
CPlusPlus::StringLiteralAST *current = ast;
|
||||||
|
do {
|
||||||
|
auto nextToken = m_currentDoc->translationUnit()->tokenAt(current->next->literal_token);
|
||||||
|
name.append(QString::fromUtf8(nextToken.spell()));
|
||||||
|
current = current->next;
|
||||||
|
} while (current->next);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast)
|
bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast)
|
||||||
{
|
{
|
||||||
if (m_currentFunction.isEmpty())
|
if (m_currentFunction.isEmpty())
|
||||||
@@ -214,15 +234,15 @@ bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast)
|
|||||||
// first argument is the one we need
|
// first argument is the one we need
|
||||||
if (const auto argumentExpressionAST = expressionListAST->value) {
|
if (const auto argumentExpressionAST = expressionListAST->value) {
|
||||||
if (const auto stringLiteral = argumentExpressionAST->asStringLiteral()) {
|
if (const auto stringLiteral = argumentExpressionAST->asStringLiteral()) {
|
||||||
auto token = m_currentDoc->translationUnit()->tokenAt(
|
bool ok = false;
|
||||||
stringLiteral->literal_token);
|
QString name = extractNameFromAST(stringLiteral, &ok);
|
||||||
if (token.isStringLiteral()) {
|
if (ok) {
|
||||||
unsigned line = 0;
|
unsigned line = 0;
|
||||||
unsigned column = 0;
|
unsigned column = 0;
|
||||||
m_currentDoc->translationUnit()->getTokenStartPosition(
|
m_currentDoc->translationUnit()->getTokenStartPosition(
|
||||||
firstToken, &line, &column);
|
firstToken, &line, &column);
|
||||||
TestCodeLocationAndType locationAndType;
|
TestCodeLocationAndType locationAndType;
|
||||||
locationAndType.m_name = QString::fromUtf8(token.spell());
|
locationAndType.m_name = name;
|
||||||
locationAndType.m_column = column - 1;
|
locationAndType.m_column = column - 1;
|
||||||
locationAndType.m_line = line;
|
locationAndType.m_line = line;
|
||||||
locationAndType.m_type = TestTreeItem::TestDataTag;
|
locationAndType.m_type = TestTreeItem::TestDataTag;
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ public:
|
|||||||
QMap<QString, TestCodeLocationList> dataTags() const { return m_dataTags; }
|
QMap<QString, TestCodeLocationList> dataTags() const { return m_dataTags; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString extractNameFromAST(CPlusPlus::StringLiteralAST *ast, bool *ok) const;
|
||||||
bool newRowCallFound(CPlusPlus::CallAST *ast, unsigned *firstToken) const;
|
bool newRowCallFound(CPlusPlus::CallAST *ast, unsigned *firstToken) const;
|
||||||
|
|
||||||
CPlusPlus::Document::Ptr m_currentDoc;
|
CPlusPlus::Document::Ptr m_currentDoc;
|
||||||
|
|||||||
Reference in New Issue
Block a user