From 9317fbffeab4a8c258acb1116eb12fbded7053d8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 8 Jul 2016 11:01:48 +0200 Subject: Control debugoutput during tests with sinksh. --- common/test.cpp | 28 ++++++++++++++++++++++ .../imapresource/tests/imapserverproxytest.cpp | 1 - .../tests/mailtransporttest.cpp | 1 - sinksh/syntax_modules/sink_trace.cpp | 21 +++++++++------- tests/accountstest.cpp | 1 - tests/clientapitest.cpp | 1 - tests/dummyresourcetest.cpp | 1 - tests/genericfacadetest.cpp | 6 ++--- tests/genericresourcetest.cpp | 1 - tests/inspectiontest.cpp | 1 - tests/maildirsyncbenchmark.cpp | 1 - tests/mailsynctest.cpp | 1 - tests/mailtest.cpp | 1 - tests/messagequeuetest.cpp | 3 ++- tests/modelinteractivitytest.cpp | 1 - tests/pipelinetest.cpp | 1 - tests/querytest.cpp | 1 - tests/resourceconfigtest.cpp | 1 - tests/testaccounttest.cpp | 1 - 19 files changed, 45 insertions(+), 28 deletions(-) diff --git a/common/test.cpp b/common/test.cpp index 99e51c8..5b4c899 100644 --- a/common/test.cpp +++ b/common/test.cpp @@ -27,6 +27,7 @@ #include "facadefactory.h" #include "query.h" #include "resourceconfig.h" +#include "definitions.h" SINK_DEBUG_AREA("test") @@ -34,6 +35,9 @@ using namespace Sink; void Sink::Test::initTest() { + auto logIniFile = Sink::configLocation() + "/log.ini"; + auto areaAutocompletionFile = Sink::dataLocation() + "/debugAreas.ini"; + setTestModeEnabled(true); // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).removeRecursively(); @@ -48,6 +52,30 @@ void Sink::Test::initTest() // qDebug() << "Removing " << QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); QDir(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)).removeRecursively(); Log::setPrimaryComponent("test"); + + //We copy those files so we can control debug output from outside the test with sinksh + { + QFile file(logIniFile); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Failed to open the file: " << logIniFile; + } + QDir dir; + dir.mkpath(Sink::configLocation()); + if (!file.copy(Sink::configLocation() + "/log.ini")) { + qWarning() << "Failed to move the file: " << Sink::configLocation() + "/log.ini"; + } + } + { + QFile file(areaAutocompletionFile); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Failed to open the file: " << logIniFile; + } + QDir dir; + dir.mkpath(Sink::dataLocation()); + if (!file.copy(Sink::dataLocation() + "/debugAreas.ini")) { + qWarning() << "Failed to move the file: " << Sink::configLocation() + "/log.ini"; + } + } } void Sink::Test::setTestModeEnabled(bool enabled) diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp index d9af453..ef695b3 100644 --- a/examples/imapresource/tests/imapserverproxytest.cpp +++ b/examples/imapresource/tests/imapserverproxytest.cpp @@ -28,7 +28,6 @@ private slots: QTcpSocket socket; socket.connectToHost("localhost", 993); QVERIFY(socket.waitForConnected(200)); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); system("resetmailbox.sh"); } diff --git a/examples/mailtransportresource/tests/mailtransporttest.cpp b/examples/mailtransportresource/tests/mailtransporttest.cpp index 3ce5f82..fdd591b 100644 --- a/examples/mailtransportresource/tests/mailtransporttest.cpp +++ b/examples/mailtransportresource/tests/mailtransporttest.cpp @@ -33,7 +33,6 @@ private slots: void initTestCase() { Test::initTest(); - Log::setDebugOutputLevel(Sink::Log::Trace); auto resource = createResource(); QVERIFY(!resource.identifier().isEmpty()); VERIFYEXEC(Store::create(resource)); diff --git a/sinksh/syntax_modules/sink_trace.cpp b/sinksh/syntax_modules/sink_trace.cpp index d480254..8bd52a0 100644 --- a/sinksh/syntax_modules/sink_trace.cpp +++ b/sinksh/syntax_modules/sink_trace.cpp @@ -31,6 +31,7 @@ #include "sinksh_utils.h" #include "state.h" #include "syntaxtree.h" +#include "iostream" namespace SinkTrace { @@ -38,22 +39,24 @@ namespace SinkTrace bool traceOff(const QStringList &args, State &state) { Sink::Log::setDebugOutputLevel(Sink::Log::Log); - qDebug() << "Turned trace off: " << args; + std::cout << "Turned trace off." << std::endl; return true; } bool traceOn(const QStringList &args, State &state) { - if (args.isEmpty()) { - state.printError(QObject::tr("Specifiy a debug area to trace: ") + Sink::Log::debugAreas().toList().join(", ")); - return false; - } Sink::Log::setDebugOutputLevel(Sink::Log::Trace); - QByteArrayList filter; - for (const auto &arg : args) { - filter << arg.toLatin1(); + if (args.isEmpty() || (args.size() == 1 && args.first() == "*")) { + Sink::Log::setDebugOutputFilter(Sink::Log::Area, QByteArrayList()); + std::cout << "Set trace filter to: *" << std::endl; + } else { + QByteArrayList filter; + for (const auto &arg : args) { + filter << arg.toLatin1(); + } + Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter); + std::cout << "Set trace filter to: " << filter.join(", ").toStdString() << std::endl; } - Sink::Log::setDebugOutputFilter(Sink::Log::Area, filter); return true; } diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp index 5a66305..d12e7f4 100644 --- a/tests/accountstest.cpp +++ b/tests/accountstest.cpp @@ -17,7 +17,6 @@ private slots: void initTestCase() { Sink::Test::initTest(); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } void init() diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index ec74cbd..ed5a9b5 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -93,7 +93,6 @@ private slots: { Sink::FacadeFactory::instance().resetFactory(); ResourceConfig::clear(); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } void testLoad() diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index d41f235..0907b1d 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -30,7 +30,6 @@ private slots: void initTestCase() { Sink::Test::initTest(); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); DummyResource::removeFromDisk("org.kde.dummy.instance1"); diff --git a/tests/genericfacadetest.cpp b/tests/genericfacadetest.cpp index 8336875..0267dac 100644 --- a/tests/genericfacadetest.cpp +++ b/tests/genericfacadetest.cpp @@ -8,6 +8,7 @@ #include #include #include +#include // Replace with something different #include "event_generated.h" @@ -23,10 +24,9 @@ class GenericFacadeTest : public QObject { Q_OBJECT private slots: - - void init() + void initTestCase() { - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + Sink::Test::initTest(); } void testLoad() diff --git a/tests/genericresourcetest.cpp b/tests/genericresourcetest.cpp index 7474cbf..fe2c146 100644 --- a/tests/genericresourcetest.cpp +++ b/tests/genericresourcetest.cpp @@ -27,7 +27,6 @@ private slots: void init() { Sink::GenericResource::removeFromDisk("org.kde.test.instance1"); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } /// Ensure the resource can process messages diff --git a/tests/inspectiontest.cpp b/tests/inspectiontest.cpp index 38bf23d..8f2c50f 100644 --- a/tests/inspectiontest.cpp +++ b/tests/inspectiontest.cpp @@ -19,7 +19,6 @@ class InspectionTest : public QObject private slots: void initTestCase() { - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); diff --git a/tests/maildirsyncbenchmark.cpp b/tests/maildirsyncbenchmark.cpp index 06c5ab1..8b1a9d7 100644 --- a/tests/maildirsyncbenchmark.cpp +++ b/tests/maildirsyncbenchmark.cpp @@ -61,7 +61,6 @@ private slots: { targetPath = tempDir.path() + "/maildir1"; - Sink::Log::setDebugOutputLevel(Sink::Log::Log); MaildirResource::removeFromDisk("org.kde.maildir.test1"); Sink::ApplicationDomain::SinkResource resource; resource.setProperty("identifier", "org.kde.maildir.test1"); diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index 4401f27..4b797c8 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp @@ -37,7 +37,6 @@ void MailSyncTest::initTestCase() { Test::initTest(); QVERIFY(isBackendAvailable()); - Log::setDebugOutputLevel(Sink::Log::Trace); resetTestEnvironment(); auto resource = createResource(); QVERIFY(!resource.identifier().isEmpty()); diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index 0537175..2547536 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp @@ -37,7 +37,6 @@ void MailTest::initTestCase() { Test::initTest(); QVERIFY(isBackendAvailable()); - Log::setDebugOutputLevel(Sink::Log::Trace); resetTestEnvironment(); auto resource = createResource(); QVERIFY(!resource.identifier().isEmpty()); diff --git a/tests/messagequeuetest.cpp b/tests/messagequeuetest.cpp index a8d0d4d..27dd12b 100644 --- a/tests/messagequeuetest.cpp +++ b/tests/messagequeuetest.cpp @@ -7,6 +7,7 @@ #include "storage.h" #include "messagequeue.h" #include "log.h" +#include "test.h" SINK_DEBUG_AREA("messagequeuetest") @@ -19,7 +20,7 @@ class MessageQueueTest : public QObject private slots: void initTestCase() { - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); + Sink::Test::initTest(); Sink::Storage store(Sink::Store::storageLocation(), "org.kde.dummy.testqueue", Sink::Storage::ReadWrite); store.removeFromDisk(); } diff --git a/tests/modelinteractivitytest.cpp b/tests/modelinteractivitytest.cpp index c55a1db..d13cdf7 100644 --- a/tests/modelinteractivitytest.cpp +++ b/tests/modelinteractivitytest.cpp @@ -51,7 +51,6 @@ private slots: void initTestCase() { Sink::Test::initTest(); - Sink::Log::setDebugOutputLevel(Sink::Log::Warning); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); Sink::Store::removeDataFromDisk(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished(); } diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index fc23cc9..65d4b49 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp @@ -190,7 +190,6 @@ class PipelineTest : public QObject private slots: void initTestCase() { - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); Sink::AdaptorFactoryRegistry::instance().registerFactory("test"); } diff --git a/tests/querytest.cpp b/tests/querytest.cpp index 6d7746e..95c22b3 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -23,7 +23,6 @@ private slots: void initTestCase() { Sink::Test::initTest(); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); auto factory = Sink::ResourceFactory::load("org.kde.dummy"); QVERIFY(factory); ResourceConfig::addResource("org.kde.dummy.instance1", "org.kde.dummy"); diff --git a/tests/resourceconfigtest.cpp b/tests/resourceconfigtest.cpp index d5f98d3..021d042 100644 --- a/tests/resourceconfigtest.cpp +++ b/tests/resourceconfigtest.cpp @@ -24,7 +24,6 @@ private slots: Sink::Test::initTest(); Sink::FacadeFactory::instance().resetFactory(); ResourceConfig::clear(); - Sink::Log::setDebugOutputLevel(Sink::Log::Trace); } void resourceManagement() diff --git a/tests/testaccounttest.cpp b/tests/testaccounttest.cpp index c630846..078e7a0 100644 --- a/tests/testaccounttest.cpp +++ b/tests/testaccounttest.cpp @@ -20,7 +20,6 @@ private slots: { // Sink::FacadeFactory::instance().resetFactory(); // ResourceConfig::clear(); - Log::setDebugOutputLevel(Sink::Log::Trace); Test::initTest(); } -- cgit v1.2.3