Redesign AbstractTest::Run.
--HG-- branch : develop
This commit is contained in:
parent
166ef0b82e
commit
df758fd159
|
@ -99,15 +99,14 @@ QString AbstractTest::TranslationsPath() const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
int AbstractTest::Run(int exit, const QString &program, const QStringList &arguments, int msecs)
|
int AbstractTest::Run(int exit, const QString &program, const QStringList &arguments, QString &error, int msecs)
|
||||||
{
|
{
|
||||||
const QString parameters = QString("Program: %1 \nArguments: %2.").arg(program).arg(arguments.join(", "));
|
const QString parameters = QString("Program: %1 \nArguments: %2.").arg(program).arg(arguments.join(", "));
|
||||||
|
|
||||||
QFileInfo info(program);
|
QFileInfo info(program);
|
||||||
if (not info.exists())
|
if (not info.exists())
|
||||||
{
|
{
|
||||||
const QString msg = QString("Can't find binary.\n%1").arg(parameters);
|
error = QString("Can't find binary.\n%1").arg(parameters);
|
||||||
QWARN(qUtf8Printable(msg));
|
|
||||||
return TST_EX_BIN;
|
return TST_EX_BIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,26 +114,29 @@ int AbstractTest::Run(int exit, const QString &program, const QStringList &argum
|
||||||
process->setWorkingDirectory(info.absoluteDir().absolutePath());
|
process->setWorkingDirectory(info.absoluteDir().absolutePath());
|
||||||
process->start(program, arguments);
|
process->start(program, arguments);
|
||||||
|
|
||||||
|
if (not process->waitForStarted(msecs))
|
||||||
|
{
|
||||||
|
error = QString("The start operation timed out or an error occurred.\n%1").arg(parameters);
|
||||||
|
process->kill();
|
||||||
|
return TST_EX_START_TIME_OUT;
|
||||||
|
}
|
||||||
|
|
||||||
if (not process->waitForFinished(msecs))
|
if (not process->waitForFinished(msecs))
|
||||||
{
|
{
|
||||||
const QString msg = QString("The operation timed out or an error occurred.\n%1").arg(parameters);
|
error = QString("The finish operation timed out or an error occurred.\n%1").arg(parameters);
|
||||||
QWARN(qUtf8Printable(msg));
|
|
||||||
process->kill();
|
process->kill();
|
||||||
return TST_EX_TIME_OUT;
|
return TST_EX_FINISH_TIME_OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process->exitStatus() == QProcess::CrashExit)
|
if (process->exitStatus() == QProcess::CrashExit)
|
||||||
{
|
{
|
||||||
const QString msg = QString("Program crashed.\n%1\n%2").arg(parameters)
|
error = QString("Program crashed.\n%1\n%2").arg(parameters).arg(QString(process->readAllStandardError()));
|
||||||
.arg(QString(process->readAllStandardError()));
|
|
||||||
QWARN(qUtf8Printable(msg));
|
|
||||||
return TST_EX_CRASH;
|
return TST_EX_CRASH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process->exitCode() != exit)
|
if (process->exitCode() != exit)
|
||||||
{
|
{
|
||||||
const QString msg = QString("Unexpected finish.\n%1").arg(QString(process->readAllStandardError()));
|
error = QString("Unexpected finish.\n%1").arg(QString(process->readAllStandardError()));
|
||||||
QWARN(qUtf8Printable(msg));
|
|
||||||
return process->exitCode();
|
return process->exitCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,9 @@ template <class T> class QVector;
|
||||||
|
|
||||||
// Return codes for testing run application
|
// Return codes for testing run application
|
||||||
static const auto V_UNUSED TST_EX_BIN = -1; // Can't find binary.
|
static const auto V_UNUSED TST_EX_BIN = -1; // Can't find binary.
|
||||||
static const auto V_UNUSED TST_EX_TIME_OUT = -2; // The operation timed out or an error occurred.
|
static const auto V_UNUSED TST_EX_FINISH_TIME_OUT = -2; // The operation timed out or an error occurred.
|
||||||
static const auto V_UNUSED TST_EX_CRASH = -3; // Program crashed.
|
static const auto V_UNUSED TST_EX_START_TIME_OUT = -3; // The operation timed out or an error occurred.
|
||||||
|
static const auto V_UNUSED TST_EX_CRASH = -4; // Program crashed.
|
||||||
|
|
||||||
#undef V_UNUSED
|
#undef V_UNUSED
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ protected:
|
||||||
QString TapePath() const;
|
QString TapePath() const;
|
||||||
QString TranslationsPath() const;
|
QString TranslationsPath() const;
|
||||||
|
|
||||||
int Run(int exit, const QString &program, const QStringList &arguments, int msecs = 120000);
|
int Run(int exit, const QString &program, const QStringList &arguments, QString &error, int msecs = 120000);
|
||||||
bool CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const;
|
bool CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "tst_tapecommandline.h"
|
#include "tst_tapecommandline.h"
|
||||||
#include "../vmisc/vsysexits.h"
|
#include "../vmisc/vsysexits.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
@ -114,11 +115,12 @@ void TST_TapeCommandLine::OpenMeasurements()
|
||||||
QFETCH(QString, file);
|
QFETCH(QString, file);
|
||||||
QFETCH(int, exitCode);
|
QFETCH(int, exitCode);
|
||||||
|
|
||||||
|
QString error;
|
||||||
const int exit = Run(exitCode, TapePath(), QStringList() << "--test"
|
const int exit = Run(exitCode, TapePath(), QStringList() << "--test"
|
||||||
<< QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder + QDir::separator() +
|
<< QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder + QDir::separator() +
|
||||||
file);
|
file, error);
|
||||||
|
|
||||||
QCOMPARE(exit, exitCode);
|
QVERIFY2(exit == exitCode, qUtf8Printable(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include "tst_valentinacommandline.h"
|
#include "tst_valentinacommandline.h"
|
||||||
#include "../vmisc/vsysexits.h"
|
#include "../vmisc/vsysexits.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
@ -102,11 +103,12 @@ void TST_ValentinaCommandLine::OpenPatterns()
|
||||||
QFETCH(QString, file);
|
QFETCH(QString, file);
|
||||||
QFETCH(int, exitCode);
|
QFETCH(int, exitCode);
|
||||||
|
|
||||||
|
QString error;
|
||||||
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder;
|
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder;
|
||||||
const int exit = Run(exitCode, ValentinaPath(), QStringList() << "--test"
|
const int exit = Run(exitCode, ValentinaPath(), QStringList() << "--test"
|
||||||
<< tmp + QDir::separator() + file);
|
<< tmp + QDir::separator() + file, error);
|
||||||
|
|
||||||
QCOMPARE(exit, exitCode);
|
QVERIFY2(exit == exitCode, qUtf8Printable(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -152,12 +154,13 @@ void TST_ValentinaCommandLine::ExportMode()
|
||||||
QFETCH(QString, arguments);
|
QFETCH(QString, arguments);
|
||||||
QFETCH(int, exitCode);
|
QFETCH(int, exitCode);
|
||||||
|
|
||||||
|
QString error;
|
||||||
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder;
|
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder;
|
||||||
const QStringList arg = QStringList() << tmp + QDir::separator() + file
|
const QStringList arg = QStringList() << tmp + QDir::separator() + file
|
||||||
<< arguments.split(";;");
|
<< arguments.split(";;");
|
||||||
const int exit = Run(exitCode, ValentinaPath(), arg);
|
const int exit = Run(exitCode, ValentinaPath(), arg, error);
|
||||||
|
|
||||||
QCOMPARE(exit, exitCode);
|
QVERIFY2(exit == exitCode, qUtf8Printable(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -209,12 +212,13 @@ void TST_ValentinaCommandLine::TestMode()
|
||||||
QFETCH(QString, arguments);
|
QFETCH(QString, arguments);
|
||||||
QFETCH(int, exitCode);
|
QFETCH(int, exitCode);
|
||||||
|
|
||||||
|
QString error;
|
||||||
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder;
|
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestFolder;
|
||||||
const QStringList arg = QStringList() << tmp + QDir::separator() + file
|
const QStringList arg = QStringList() << tmp + QDir::separator() + file
|
||||||
<< arguments.split(";;");
|
<< arguments.split(";;");
|
||||||
const int exit = Run(exitCode, ValentinaPath(), arg);
|
const int exit = Run(exitCode, ValentinaPath(), arg, error);
|
||||||
|
|
||||||
QCOMPARE(exit, exitCode);
|
QVERIFY2(exit == exitCode, qUtf8Printable(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -269,12 +273,13 @@ void TST_ValentinaCommandLine::TestOpenCollection()
|
||||||
QFETCH(QString, arguments);
|
QFETCH(QString, arguments);
|
||||||
QFETCH(int, exitCode);
|
QFETCH(int, exitCode);
|
||||||
|
|
||||||
|
QString error;
|
||||||
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestCollectionFolder;
|
const QString tmp = QApplication::applicationDirPath() + QDir::separator() + tmpTestCollectionFolder;
|
||||||
const QStringList arg = QStringList() << tmp + QDir::separator() + file
|
const QStringList arg = QStringList() << tmp + QDir::separator() + file
|
||||||
<< arguments.split(";;");
|
<< arguments.split(";;");
|
||||||
const int exit = Run(exitCode, ValentinaPath(), arg);
|
const int exit = Run(exitCode, ValentinaPath(), arg, error);
|
||||||
|
|
||||||
QCOMPARE(exit, exitCode);
|
QVERIFY2(exit == exitCode, qUtf8Printable(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user