OSDN Git Service

641236b66f5b54a7cb6146590fd4419a637f8e53
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qtparser.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "qtparser.h"
35 #include "qt4projectmanagerconstants.h"
36
37 #include <projectexplorer/taskwindow.h>
38 #include <projectexplorer/projectexplorerconstants.h>
39 #include <utils/qtcassert.h>
40
41 using namespace Qt4ProjectManager;
42 using namespace Qt4ProjectManager::Internal;
43 using ProjectExplorer::Task;
44
45 namespace {
46     // opt. drive letter + filename: (2 brackets)
47     const char * const FILE_PATTERN = "^(([A-Za-z]:)?[^:]+\\.[^:]+)";
48 }
49
50 QtParser::QtParser()
51 {
52     setObjectName(QLatin1String("QtParser"));
53     m_mocRegExp.setPattern(QString::fromLatin1(FILE_PATTERN) + "[:\\(](\\d+)\\)?:\\s(Warning|Error):\\s(.+)$");
54     m_mocRegExp.setMinimal(true);
55 }
56
57 void QtParser::stdError(const QString &line)
58 {
59     QString lne(line.trimmed());
60     if (m_mocRegExp.indexIn(lne) > -1) {
61         bool ok;
62         int lineno = m_mocRegExp.cap(3).toInt(&ok);
63         if (!ok)
64             lineno = -1;
65         Task task(Task::Error,
66                   m_mocRegExp.cap(5).trimmed(),
67                   m_mocRegExp.cap(1) /* filename */,
68                   lineno,
69                   ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
70         if (m_mocRegExp.cap(4) == QLatin1String("Warning"))
71             task.type = Task::Warning;
72         emit addTask(task);
73         return;
74     }
75     IOutputParser::stdError(line);
76 }
77
78 // Unit tests:
79
80 #ifdef WITH_TESTS
81 #   include <QTest>
82
83 #   include "qt4projectmanagerplugin.h"
84 #   include <projectexplorer/projectexplorerconstants.h>
85 #   include <projectexplorer/metatypedeclarations.h>
86 #   include <projectexplorer/outputparser_test.h>
87
88 using namespace ProjectExplorer;
89
90 void Qt4ProjectManagerPlugin::testQtOutputParser_data()
91 {
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");
98
99
100     QTest::newRow("pass-through stdout")
101             << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
102             << QString::fromLatin1("Sometext") << QString()
103             << QList<ProjectExplorer::Task>()
104             << QString();
105     QTest::newRow("pass-through stderr")
106             << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
107             << QString() << QString::fromLatin1("Sometext")
108             << QList<ProjectExplorer::Task>()
109             << QString();
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
117             << QString()
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>()
124             << QString();
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))
133             << QString();
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))
142             << QString();
143 }
144
145 void Qt4ProjectManagerPlugin::testQtOutputParser()
146 {
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);
155
156     testbench.testParsing(input, inputChannel, tasks, childStdOutLines, childStdErrLines, outputLines);
157 }
158 #endif