[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
main
Adriaan de Groot 4 years ago
parent cdbc5a7b4b
commit 1998405dbb

@ -28,10 +28,11 @@ using namespace CalamaresUtils::Units;
STATICTEST QByteArray STATICTEST QByteArray
logFileContents() logFileContents()
{ {
QFile pasteSourceFile( Logger::logFile() ); const QString name = Logger::logFile();
QFile pasteSourceFile( name );
if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) if ( !pasteSourceFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
{ {
cError() << "Could not open log file"; cWarning() << "Could not open log file" << name;
return QByteArray(); return QByteArray();
} }
QFileInfo fi( pasteSourceFile ); QFileInfo fi( pasteSourceFile );

@ -35,15 +35,16 @@ private Q_SLOTS:
void void
TestPaste::testGetLogFile() TestPaste::testGetLogFile()
{ {
QFile::remove( Logger::logFile() );
// This test assumes nothing **else** has set up logging yet // This test assumes nothing **else** has set up logging yet
QByteArray b = logFileContents(); QByteArray contentsOfLogfileBefore = logFileContents();
QVERIFY( b.isEmpty() ); QVERIFY( contentsOfLogfileBefore.isEmpty() );
Logger::setupLogLevel( Logger::LOGDEBUG ); Logger::setupLogLevel( Logger::LOGDEBUG );
Logger::setupLogfile(); Logger::setupLogfile();
b = logFileContents(); QByteArray contentsOfLogfileAfterSetup = logFileContents();
QVERIFY( !b.isEmpty() ); QVERIFY( !contentsOfLogfileAfterSetup.isEmpty() );
} }
void void

Loading…
Cancel
Save