mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-12 08:25:03 -05:00
#3472 Regression Test : Use git to produce diff of exported files from ResInsight
This commit is contained in:
1 parent
85197661fe
commit
2f61681642
7 files changed
+129
-17
No files matched your search
@@ -55,7 +55,7 @@ std::string removeCommonStart(const std::string& mask, const std::string& filena
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiaImageCompareReporter::generateHTMLReport(const std::string& fileName)
|
void RiaImageCompareReporter::generateHTMLReport(const std::string& fileName, const std::string& diff2htmlHeaderText)
|
||||||
{
|
{
|
||||||
if (m_directorySets.size() == 0) return;
|
if (m_directorySets.size() == 0) return;
|
||||||
|
|
||||||
@@ -70,16 +70,18 @@ void RiaImageCompareReporter::generateHTMLReport(const std::string& fileName)
|
|||||||
|
|
||||||
html += "<html>\n";
|
html += "<html>\n";
|
||||||
html += "<head>\n";
|
html += "<head>\n";
|
||||||
html += "<title>Regression-Test Report</title>\n";
|
|
||||||
|
|
||||||
if (m_showInteractiveDiff)
|
if (m_showInteractiveDiff)
|
||||||
{
|
{
|
||||||
html += cssString();
|
html += cssString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html += diff2htmlHeaderText;
|
||||||
|
|
||||||
html += "</head>\n";
|
html += "</head>\n";
|
||||||
html += "\n";
|
html += "\n";
|
||||||
html += "<body>\n";
|
html += "<body>\n";
|
||||||
|
html += "<title>Regression-Test Report</title>\n";
|
||||||
html += "\n";
|
html += "\n";
|
||||||
|
|
||||||
for (size_t dsIdx = 0; dsIdx < m_directorySets.size(); ++dsIdx)
|
for (size_t dsIdx = 0; dsIdx < m_directorySets.size(); ++dsIdx)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public:
|
|||||||
virtual ~RiaImageCompareReporter();
|
virtual ~RiaImageCompareReporter();
|
||||||
|
|
||||||
void addImageDirectoryComparisonSet(const std::string& title, const std::string& baseImageDir, const std::string& newImagesDir, const std::string& diffImagesDir );
|
void addImageDirectoryComparisonSet(const std::string& title, const std::string& baseImageDir, const std::string& newImagesDir, const std::string& diffImagesDir );
|
||||||
void generateHTMLReport(const std::string& filenName);
|
void generateHTMLReport(const std::string& filenName, const std::string& pathToDiff2html);
|
||||||
|
|
||||||
void showInteractiveOnly();
|
void showInteractiveOnly();
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ RiaRegressionTest::RiaRegressionTest(void)
|
|||||||
CAF_PDM_InitFieldNoDefault(&folderContainingDiffTool, "folderContainingDiffTool", "Folder containing <b>diff</b>", "", "Location of diff tool used for text compare", "");
|
CAF_PDM_InitFieldNoDefault(&folderContainingDiffTool, "folderContainingDiffTool", "Folder containing <b>diff</b>", "", "Location of diff tool used for text compare", "");
|
||||||
folderContainingDiffTool.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
folderContainingDiffTool.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
||||||
|
|
||||||
|
CAF_PDM_InitFieldNoDefault(&folderContainingGitTool, "folderContainingGitTool", "Folder containing <b>git</b>", "", "Location of git tool used for text compare", "");
|
||||||
|
folderContainingGitTool.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
||||||
|
|
||||||
CAF_PDM_InitFieldNoDefault(®ressionTestFolder, "regressionTestFolder", "Regression Test Folder", "", "", "");
|
CAF_PDM_InitFieldNoDefault(®ressionTestFolder, "regressionTestFolder", "Regression Test Folder", "", "", "");
|
||||||
regressionTestFolder.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
regressionTestFolder.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
||||||
|
|
||||||
@@ -74,7 +77,7 @@ void RiaRegressionTest::readSettingsFromApplicationStore()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiaRegressionTest::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
|
void RiaRegressionTest::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
|
||||||
{
|
{
|
||||||
if (field == &folderContainingDiffTool || field == &folderContainingCompareTool || field == ®ressionTestFolder)
|
if (field == &folderContainingDiffTool || field == &folderContainingCompareTool || field == ®ressionTestFolder || field == &folderContainingGitTool)
|
||||||
{
|
{
|
||||||
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>(attribute);
|
caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast<caf::PdmUiFilePathEditorAttribute*>(attribute);
|
||||||
if (myAttr)
|
if (myAttr)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
caf::PdmField<QString> folderContainingCompareTool;
|
caf::PdmField<QString> folderContainingCompareTool;
|
||||||
caf::PdmField<QString> folderContainingDiffTool;
|
caf::PdmField<QString> folderContainingDiffTool;
|
||||||
|
caf::PdmField<QString> folderContainingGitTool;
|
||||||
caf::PdmField<QString> regressionTestFolder;
|
caf::PdmField<QString> regressionTestFolder;
|
||||||
caf::PdmField<QString> testFilter;
|
caf::PdmField<QString> testFilter;
|
||||||
caf::PdmField<bool> showInteractiveDiffImages;
|
caf::PdmField<bool> showInteractiveDiffImages;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "RiaRegressionTestRunner.h"
|
#include "RiaRegressionTestRunner.h"
|
||||||
|
|
||||||
#include "RiaApplication.h"
|
#include "RiaApplication.h"
|
||||||
|
#include "RiaGitDiff.h"
|
||||||
#include "RiaImageCompareReporter.h"
|
#include "RiaImageCompareReporter.h"
|
||||||
#include "RiaImageFileCompare.h"
|
#include "RiaImageFileCompare.h"
|
||||||
#include "RiaLogging.h"
|
#include "RiaLogging.h"
|
||||||
@@ -103,17 +104,14 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
|
|||||||
|
|
||||||
QString currentApplicationPath = QDir::currentPath();
|
QString currentApplicationPath = QDir::currentPath();
|
||||||
|
|
||||||
|
RiaRegressionTest regressionTestConfig;
|
||||||
|
regressionTestConfig.readSettingsFromApplicationStore();
|
||||||
|
if (!regressionTestConfig.folderContainingCompareTool().isEmpty())
|
||||||
{
|
{
|
||||||
RiaRegressionTest regressionTestConfig;
|
// Windows Only : The image compare tool requires current working directory to be at the folder
|
||||||
regressionTestConfig.readSettingsFromApplicationStore();
|
// containing the image compare tool
|
||||||
|
|
||||||
if (!regressionTestConfig.folderContainingCompareTool().isEmpty())
|
QDir::setCurrent(regressionTestConfig.folderContainingCompareTool());
|
||||||
{
|
|
||||||
// Windows Only : The image compare tool requires current working directory to be at the folder
|
|
||||||
// containing the image compare tool
|
|
||||||
|
|
||||||
QDir::setCurrent(regressionTestConfig.folderContainingCompareTool());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString generatedFolderName = RegTestNames::generatedFolderName;
|
QString generatedFolderName = RegTestNames::generatedFolderName;
|
||||||
@@ -212,7 +210,9 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString htmlReportFileName = testDir.filePath(RegTestNames::reportFileName);
|
QString htmlReportFileName = testDir.filePath(RegTestNames::reportFileName);
|
||||||
imageCompareReporter.generateHTMLReport(htmlReportFileName.toStdString());
|
|
||||||
|
QString htmldiff2htmlText = diff2htmlHeaderText(testRootPath);
|
||||||
|
imageCompareReporter.generateHTMLReport(htmlReportFileName.toStdString(), htmldiff2htmlText.toStdString());
|
||||||
|
|
||||||
// Open HTML report
|
// Open HTML report
|
||||||
QDesktopServices::openUrl(htmlReportFileName);
|
QDesktopServices::openUrl(htmlReportFileName);
|
||||||
@@ -256,9 +256,6 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
|
|||||||
{
|
{
|
||||||
QString html;
|
QString html;
|
||||||
|
|
||||||
RiaRegressionTest regressionTestConfig;
|
|
||||||
regressionTestConfig.readSettingsFromApplicationStore();
|
|
||||||
|
|
||||||
RiaTextFileCompare textFileCompare(regressionTestConfig.folderContainingDiffTool());
|
RiaTextFileCompare textFileCompare(regressionTestConfig.folderContainingDiffTool());
|
||||||
|
|
||||||
QString baseFilesFolderName = testCaseFolder.filePath(RegTestNames::baseFilesFolderName);
|
QString baseFilesFolderName = testCaseFolder.filePath(RegTestNames::baseFilesFolderName);
|
||||||
@@ -379,6 +376,61 @@ void RiaRegressionTestRunner::runRegressionTest(const QString& testRootPath, con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoke git diff
|
||||||
|
|
||||||
|
{
|
||||||
|
QString folderContainingGit = regressionTestConfig.folderContainingGitTool();
|
||||||
|
RiaGitDiff gitDiff(folderContainingGit);
|
||||||
|
gitDiff.executeDiff(testRootPath);
|
||||||
|
|
||||||
|
QString diffText = gitDiff.diffOutput();
|
||||||
|
if (!diffText.isEmpty())
|
||||||
|
{
|
||||||
|
QFile file(htmlReportFileName);
|
||||||
|
if (file.open(QIODevice::Append | QIODevice::Text))
|
||||||
|
{
|
||||||
|
QTextStream stream(&file);
|
||||||
|
|
||||||
|
QString divSectionForDiff = R"(
|
||||||
|
<div id = "destination-elem-id"[innerHtml] = "outputHtml">
|
||||||
|
original
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)";
|
||||||
|
stream << divSectionForDiff;
|
||||||
|
stream << "</body>";
|
||||||
|
|
||||||
|
{
|
||||||
|
QString generateDiffString = R"(
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function generateDiff() {
|
||||||
|
return `
|
||||||
|
)";
|
||||||
|
|
||||||
|
generateDiffString += diffText;
|
||||||
|
|
||||||
|
generateDiffString += R"(
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
)";
|
||||||
|
|
||||||
|
generateDiffString += R"(
|
||||||
|
var diffHtml = Diff2Html.getPrettyHtml(
|
||||||
|
generateDiff(),
|
||||||
|
{inputFormat: 'diff', showFiles: true, matching: 'lines', outputFormat: 'side-by-side'}
|
||||||
|
);
|
||||||
|
|
||||||
|
document.getElementById("destination-elem-id").innerHTML = diffHtml;
|
||||||
|
</script>
|
||||||
|
</html>
|
||||||
|
)";
|
||||||
|
stream << generateDiffString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RiaLogging::info("\n");
|
RiaLogging::info("\n");
|
||||||
logInfoTextWithTimeInSeconds(timeStamp, "Completed regression tests");
|
logInfoTextWithTimeInSeconds(timeStamp, "Completed regression tests");
|
||||||
|
|
||||||
@@ -483,6 +535,41 @@ QSize RiaRegressionTestRunner::regressionDefaultImageSize()
|
|||||||
return QSize(1000, 745);
|
return QSize(1000, 745);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RiaRegressionTestRunner::diff2htmlHeaderText(const QString& testRootPath)
|
||||||
|
{
|
||||||
|
QString html;
|
||||||
|
|
||||||
|
QString oldProjPath = QDir::fromNativeSeparators(testRootPath);
|
||||||
|
QStringList pathFolders = oldProjPath.split("/", QString::KeepEmptyParts);
|
||||||
|
|
||||||
|
QString path;
|
||||||
|
for (const auto& f : pathFolders)
|
||||||
|
{
|
||||||
|
path += f;
|
||||||
|
path += "/";
|
||||||
|
if (f == "ResInsight-regression-test") break;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
html = R"(
|
||||||
|
<!-- CSS -->
|
||||||
|
<link rel = "stylesheet" type = "text/css" href = "dist/diff2html.css">
|
||||||
|
|
||||||
|
<!--Javascripts-->
|
||||||
|
<script type = "text/javascript" src = "dist/diff2html.js"></script>
|
||||||
|
<script type = "text/javascript" src = "dist/diff2html-ui.js"></script>
|
||||||
|
)";
|
||||||
|
|
||||||
|
QString pathToDiff2html = path + "diff2html/dist/";
|
||||||
|
html = html.replace("dist/", pathToDiff2html);
|
||||||
|
}
|
||||||
|
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ private:
|
|||||||
static void regressionTestConfigureProject();
|
static void regressionTestConfigureProject();
|
||||||
static void resizeMaximizedPlotWindows();
|
static void resizeMaximizedPlotWindows();
|
||||||
static QSize regressionDefaultImageSize();
|
static QSize regressionDefaultImageSize();
|
||||||
|
static QString diff2htmlHeaderText(const QString& testRootPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_rootPath;
|
const QString m_rootPath;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "RiaGitDiff.h"
|
||||||
#include "RiaRegressionTest.h"
|
#include "RiaRegressionTest.h"
|
||||||
#include "RiaTestDataDirectory.h"
|
#include "RiaTestDataDirectory.h"
|
||||||
#include "RiaTextFileCompare.h"
|
#include "RiaTextFileCompare.h"
|
||||||
@@ -66,3 +67,20 @@ TEST(RiaTextFileCompareTest, BasicCompareError)
|
|||||||
QString error = compare.errorMessage();
|
QString error = compare.errorMessage();
|
||||||
EXPECT_FALSE(error.isEmpty());
|
EXPECT_FALSE(error.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
TEST(DISABLED_RiaGitDiffTest, BasicCompare)
|
||||||
|
{
|
||||||
|
RiaRegressionTest regTestConfig;
|
||||||
|
regTestConfig.readSettingsFromApplicationStore();
|
||||||
|
QString folderContainingDiff = regTestConfig.folderContainingGitTool();
|
||||||
|
|
||||||
|
RiaGitDiff compare(folderContainingDiff);
|
||||||
|
|
||||||
|
QString baseFolder = QString("d:/gitroot-ceesol/ResInsight-regression-test/ProjectFiles/CommandFileTests");
|
||||||
|
|
||||||
|
compare.executeDiff(baseFolder);
|
||||||
|
compare.diffOutput();
|
||||||
|
}
|
||||||
Reference in new issue
Block a user