Commit 87bfd402 authored by Manuel Breugelmans's avatar Manuel Breugelmans

Store qtest results as temporary files. Add outputview for verbose test...

Store qtest results as temporary files. Add outputview for verbose test output. Refactor QTestOutputParserTest.
parent 840f4bae
......@@ -65,4 +65,4 @@ money_suite (void)
return s;
}
CHECK_XTEST_MAIN( money_suite() )
CHECK_VERITAS_MAIN_( money_suite() )
......@@ -39,4 +39,4 @@ Test* MoneyTest::suite()
return r;
}
CPPUNIT_XTEST_MAIN( MoneyTest::suite() )
CPPUNIT_VERITAS_MAIN( MoneyTest::suite() )
#include <QtTest/QtTest>
#include <QDebug>
#include "money.h"
#include "moneytest.h"
......@@ -19,6 +20,8 @@ void MoneyTest::negative()
void MoneyTest::zero()
{
qDebug() << "supposed to fail";
qDebug() << "more garbage output";
Money m(0, "USD");
QCOMPARE(Money::Good, m.state());
QCOMPARE(0, m.amount());
......
[Project]
Name=KDevelop
Name=kdevelop
Manager=KDevCMakeManager
......@@ -63,7 +63,7 @@ public:
}
virtual Qt::DockWidgetArea defaultPosition() {
return Qt::BottomDockWidgetArea;
return Qt::LeftDockWidgetArea;
}
virtual QString id() const {
......
......@@ -29,13 +29,17 @@ namespace Veritas { class Test; }
class CheckView : public Veritas::TestRunnerToolView
{
Q_OBJECT
Q_OBJECT
public:
explicit CheckView(QObject* parent, const QVariantList & = QVariantList());
virtual ~CheckView();
protected slots:
virtual void openVerbose(Veritas::Test*) {}
protected:
Veritas::Test* registerTests();
virtual QString resultsViewId() { return "org.kdevelop.CheckResultsView"; }
private:
QString fetchExe();
......
......@@ -185,26 +185,27 @@ void CheckRunnerTest::checkResultItems(QList<QStringList> expected)
// helper
void CheckRunnerTest::checkResultItem(int num, const QStringList& item)
{
QAbstractItemModel* results = m_window->ui()->treeResults->model();
KOMPARE(item[0], results->data(results->index(num, 0))); // test name
//KOMPARE(item[1], results->data(results->index(num, 1))); // status -> "Error"
m_resultModel = m_window->resultsView()->model();
;
KOMPARE(item[0], m_resultModel->data(m_resultModel->index(num, 0))); // test name
//KOMPARE(item[1], m_resultModel->data(m_resultModel->index(num, 1))); // status -> "Error"
// commented out since this row is currently hidden
KOMPARE(item[1], results->data(results->index(num, 2))); // failure message
// KOMPARE(item[2], results->data(results->index(num, 3))); // filename
KOMPARE(item[1], m_resultModel->data(m_resultModel->index(num, 2))); // failure message
// KOMPARE(item[2], m_resultModel->data(m_resultModel->index(num, 3))); // filename
// commented out since this is factually a file in the source-tree, for
// which i can not get the proper location at runtime.
KOMPARE(item[3], results->data(results->index(num, 4))); // line number
KOMPARE(item[3], m_resultModel->data(m_resultModel->index(num, 4))); // line number
}
// helper
void CheckRunnerTest::nrofMessagesEquals(int num)
{
QAbstractItemModel* results = m_window->ui()->treeResults->model();
m_resultModel = m_window->resultsView()->model();
for (int i = 0; i < num; i++) {
KVERIFY_MSG(results->index(i, 0).isValid(),
KVERIFY_MSG(m_resultModel->index(i, 0).isValid(),
QString("Expected ") + QString::number(num) + " items but got " + QString::number(i));
}
KVERIFY(!results->index(num, 0).isValid());
KVERIFY(!m_resultModel->index(num, 0).isValid());
}
// helper
......@@ -218,7 +219,7 @@ void CheckRunnerTest::initNrun(const char* exe)
model->setRootItem(reg.rootItem());
m_window = new RunnerWindow;
m_window->setModel(model);
m_window->show();
//m_window->show();
m_window->ui()->actionStart->trigger();
}
......
......@@ -55,8 +55,8 @@ private:
private:
Veritas::RunnerWindow* m_window;
QAbstractItemModel* m_runnerItems;
QAbstractItemModel* m_resultItems;
QAbstractItemModel* m_runnerModel;
QAbstractItemModel* m_resultModel;
};
} // namespace it
......
......@@ -62,7 +62,7 @@ public:
}
virtual Qt::DockWidgetArea defaultPosition() {
return Qt::BottomDockWidgetArea;
return Qt::LeftDockWidgetArea;
}
virtual QString id() const {
......
......@@ -34,8 +34,12 @@ public:
explicit CppUnitView(QObject* parent, const QVariantList & = QVariantList());
virtual ~CppUnitView();
protected slots:
virtual void openVerbose(Veritas::Test*) {}
protected:
Veritas::Test* registerTests();
virtual QString resultsViewId() { return "org.kdevelop.CppUnitResultsView";};
private:
QString fetchExe();
......
......@@ -172,26 +172,27 @@ void CppUnitRunnerTest::checkResultItems(QList<QStringList> expected)
// helper
void CppUnitRunnerTest::checkResultItem(int num, const QStringList& item)
{
QAbstractItemModel* results = m_window->ui()->treeResults->model();
KOMPARE(item[0], results->data(results->index(num, 0))); // test name
//KOMPARE(item[1], results->data(results->index(num, 1))); // status -> "Error"
m_resultModel = m_window->resultsView()->model();
KOMPARE(item[0], m_resultModel->data(m_resultModel->index(num, 0))); // test name
//KOMPARE(item[1], m_resultModel->data(m_resultModel->index(num, 1))); // status -> "Error"
// commented out since this row is currently hidden
KOMPARE(item[1], results->data(results->index(num, 2))); // failure message
// KOMPARE(item[2], results->data(results->index(num, 3))); // filename
KOMPARE(item[1], m_resultModel->data(m_resultModel->index(num, 2))); // failure message
// KOMPARE(item[2], m_resultModel->data(m_resultModel->index(num, 3))); // filename
// commented out since this is factually a file in the source-tree, for
// which i can not get the proper location at runtime.
KOMPARE(item[3], results->data(results->index(num, 4))); // line number
KOMPARE(item[3], m_resultModel->data(m_resultModel->index(num, 4))); // line number
}
// helper
void CppUnitRunnerTest::nrofMessagesEquals(int num)
{
QAbstractItemModel* results = m_window->ui()->treeResults->model();
m_resultModel = m_window->resultsView()->model();
for (int i = 0; i < num; i++) {
KVERIFY_MSG(results->index(i, 0).isValid(),
KVERIFY_MSG(m_resultModel->index(i, 0).isValid(),
QString("Expected ") + QString::number(num) + " items but got " + QString::number(i));
}
KVERIFY(!results->index(num, 0).isValid());
KVERIFY(!m_resultModel->index(num, 0).isValid());
}
// helper
......@@ -205,7 +206,7 @@ void CppUnitRunnerTest::initNrun(const char* exe)
model->setExpectedResults(Veritas::RunError);
m_window = new RunnerWindow;
m_window->setModel(model);
m_window->show();
//m_window->show();
m_window->ui()->actionStart->trigger();
}
......
......@@ -54,8 +54,8 @@ private:
private:
Veritas::RunnerWindow* m_window;
QAbstractItemModel* m_runnerItems;
QAbstractItemModel* m_resultItems;
QAbstractItemModel* m_runnerModel;
QAbstractItemModel* m_resultModel;
};
} // namespace it
......
......@@ -115,6 +115,8 @@
<command name="construct" />
<command name="addCommand" />
<command name="addCommands" />
<command name="demoFailure" />
<command name="moreFailures" />
</case>
<case name="qtest-it-qtestrunnertest" exe="qtest-it-qtestrunnertest.shell">
<command name="empty" />
......
add_subdirectory(tests)
add_subdirectory(config)
#add_subdirectory(outputview)
add_definitions( ${KDE4_ENABLE_EXCEPTIONS} )
add_definitions( -DKDE_DEFAULT_DEBUG_AREA=9003 )
......@@ -25,13 +26,22 @@ set(kdevqtest_SRCS
qtestcommand.cpp
qtestsuite.cpp
qtestregister.cpp
config/qtestsettings.cpp)
qtestoutputmorpher.cpp
config/qtestsettings.cpp
outputview/qtestoutputmodel.cpp
outputview/qtestoutputdelegate.cpp
outputview/qtestoutputjob.cpp)
qt4_automoc(${kdevqtest_SRCS})
kde4_add_library(kdevqtest SHARED ${kdevqtest_SRCS})
target_link_libraries(kdevqtest
${KDEVPLATFORM_VERITAS_LIBRARY}
${KDEVPLATFORM_INTERFACES_LIBRARY}
${KDEVPLATFORM_OUTPUTVIEW_LIBRARY}
${KDEVPLATFORM_PROJECT_LIBRARY}
${KDEVPLATFORM_UTIL_LIBRARY}
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
${QT_QTCORE_LIBRARY}
${QT_QTXML_LIBRARY})
install(TARGETS kdevqtest ${INSTALL_TARGETS_DEFAULT_ARGS} )
......@@ -41,10 +51,12 @@ qt4_automoc(${kdevqtestview_SRCS})
kde4_add_plugin(kdevqtestview ${kdevqtestview_SRCS})
target_link_libraries(kdevqtestview
kdevqtest
${QT_QTCORE_LIBRARY}
${KDEVPLATFORM_LIBRARIES}
${KDE4_KDEUI_LIBS}
${KDE4_KDECORE_LIBS}
${KDE4_KTEXTEDITOR_LIBS}
${QT_QTCORE_LIBRARY})
${KDE4_KPARTS_LIBS})
install(TARGETS kdevqtestview DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
......
/***************************************************************************
* This file is part of KDevelop *
* Copyright (C) 2007 Andreas Pakulat <apaku@gmx.de> *
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "qtestoutputdelegate.h"
#include "qtestoutputmodel.h"
#include <QtGui/QPainter>
#include <QtCore/QModelIndex>
#include <KDebug>
QTestOutputDelegate::QTestOutputDelegate(QObject* parent)
: QItemDelegate(parent),
textBrush(KColorScheme::View, KColorScheme::NormalText),
errorBrush(KColorScheme::View, KColorScheme::NegativeText),
passBrush(KColorScheme::View, KColorScheme::PositiveText)
{}
void QTestOutputDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyleOptionViewItem opt = option;
QString text = index.data().toString();
if (text.startsWith("PASS")) {
opt.palette.setBrush(QPalette::Text, passBrush.brush(option.palette));
} else if (text.startsWith("FAIL") || text.startsWith("QFATAL")) {
opt.palette.setBrush(QPalette::Text, errorBrush.brush(option.palette));
} else {
opt.palette.setBrush(QPalette::Text, textBrush.brush(option.palette));
}
QItemDelegate::paint(painter, opt, index);
}
/***************************************************************************
* This file is part of KDevelop *
* Copyright (C) 2007 Andreas Pakulat <apaku@gmx.de> *
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef MYOUTPUTOUTPUTDELEGATE_H
#define MYOUTPUTOUTPUTDELEGATE_H
#include <QtGui/QItemDelegate>
#include <kcolorscheme.h>
class QTestOutputDelegate : public QItemDelegate
{
public:
QTestOutputDelegate(QObject*);
void paint(QPainter*, const QStyleOptionViewItem&, const QModelIndex&) const;
private:
KStatefulBrush textBrush;
KStatefulBrush errorBrush;
KStatefulBrush passBrush;
};
#endif
/* KDevelop xUnit plugin
* Copyright 1999-2001 Bernd Gehrmann and the KDevelop Team <bernd@kdevelop.org>
* Copyright 2007 Dukju Ahn <dukjuahn@gmail.com> *
* Copyright 2008 by Hamish Rodda <rodda@kde.org>
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "qtestoutputjob.h"
#include "qtestoutputmodel.h"
#include "qtestoutputdelegate.h"
#include "../qtestview.h"
#include "../qtestcase.h"
#include <KProcess>
#include <KLocale>
#include <kdevplatform/interfaces/icore.h>
#include <kdevplatform/util/processlinemaker.h>
using namespace KDevelop;
using QTest::QTestCase;
QTestOutputJob::QTestOutputJob(QTestOutputDelegate* parent, QTestCase* caze)
: OutputJob(parent), m_caze(caze)
{}
void QTestOutputJob::start()
{
setToolTitle(i18n("QTest verbose output"));
setToolIcon(KIcon("edit-find"));
setViewType(KDevelop::IOutputView::HistoryView);
setStandardToolView(KDevelop::IOutputView::TestView);
//setTitle("");
setBehaviours(KDevelop::IOutputView::AutoScroll | KDevelop::IOutputView::AllowUserClose);
setModel(new QTestOutputModel(delegate()), KDevelop::IOutputView::TakeOwnership);
setDelegate(delegate());
startOutput();
m_cat = new KProcess;
QStringList l;
l << m_caze->textOutFilePath().absoluteFilePath();
l << m_caze->stdErrFilePath().absoluteFilePath();
m_cat->setProgram("cat", l);
m_cat->setOutputChannelMode(KProcess::SeparateChannels);
m_lineMaker = new KDevelop::ProcessLineMaker(m_cat);
connect(m_lineMaker, SIGNAL(receivedStdoutLines(QStringList)),
model(), SLOT(appendOutputs(QStringList)));
connect(m_lineMaker, SIGNAL(receivedStderrLines(QStringList)),
model(), SLOT(appendErrors(QStringList)));
connect(m_cat, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotFinished()));
connect(m_cat, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(slotError(QProcess::ProcessError)));
m_cat->start();
}
void QTestOutputJob::slotFinished()
{
m_lineMaker->flushBuffers();
model()->slotCompleted();
emitResult();
}
void QTestOutputJob::slotError(QProcess::ProcessError)
{
m_lineMaker->flushBuffers();
model()->slotCompleted();
m_cat->kill();
setError(UserDefinedError);
emitResult();
}
QTestOutputDelegate* QTestOutputJob::delegate() const
{
return const_cast<QTestOutputDelegate*>(static_cast<const QTestOutputDelegate*>(parent()));
}
QTestOutputModel* QTestOutputJob::model() const
{
return static_cast<QTestOutputModel*>(OutputJob::model());
}
#include "qtestoutputjob.moc"
/* KDevelop xUnit plugin
* Copyright 1999-2001 Bernd Gehrmann and the KDevelop Team <bernd@kdevelop.org>
* Copyright 2008 by Hamish Rodda <rodda@kde.org>
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef QTEST_QTESTOUTPUTJOB_H
#define QTEST_QTESTOUTPUTJOB_H
#include <kdevplatform/interfaces/iplugin.h>
#include <kdevplatform/outputview/outputjob.h>
#include <QProcess>
namespace KDevelop
{
class IOutputView;
class IProject;
class ProcessLineMaker;
}
namespace QTest { class QTestCase; }
class KProcess;
class QTestOutputModel;
class QTestOutputDelegate;
class QTestView;
class QTestOutputJob : public KDevelop::OutputJob
{
Q_OBJECT
public:
QTestOutputJob(QTestOutputDelegate *parent, QTest::QTestCase*);
virtual void start();
protected:
QTestOutputModel* model() const;
private Q_SLOTS:
void slotFinished();
void slotError(QProcess::ProcessError error);
private:
QTestOutputDelegate* delegate() const;
KDevelop::ProcessLineMaker* m_lineMaker;
KProcess* m_cat;
QTest::QTestCase* m_caze;
};
#endif // QTEST_QTESTOUTPUTJOB_H
/* KDevelop xUnit plugin
* Copyright 1999-2001 Bernd Gehrmann and the KDevelop Team <bernd@kdevelop.org>
* Copyright 2007 Dukju Ahn <dukjuahn@gmail.com>
* Copyright 2008 Manuel Breugelmans <mbr.nxi@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "qtestoutputmodel.h"
#include <QModelIndex>
#include <KGlobalSettings>
#include <kdevplatform/interfaces/icore.h>
QTestOutputItem::QTestOutputItem(const QString &text)
: QStandardItem(), m_text(text)
{
setText(text);
}
QTestOutputItem::~QTestOutputItem()
{}
QTestOutputModel::QTestOutputModel(QObject *parent)
: QStandardItemModel(parent)
{}
QTestOutputModel::~QTestOutputModel()
{}
QVariant QTestOutputModel::data(const QModelIndex& index, int role) const
{
if (role != Qt::FontRole) {
return QStandardItemModel::data(index, role);
} else {
return KGlobalSettings::fixedFont();
}
}
void QTestOutputModel::activate(const QModelIndex &idx)
{
QStandardItem *stditem = itemFromIndex(idx);
QTestOutputItem *qtestoutputitem = dynamic_cast<QTestOutputItem*>(stditem);
if (!qtestoutputitem) return;
}
QModelIndex QTestOutputModel::nextHighlightIndex(const QModelIndex& currentIndex)
{
int nextRow = currentIndex.row() + 1;
int rows = rowCount(currentIndex.parent());
while (nextRow != currentIndex.row()) {
QModelIndex idx = index(nextRow, currentIndex.column(), currentIndex.parent());
if (QTestOutputItem* item = dynamic_cast<QTestOutputItem*>(itemFromIndex(idx))) {
return idx;
}
++nextRow;
if (nextRow >= rows) {
if (currentIndex.row() == -1) {
break;
} else {
nextRow = 0;
}
}
}
return QModelIndex();
}
QModelIndex QTestOutputModel::previousHighlightIndex(const QModelIndex& currentIndex)
{
int prevRow = currentIndex.row() - 1;
int rows = rowCount(currentIndex.parent());
do {
if (prevRow < 0) {
prevRow = rows - 1;
}
QModelIndex idx = index(prevRow, currentIndex.column(), currentIndex.parent());
if (QTestOutputItem* item = dynamic_cast<QTestOutputItem*>(itemFromIndex(idx))) {
return idx;
}
--prevRow;
} while (prevRow != currentIndex.row());
return QModelIndex();
}
void QTestOutputModel::appendOutputs(const QStringList &lines)