From f0ec467d6d9d83bda73396abe1be3c59fac50cc7 Mon Sep 17 00:00:00 2001 From: Lene Preuss Date: Wed, 16 Apr 2014 16:30:52 +0200 Subject: [PATCH] write test output to a temp file to store it (#130) --- tests/Auxiliary/TestRunner.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/Auxiliary/TestRunner.cpp b/tests/Auxiliary/TestRunner.cpp index 167379cb..62dcc093 100644 --- a/tests/Auxiliary/TestRunner.cpp +++ b/tests/Auxiliary/TestRunner.cpp @@ -4,7 +4,9 @@ #include #include #include -#include +#include + +#include struct TestRunner::Impl { @@ -14,6 +16,7 @@ struct TestRunner::Impl { static void printFailedTestSuite(std::string suite); + static QString getTestOutputFile(const QObject *test); unsigned executedTestSuites_; std::vector tests_to_run_; @@ -39,12 +42,22 @@ void TestRunner::add(QObject *test) { } void TestRunner::run() { - QStringList args; - args.append("-o /tmp/out"); -// args.append(""); for (QObject *test: pImpl->tests_to_run_) { - if (QTest::qExec(test, QStringList(args))) pImpl->failedTestSuites_.push_back(typeid(*test).name()); + QStringList args; + args << " " << "-o" << TestRunner::Impl::getTestOutputFile(test); + if (QTest::qExec(test, args)) pImpl->failedTestSuites_.push_back(typeid(*test).name()); pImpl->executedTestSuites_++; + + QFile file(TestRunner::Impl::getTestOutputFile(test)); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + + QTextStream in(&file); + while (!in.atEnd()) { + QString line = in.readLine(); + std::cerr << line.toStdString() << std::endl; + } + } pImpl->has_run_ = true; } @@ -69,3 +82,9 @@ void TestRunner::Impl::printFailedTestSuites() const { void TestRunner::Impl::printFailedTestSuite(std::string suite) { qDebug() << " " << suite.c_str(); } + +QString TestRunner::Impl::getTestOutputFile(const QObject* test) { + + QString testname = typeid(*test).name(); + return "/tmp/"+testname+".out"; +}