1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
35 #include "qt4projectmanagerconstants.h"
37 #include <projectexplorer/taskwindow.h>
38 #include <projectexplorer/projectexplorerconstants.h>
39 #include <utils/qtcassert.h>
41 using namespace Qt4ProjectManager;
42 using namespace Qt4ProjectManager::Internal;
43 using ProjectExplorer::Task;
46 // opt. drive letter + filename: (2 brackets)
47 const char * const FILE_PATTERN = "^(([A-Za-z]:)?[^:]+\\.[^:]+)";
52 setObjectName(QLatin1String("QtParser"));
53 m_mocRegExp.setPattern(QString::fromLatin1(FILE_PATTERN) + "[:\\(](\\d+)\\)?:\\s(Warning|Error):\\s(.+)$");
54 m_mocRegExp.setMinimal(true);
57 void QtParser::stdError(const QString &line)
59 QString lne(line.trimmed());
60 if (m_mocRegExp.indexIn(lne) > -1) {
62 int lineno = m_mocRegExp.cap(3).toInt(&ok);
65 Task task(Task::Error,
66 m_mocRegExp.cap(5).trimmed(),
67 m_mocRegExp.cap(1) /* filename */,
69 ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
70 if (m_mocRegExp.cap(4) == QLatin1String("Warning"))
71 task.type = Task::Warning;
75 IOutputParser::stdError(line);
83 # include "qt4projectmanagerplugin.h"
84 # include <projectexplorer/projectexplorerconstants.h>
85 # include <projectexplorer/metatypedeclarations.h>
86 # include <projectexplorer/outputparser_test.h>
88 using namespace ProjectExplorer;
90 void Qt4ProjectManagerPlugin::testQtOutputParser_data()
92 QTest::addColumn<QString>("input");
93 QTest::addColumn<OutputParserTester::Channel>("inputChannel");
94 QTest::addColumn<QString>("childStdOutLines");
95 QTest::addColumn<QString>("childStdErrLines");
96 QTest::addColumn<QList<ProjectExplorer::Task> >("tasks");
97 QTest::addColumn<QString>("outputLines");
100 QTest::newRow("pass-through stdout")
101 << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
102 << QString::fromLatin1("Sometext") << QString()
103 << QList<ProjectExplorer::Task>()
105 QTest::newRow("pass-through stderr")
106 << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
107 << QString() << QString::fromLatin1("Sometext")
108 << QList<ProjectExplorer::Task>()
110 QTest::newRow("pass-through gcc infos")
111 << QString::fromLatin1("/temp/test/untitled8/main.cpp: In function `int main(int, char**)':\n"
112 "../../scriptbug/main.cpp: At global scope:\n"
113 "../../scriptbug/main.cpp: In instantiation of void bar(i) [with i = double]:\n"
114 "../../scriptbug/main.cpp:8: instantiated from void foo(i) [with i = double]\n"
115 "../../scriptbug/main.cpp:22: instantiated from here\n")
116 << OutputParserTester::STDERR
118 << QString::fromLatin1("/temp/test/untitled8/main.cpp: In function `int main(int, char**)':\n"
119 "../../scriptbug/main.cpp: At global scope:\n"
120 "../../scriptbug/main.cpp: In instantiation of void bar(i) [with i = double]:\n"
121 "../../scriptbug/main.cpp:8: instantiated from void foo(i) [with i = double]\n"
122 "../../scriptbug/main.cpp:22: instantiated from here\n")
123 << QList<ProjectExplorer::Task>()
125 QTest::newRow("moc warning")
126 << QString::fromLatin1("..\\untitled\\errorfile.h:0: Warning: No relevant classes found. No output generated.")
127 << OutputParserTester::STDERR
128 << QString() << QString()
129 << (QList<ProjectExplorer::Task>() << Task(Task::Warning,
130 QLatin1String("No relevant classes found. No output generated."),
131 QLatin1String("..\\untitled\\errorfile.h"), 0,
132 ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
134 QTest::newRow("moc warning 2")
135 << QString::fromLatin1("c:\\code\\test.h(96): Warning: Property declaration ) has no READ accessor function. The property will be invalid.")
136 << OutputParserTester::STDERR
137 << QString() << QString()
138 << (QList<ProjectExplorer::Task>() << Task(Task::Warning,
139 QLatin1String("Property declaration ) has no READ accessor function. The property will be invalid."),
140 QLatin1String("c:\\code\\test.h"), 96,
141 ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
145 void Qt4ProjectManagerPlugin::testQtOutputParser()
147 OutputParserTester testbench;
148 testbench.appendOutputParser(new QtParser);
149 QFETCH(QString, input);
150 QFETCH(OutputParserTester::Channel, inputChannel);
151 QFETCH(QList<Task>, tasks);
152 QFETCH(QString, childStdOutLines);
153 QFETCH(QString, childStdErrLines);
154 QFETCH(QString, outputLines);
156 testbench.testParsing(input, inputChannel, tasks, childStdOutLines, childStdErrLines, outputLines);