From 1998405dbbf9bf276bc208ddd15a0c05c17ea2bc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 14 Mar 2021 21:35:56 +0100 Subject: [PATCH] [libcalamaresui] Fix up test for logfile - this test would fail if the logfile already exists for any reason (including "I just ran the test") - remove the file before expecting an empty logfile - improve messages; a missing logfile is not a "things cannot work" situation, it's a warning --- src/libcalamaresui/utils/Paste.cpp | 5 +++-- src/libcalamaresui/utils/TestPaste.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libcalamaresui/utils/Paste.cpp b/src/libcalamaresui/utils/Paste.cpp index ea20dc8b2..2f0cfa143 100644 --- a/src/libcalamaresui/utils/Paste.cpp +++ b/src/libcalamaresui/utils/Paste.cpp @@ -28,10 +28,11 @@ using namespace CalamaresUtils::Units; STATICTEST QByteArray logFileContents() { - QFile pasteSourceFile( Logger::logFile() ); + const QString name = Logger::logFile(); + QFile pasteSourceFile( name ); if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) { - cError() << "Could not open log file"; + cWarning() << "Could not open log file" << name; return QByteArray(); } QFileInfo fi( pasteSourceFile ); diff --git a/src/libcalamaresui/utils/TestPaste.cpp b/src/libcalamaresui/utils/TestPaste.cpp index ff75be02d..d21d6b81e 100644 --- a/src/libcalamaresui/utils/TestPaste.cpp +++ b/src/libcalamaresui/utils/TestPaste.cpp @@ -35,15 +35,16 @@ private Q_SLOTS: void TestPaste::testGetLogFile() { + QFile::remove( Logger::logFile() ); // This test assumes nothing **else** has set up logging yet - QByteArray b = logFileContents(); - QVERIFY( b.isEmpty() ); + QByteArray contentsOfLogfileBefore = logFileContents(); + QVERIFY( contentsOfLogfileBefore.isEmpty() ); Logger::setupLogLevel( Logger::LOGDEBUG ); Logger::setupLogfile(); - b = logFileContents(); - QVERIFY( !b.isEmpty() ); + QByteArray contentsOfLogfileAfterSetup = logFileContents(); + QVERIFY( !contentsOfLogfileAfterSetup.isEmpty() ); } void