RegTestRunner : Add removeDirectoryAndFilesRecursively

This commit is contained in:
Magne Sjaastad 2018-08-10 08:23:08 +02:00
parent 8b310e4cca
commit e21fe9b706
3 changed files with 60 additions and 22 deletions

View File

@ -32,13 +32,15 @@
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RiuPlotMainWindow.h"
#include "RiuMainWindow.h"
#include "RiuPlotMainWindow.h"
#include "RiuViewer.h"
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
#include "cafUtils.h"
#include <QDateTime>
#include <QDebug>
#include <QDesktopServices>
@ -153,13 +155,20 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
{
QDir testCaseFolder(folderList[i].filePath());
QDir genDir(testCaseFolder.filePath(generatedFolderName));
removeDirectoryWithContent(genDir);
{
QDir genDir(testCaseFolder.filePath(generatedFolderName));
removeDirectoryWithContent(genDir);
}
QDir diffDir(testCaseFolder.filePath(diffFolderName));
removeDirectoryWithContent(diffDir);
{
QDir diffDir(testCaseFolder.filePath(diffFolderName));
removeDirectoryWithContent(diffDir);
}
QDir baseDir(testCaseFolder.filePath(baseFolderName));
{
QDir generatedFiles(testCaseFolder.filePath(RegTestNames::generatedFilesFolderName));
removeDirectoryWithContent(generatedFiles);
}
}
// Generate html report
@ -216,12 +225,6 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
QFileInfoList commandFileEntries = testCaseFolder.entryInfoList(filterList);
if (!commandFileEntries.empty())
{
{
QString generatedFilesFolderName = testCaseFolder.filePath(RegTestNames::generatedFilesFolderName);
QDir genDir(generatedFilesFolderName);
removeDirectoryWithContent(genDir);
}
QString currentApplicationPath = QDir::current().absolutePath();
// Set current path to the folder containing the command file, as this is required when using file references
@ -268,22 +271,26 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
html += "<table>\n";
html += " <tr>\n";
html += " <td colspan=\"3\" bgcolor=\"darkblue\" height=\"40\"> <b><font color=\"white\" size=\"3\"> " + headerText + " </font></b> </td>\n";
html +=
" <td colspan=\"3\" bgcolor=\"darkblue\" height=\"40\"> <b><font color=\"white\" size=\"3\"> " +
headerText + " </font></b> </td>\n";
html += " </tr>\n";
textFileCompare.runComparison(baseFilesFolderName, generatedFilesFolderName);
QString diff = textFileCompare.diffOutput();
if (diff.isEmpty())
{
html += " <tr>\n";
html += " <td colspan=\"3\" bgcolor=\"lightgray\"> <font color=\"green\">No text diff detected</font> </td> \n";
html += " <td colspan=\"3\" bgcolor=\"lightgray\"> <font color=\"green\">No text diff "
"detected</font> </td> \n";
html += " </tr>\n";
}
else
{
html += " <tr>\n";
html += " <td colspan=\"3\" bgcolor=\"lightgray\"> <font color=\"red\">Text diff detected - output from diff tool : </font> </td> \n";
html += " <td colspan=\"3\" bgcolor=\"lightgray\"> <font color=\"red\">Text diff detected - "
"output from diff tool : </font> </td> \n";
html += " </tr>\n";
}
@ -382,12 +389,7 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
//--------------------------------------------------------------------------------------------------
void RiaRegressionTestRunner::removeDirectoryWithContent(QDir& dirToDelete)
{
QStringList files = dirToDelete.entryList();
for (int fIdx = 0; fIdx < files.size(); ++fIdx)
{
dirToDelete.remove(files[fIdx]);
}
dirToDelete.rmdir(".");
caf::Utils::removeDirectoryAndFilesRecursively(dirToDelete.absolutePath());
}
//--------------------------------------------------------------------------------------------------

View File

@ -280,4 +280,39 @@ bool Utils::isStringMatch(const QString& filterString, const QString& value)
return searcher.exactMatch(value);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool Utils::removeDirectoryAndFilesRecursively(const QString& dirName)
{
bool result = true;
QDir dir(dirName);
if (dir.exists())
{
QFileInfoList fileInfoList =
dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst);
for (const auto& fileInfo : fileInfoList)
{
if (fileInfo.isDir())
{
result = removeDirectoryAndFilesRecursively(fileInfo.absoluteFilePath());
}
else
{
result = QFile::remove(fileInfo.absoluteFilePath());
}
if (!result)
{
return result;
}
}
result = QDir().rmdir(dirName);
}
return result;
}
} // namespace caf

View File

@ -69,6 +69,7 @@ public:
static bool isFolderWritable(const QString& folderName);
static bool isStringMatch(const QString& filterString, const QString& value);
static bool removeDirectoryAndFilesRecursively(const QString& dirName);
};
}