Add unit test for the gcc output parser

This commit is contained in:
Tobias Hunger
2010-03-03 18:05:37 +01:00
parent c59912819f
commit c2303b3c76
5 changed files with 419 additions and 0 deletions

View File

@@ -88,3 +88,162 @@ void GccParser::stdError(const QString &line)
}
IOutputParser::stdError(line);
}
// Unit tests:
#ifdef WITH_TESTS
# include <QTest>
# include "projectexplorer.h"
# include "metatypedeclarations.h"
# include "outputparser_test.h"
void ProjectExplorerPlugin::testGccOutputParsers_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<OutputParserTester::Channel>("inputChannel");
QTest::addColumn<QString>("childStdOutLines");
QTest::addColumn<QString>("childStdErrLines");
QTest::addColumn<QList<ProjectExplorer::TaskWindow::Task> >("tasks");
QTest::addColumn<QString>("outputLines");
QTest::newRow("pass-through stdout")
<< QString::fromLatin1("Sometext") << OutputParserTester::STDOUT
<< QString::fromLatin1("Sometext") << QString()
<< QList<ProjectExplorer::TaskWindow::Task>()
<< QString();
QTest::newRow("pass-through stderr")
<< QString::fromLatin1("Sometext") << OutputParserTester::STDERR
<< QString() << QString::fromLatin1("Sometext")
<< QList<ProjectExplorer::TaskWindow::Task>()
<< QString();
QTest::newRow("GCCE error")
<< QString::fromLatin1("/temp/test/untitled8/main.cpp: In function `int main(int, char**)':\n"
"/temp/test/untitled8/main.cpp:9: error: `sfasdf' undeclared (first use this function)\n"
"/temp/test/untitled8/main.cpp:9: error: (Each undeclared identifier is reported only once for each function it appears in.)")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>()
<< TaskWindow::Task(TaskWindow::Unknown,
QLatin1String("In function `int main(int, char**)':"),
QLatin1String("/temp/test/untitled8/main.cpp"), -1,
Constants::TASK_CATEGORY_COMPILE)
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("`sfasdf' undeclared (first use this function)"),
QLatin1String("/temp/test/untitled8/main.cpp"), 9,
Constants::TASK_CATEGORY_COMPILE)
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("(Each undeclared identifier is reported only once for each function it appears in.)"),
QLatin1String("/temp/test/untitled8/main.cpp"), 9,
Constants::TASK_CATEGORY_COMPILE)
)
<< QString();
QTest::newRow("GCCE warning")
<< QString::fromLatin1("/src/corelib/global/qglobal.h:1635: warning: inline function `QDebug qDebug()' used but never defined")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>()
<< TaskWindow::Task(TaskWindow::Warning,
QLatin1String("inline function `QDebug qDebug()' used but never defined"),
QLatin1String("/src/corelib/global/qglobal.h"), 1635,
Constants::TASK_CATEGORY_COMPILE))
<< QString();
QTest::newRow("warning")
<< QString::fromLatin1("main.cpp:7:2: warning: Some warning")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>() << TaskWindow::Task(TaskWindow::Warning,
QLatin1String("Some warning"),
QLatin1String("main.cpp"), 7,
Constants::TASK_CATEGORY_COMPILE))
<< QString();
QTest::newRow("GCCE #error")
<< QString::fromLatin1("C:\\temp\\test\\untitled8\\main.cpp:7: #error Symbian error")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>() << TaskWindow::Task(TaskWindow::Error,
QLatin1String("#error Symbian error"),
QLatin1String("C:\\temp\\test\\untitled8\\main.cpp"), 7,
Constants::TASK_CATEGORY_COMPILE))
<< QString();
// Symbian reports #warning(s) twice (using different syntax).
QTest::newRow("GCCE #warning1")
<< QString::fromLatin1("C:\\temp\\test\\untitled8\\main.cpp:8: warning: #warning Symbian warning")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>() << TaskWindow::Task(TaskWindow::Warning,
QLatin1String("#warning Symbian warning"),
QLatin1String("C:\\temp\\test\\untitled8\\main.cpp"), 8,
Constants::TASK_CATEGORY_COMPILE))
<< QString();
QTest::newRow("GCCE #warning2")
<< QString::fromLatin1("/temp/test/untitled8/main.cpp:8:2: warning: #warning Symbian warning")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>() << TaskWindow::Task(TaskWindow::Warning,
QLatin1String("#warning Symbian warning"),
QLatin1String("/temp/test/untitled8/main.cpp"), 8,
Constants::TASK_CATEGORY_COMPILE))
<< QString();
QTest::newRow("Undefined reference (debug)")
<< QString::fromLatin1("main.o: In function `main':\n"
"C:\\temp\\test\\untitled8/main.cpp:8: undefined reference to `MainWindow::doSomething()'\n"
"collect2: ld returned 1 exit status")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>()
<< TaskWindow::Task(TaskWindow::Unknown,
QLatin1String("In function `main':"),
QLatin1String("main.o"), -1,
Constants::TASK_CATEGORY_COMPILE)
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("undefined reference to `MainWindow::doSomething()'"),
QLatin1String("C:\\temp\\test\\untitled8/main.cpp"), 8,
Constants::TASK_CATEGORY_COMPILE)
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("collect2: ld returned 1 exit status"),
QString(), -1,
Constants::TASK_CATEGORY_COMPILE)
)
<< QString();
QTest::newRow("Undefined reference (release)")
<< QString::fromLatin1("main.o: In function `main':\n"
"C:\\temp\\test\\untitled8/main.cpp:(.text+0x40): undefined reference to `MainWindow::doSomething()'\n"
"collect2: ld returned 1 exit status")
<< OutputParserTester::STDERR
<< QString() << QString()
<< (QList<ProjectExplorer::TaskWindow::Task>()
<< TaskWindow::Task(TaskWindow::Unknown,
QLatin1String("In function `main':"),
QLatin1String("main.o"), -1,
Constants::TASK_CATEGORY_COMPILE)
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("undefined reference to `MainWindow::doSomething()'"),
QLatin1String("C:\\temp\\test\\untitled8/main.cpp"), -1,
Constants::TASK_CATEGORY_COMPILE)
<< TaskWindow::Task(TaskWindow::Error,
QLatin1String("collect2: ld returned 1 exit status"),
QString(), -1,
Constants::TASK_CATEGORY_COMPILE)
)
<< QString();
}
void ProjectExplorerPlugin::testGccOutputParsers()
{
OutputParserTester testbench;
testbench.appendOutputParser(new GccParser);
QFETCH(QString, input);
QFETCH(OutputParserTester::Channel, inputChannel);
QFETCH(QList<TaskWindow::Task>, tasks);
QFETCH(QString, childStdOutLines);
QFETCH(QString, childStdErrLines);
QFETCH(QString, outputLines);
testbench.testParsing(input, inputChannel,
tasks, childStdOutLines, childStdErrLines,
outputLines);
}
#endif