Show expected images side-by-side rather than creating one MD file per

image set
This commit is contained in:
sabrina-shanman 2019-08-26 10:49:16 -07:00
parent 5e3777999d
commit 1ae66c6c10

View file

@ -757,63 +757,67 @@ bool TestCreator::createMDFile(const QString& directory) {
QDir qDirectory(directory); QDir qDirectory(directory);
QString mdFilename(directory + "/" + "test.md");
QFile mdFile(mdFilename);
if (!mdFile.open(QIODevice::WriteOnly)) {
QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "Failed to create file " + mdFilename);
// TODO: Don't just exit
exit(-1);
}
QTextStream stream(&mdFile);
QString testName = testScriptLines.title;
stream << "# " << testName << "\n";
stream << "## Run this script URL: [Manual](./test.js?raw=true) [Auto](./testAuto.js?raw=true)(from menu/Edit/Open and Run scripts from URL...)." << "\n\n";
stream << "## Preconditions" << "\n";
stream << "- In an empty region of a domain with editing rights." << "\n";
stream << "\n";
// ExpectedImage_00000.png OR ExpectedImage_some_stu-ff_00000.png // ExpectedImage_00000.png OR ExpectedImage_some_stu-ff_00000.png
const QRegularExpression firstExpectedImage("^ExpectedImage(_[-_\\w]*)?_00000\\.png$"); const QRegularExpression firstExpectedImage("^ExpectedImage(_[-_\\w]*)?_00000\\.png$");
for (const auto& potentialImageFile : qDirectory.entryInfoList()) {
if (potentialImageFile.isDir()) {
continue;
}
auto firstExpectedImageMatch = firstExpectedImage.match(potentialImageFile.fileName()); stream << "## Steps\n";
if (!firstExpectedImageMatch.hasMatch()) { stream << "Press '" + ADVANCE_KEY + "' key to advance step by step\n\n"; // note apostrophes surrounding 'ADVANCE_KEY'
continue; int snapShotIndex { 0 };
} for (size_t i = 0; i < testScriptLines.stepList.size(); ++i) {
stream << "### Step " << QString::number(i + 1) << "\n";
stream << "- " << testScriptLines.stepList[i]->text << "\n";
if ((i + 1 < testScriptLines.stepList.size()) && testScriptLines.stepList[i]->takeSnapshot) {
for (const auto& potentialImageFile : qDirectory.entryInfoList()) {
if (potentialImageFile.isDir()) {
continue;
}
QString testDescriptor = firstExpectedImageMatch.captured(1); auto firstExpectedImageMatch = firstExpectedImage.match(potentialImageFile.fileName());
auto filterString = QString(testDescriptor).replace("_", ".").replace("-", ","); if (!firstExpectedImageMatch.hasMatch()) {
TestFilter descriptorAsFilter(filterString); continue;
}
QString mdFilename(directory + "/" + "test" + testDescriptor + ".md"); QString testDescriptor = firstExpectedImageMatch.captured(1);
QFile mdFile(mdFilename); auto filterString = QString(testDescriptor).replace("_", ".").replace("-", ",");
if (!mdFile.open(QIODevice::WriteOnly)) { TestFilter descriptorAsFilter(filterString);
QMessageBox::critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "Failed to create file " + mdFilename); if (descriptorAsFilter.isValid()) {
// TODO: Don't just exit stream << "- Expected image on ";
exit(-1); stream << (descriptorAsFilter.allowedTiers.empty() ? "any" : joinVector(descriptorAsFilter.allowedTiers, "/")) << " tier, ";
} stream << (descriptorAsFilter.allowedOperatingSystems.empty() ? "any" : joinVector(descriptorAsFilter.allowedOperatingSystems, "/")) << " OS, ";
stream << (descriptorAsFilter.allowedGPUs.empty() ? "any" : joinVector(descriptorAsFilter.allowedGPUs, "/")) << " GPU";
QTextStream stream(&mdFile); stream << ":";
} else {
QString testName = testScriptLines.title; // Fall back to displaying file name
stream << "# " << testName << "\n"; stream << "ExpectedImage" << testDescriptor << "_" << QString::number(snapShotIndex).rightJustified(5, '0') << ".png";
}
stream << "## Run this script URL: [Manual](./test.js?raw=true) [Auto](./testAuto.js?raw=true)(from menu/Edit/Open and Run scripts from URL...)." << "\n\n"; stream << "\n";
stream << "## Preconditions" << "\n";
stream << "- In an empty region of a domain with editing rights." << "\n";
stream << "- Tier: " << (descriptorAsFilter.allowedTiers.empty() ? "any" : joinVector(descriptorAsFilter.allowedTiers, ", ")) << "\n";
stream << "- OS: " << (descriptorAsFilter.allowedOperatingSystems.empty() ? "any" : joinVector(descriptorAsFilter.allowedOperatingSystems, ", ")) << "\n";
stream << "- GPU: " << (descriptorAsFilter.allowedGPUs.empty() ? "any" : joinVector(descriptorAsFilter.allowedGPUs, ", ")) << "\n";
if (!descriptorAsFilter.isValid()) {
stream << "\nWarning: The profile preconditions were unsuccessfully read from the expected image name and may be incorrect. Error message: " << descriptorAsFilter.getError() << "\n";
}
stream << "\n";
stream << "## Steps\n";
stream << "Press '" + ADVANCE_KEY + "' key to advance step by step\n\n"; // note apostrophes surrounding 'ADVANCE_KEY'
int snapShotIndex { 0 };
for (size_t i = 0; i < testScriptLines.stepList.size(); ++i) {
stream << "### Step " << QString::number(i + 1) << "\n";
stream << "- " << testScriptLines.stepList[i]->text << "\n";
if ((i + 1 < testScriptLines.stepList.size()) && testScriptLines.stepList[i]->takeSnapshot) {
stream << "- ![](./ExpectedImage" << testDescriptor << "_" << QString::number(snapShotIndex).rightJustified(5, '0') << ".png)\n"; stream << "- ![](./ExpectedImage" << testDescriptor << "_" << QString::number(snapShotIndex).rightJustified(5, '0') << ".png)\n";
++snapShotIndex;
} }
++snapShotIndex;
} }
mdFile.close();
} }
mdFile.close();
foreach (auto test, testScriptLines.stepList) { foreach (auto test, testScriptLines.stepList) {
delete test; delete test;
} }