OSDN Git Service

Merge remote branch 'origin/2.0'
[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) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
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 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29
30 #include "qtparser.h"
31 #include "qt4projectmanagerconstants.h"
32
33 #include <projectexplorer/taskwindow.h>
34 #include <projectexplorer/projectexplorerconstants.h>
35 #include <utils/qtcassert.h>
36
37 using namespace Qt4ProjectManager;
38 using namespace Qt4ProjectManager::Internal;
39 using ProjectExplorer::Task;
40
41 namespace {
42     // opt. drive letter + filename: (2 brackets)
43     const char * const FILE_PATTERN = "^(([A-Za-z]:)?[^:]+\\.[^:]+):";
44 }
45
46 QtParser::QtParser()
47 {
48     m_mocRegExp.setPattern(QString::fromLatin1(FILE_PATTERN) + "(\\d+):\\s(Warning|Error):\\s(.+)$");
49     m_mocRegExp.setMinimal(true);
50 }
51
52 void QtParser::stdError(const QString &line)
53 {
54     QString lne(line.trimmed());
55     if (m_mocRegExp.indexIn(lne) > -1) {
56         bool ok;
57         int lineno = m_mocRegExp.cap(3).toInt(&ok);
58         if (!ok)
59             lineno = -1;
60         Task task(Task::Error,
61                   m_mocRegExp.cap(5).trimmed(),
62                   m_mocRegExp.cap(1) /* filename */,
63                   lineno,
64                   ProjectExplorer::Constants::TASK_CATEGORY_COMPILE);
65         if (m_mocRegExp.cap(4) == QLatin1String("Warning"))
66             task.type = Task::Warning;
67         emit addTask(task);
68         return;
69     }
70     IOutputParser::stdError(line);
71 }
72
73 // Unit tests:
74
75 #ifdef WITH_TESTS
76 #   include <QTest>
77
78 #   include "qt4projectmanagerplugin.h"
79 #   include <projectexplorer/projectexplorerconstants.h>
80 #   include <projectexplorer/metatypedeclarations.h>
81 #   include <projectexplorer/outputparser_test.h>
82
83 using namespace ProjectExplorer;
84
85 void Qt4ProjectManagerPlugin::testQtOutputParser_data()
86 {
87     QTest::addColumn<QString>("input");
88     QTest::addColumn<OutputParserTester::Channel>("inputChannel");
89     QTest::addColumn<QString>("childStdOutLines");
90     QTest::addColumn<QString>("childStdErrLines");
91     QTest::addColumn<QList<ProjectExplorer::Task> >("tasks");
92     QTest::addColumn<QString>("outputLines");
93
94
95     QTest::newRow("pass-through stdout")
96             << QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
97             << QString::fromLatin1("Sometext") << QString()
98             << QList<ProjectExplorer::Task>()
99             << QString();
100     QTest::newRow("pass-through stderr")
101             << QString::fromLatin1("Sometext") << OutputParserTester::STDERR
102             << QString() << QString::fromLatin1("Sometext")
103             << QList<ProjectExplorer::Task>()
104             << QString();
105
106     QTest::newRow("moc warning")
107             << QString::fromLatin1("..\\untitled\\errorfile.h:0: Warning: No relevant classes found. No output generated.")
108             << OutputParserTester::STDERR
109             << QString() << QString()
110             << (QList<ProjectExplorer::Task>() << Task(Task::Warning,
111                                                        QLatin1String("No relevant classes found. No output generated."),
112                                                        QLatin1String("..\\untitled\\errorfile.h"), 0,
113                                                        ProjectExplorer::Constants::TASK_CATEGORY_COMPILE))
114             << QString();
115 }
116
117 void Qt4ProjectManagerPlugin::testQtOutputParser()
118 {
119     OutputParserTester testbench;
120     testbench.appendOutputParser(new QtParser);
121     QFETCH(QString, input);
122     QFETCH(OutputParserTester::Channel, inputChannel);
123     QFETCH(QList<Task>, tasks);
124     QFETCH(QString, childStdOutLines);
125     QFETCH(QString, childStdErrLines);
126     QFETCH(QString, outputLines);
127
128     testbench.testParsing(input, inputChannel, tasks, childStdOutLines, childStdErrLines, outputLines);
129 }
130 #endif