From 8e063a600bc895be32cb9db3073183c7034cecc0 Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Tue, 10 Apr 2018 20:16:36 -0700 Subject: [PATCH 1/3] Added recursive creation of MD files. --- tools/auto-tester/src/Test.cpp | 44 +++++++++++++++++++++++-- tools/auto-tester/src/Test.h | 4 ++- tools/auto-tester/src/ui/AutoTester.cpp | 10 ++++-- tools/auto-tester/src/ui/AutoTester.h | 7 ++-- tools/auto-tester/src/ui/AutoTester.ui | 27 +++++++++++---- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 5d8b9115b8..9af5f3a079 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -304,7 +304,7 @@ void Test::createRecursiveScript() { } // This method creates a `testRecursive.js` script in every sub-folder. -void Test::createRecursiveScriptsRecursively() { +void Test::createAllRecursiveScripts() { // Select folder to start recursing from QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select the root folder for the recursive scripts", ".", QFileDialog::ShowDirsOnly); if (topLevelDirectory == "") { @@ -559,6 +559,44 @@ void Test::createMDFile() { return; } + createMDFile(testDirectory); +} + +void Test::createAllMDFiles() { + // Select folder to start recursing from + QString topLevelDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select the root folder for the MD files", ".", QFileDialog::ShowDirsOnly); + if (topLevelDirectory == "") { + return; + } + + // First test if top-level folder has a test.js file + const QString testPathname{ topLevelDirectory + "/" + TEST_FILENAME }; + QFileInfo fileInfo(testPathname); + if (fileInfo.exists()) { + createMDFile(topLevelDirectory); + } + + QDirIterator it(topLevelDirectory.toStdString().c_str(), QDirIterator::Subdirectories); + while (it.hasNext()) { + QString directory = it.next(); + + // Only process directories + QDir dir; + if (!isAValidDirectory(directory)) { + continue; + } + + const QString testPathname{ directory + "/" + TEST_FILENAME }; + QFileInfo fileInfo(testPathname); + if (fileInfo.exists()) { + createMDFile(directory); + } + } + + messageBox.information(0, "Success", "MD files have been created"); +} + +void Test::createMDFile(QString testDirectory) { // Verify folder contains test.js file QString testFileName(testDirectory + "/" + TEST_FILENAME); QFileInfo testFileInfo(testFileName); @@ -639,8 +677,8 @@ void Test::createMDFile() { int snapShotIndex { 0 }; for (size_t i = 0; i < testScriptLines.stepList.size(); ++i) { - stream << "### Step " << QString::number(i) << "\n"; - stream << "- " << testScriptLines.stepList[i + 1]->text << "\n"; + stream << "### Step " << QString::number(i + 1) << "\n"; + stream << "- " << testScriptLines.stepList[i]->text << "\n"; if (testScriptLines.stepList[i]->takeSnapshot) { stream << "- ![](./ExpectedImage_" << QString::number(snapShotIndex).rightJustified(5, '0') << ".png)\n"; ++snapShotIndex; diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 3d04b00df9..64923da729 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -45,11 +45,13 @@ public: void finishTestsEvaluation(bool interactiveMode, QProgressBar* progressBar); void createRecursiveScript(); - void createRecursiveScriptsRecursively(); + void createAllRecursiveScripts(); void createRecursiveScript(QString topLevelDirectory, bool interactiveMode); void createTest(); void createMDFile(); + void createAllMDFiles(); + void createMDFile(QString topLevelDirectory); bool compareImageLists(bool isInteractiveMode, QProgressBar* progressBar); diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index 9153365184..fd001cc774 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -28,8 +28,8 @@ void AutoTester::on_createRecursiveScriptButton_clicked() { test->createRecursiveScript(); } -void AutoTester::on_createRecursiveScriptsRecursivelyButton_clicked() { - test->createRecursiveScriptsRecursively(); +void AutoTester::on_createAllRecursiveScriptsButton_clicked() { + test->createAllRecursiveScripts(); } void AutoTester::on_createTestButton_clicked() { @@ -37,7 +37,11 @@ void AutoTester::on_createTestButton_clicked() { } void AutoTester::on_createMDFileButton_clicked() { - test->createMDFile(); + test->createMDFile(); +} + +void AutoTester::on_createAllMDFilesButton_clicked() { + test->createAllMDFiles(); } void AutoTester::on_closeButton_clicked() { diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/auto-tester/src/ui/AutoTester.h index 82ff3780e3..643286563c 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/auto-tester/src/ui/AutoTester.h @@ -28,10 +28,11 @@ public: private slots: void on_evaluateTestsButton_clicked(); void on_createRecursiveScriptButton_clicked(); - void on_createRecursiveScriptsRecursivelyButton_clicked(); + void on_createAllRecursiveScriptsButton_clicked(); void on_createTestButton_clicked(); - void on_createMDFileButton_clicked(); - void on_closeButton_clicked(); + void on_createMDFileButton_clicked(); + void on_createAllMDFilesButton_clicked(); + void on_closeButton_clicked(); void saveImage(int index); diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index 600de283ad..391bb61fd4 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -17,8 +17,8 @@ - 20 - 420 + 360 + 400 220 40 @@ -44,7 +44,7 @@ 20 - 255 + 285 220 40 @@ -70,7 +70,7 @@ 23 - 220 + 250 131 20 @@ -86,7 +86,7 @@ 20 - 310 + 340 255 23 @@ -105,14 +105,14 @@ - Create Recursive Scripts Recursively + Create all Recursive Scripts 20 - 90 + 80 220 40 @@ -121,6 +121,19 @@ Create MD file + + + + 20 + 130 + 220 + 40 + + + + Create all MD files + + From 60f4c6788faeddda9524936f98240a3b73703cfe Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Tue, 10 Apr 2018 23:04:56 -0700 Subject: [PATCH 2/3] Added creation of tests outline .MD file. --- tools/auto-tester/src/Test.cpp | 54 +++++++++++++++++++++++++ tools/auto-tester/src/Test.h | 2 + tools/auto-tester/src/ui/AutoTester.cpp | 4 ++ tools/auto-tester/src/ui/AutoTester.h | 1 + tools/auto-tester/src/ui/AutoTester.ui | 17 +++++++- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index 9af5f3a079..b5a0069701 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -688,6 +688,60 @@ void Test::createMDFile(QString testDirectory) { mdFile.close(); } +void Test::createTestsOutline() { + QString testsRootDirectory = QFileDialog::getExistingDirectory(nullptr, "Please select the tests root folder", ".", QFileDialog::ShowDirsOnly); + if (testsRootDirectory == "") { + return; + } + + const QString testsOutlineFilename { "testsOutline.md" }; + QString mdFilename(testsRootDirectory + "/" + testsOutlineFilename); + QFile mdFile(mdFilename); + if (!mdFile.open(QIODevice::WriteOnly)) { + messageBox.critical(0, "Internal error: " + QString(__FILE__) + ":" + QString::number(__LINE__), "Failed to create file " + mdFilename); + exit(-1); + } + + QTextStream stream(&mdFile); + + //Test title + stream << "# Outline of all tests\n"; + stream << "Directories with an appended (*) have an automatic test\n\n"; + + // We need to know our current depth, as this isn't given by QDirIterator + int rootDepth { testsRootDirectory.count('/') }; + + QDirIterator it(testsRootDirectory.toStdString().c_str(), QDirIterator::Subdirectories); + while (it.hasNext()) { + QString directory = it.next(); + + // Only process directories + QDir dir; + if (!isAValidDirectory(directory)) { + continue; + } + + // Ignore the utils directory + if (directory.right(5) == "utils") { + continue; + } + + int currentDepth = directory.count('/') - rootDepth; + QString prefix = QString(" ").repeated(2 * currentDepth - 1) + " - "; + stream << prefix; + stream << directory.right(directory.length() - directory.lastIndexOf("/") - 1); + QFileInfo fileInfo(directory + "/" + TEST_FILENAME); + if (fileInfo.exists()) { + stream << " (*)"; + } + stream << "\n"; + } + + mdFile.close(); + + messageBox.information(0, "Success", "Test outline file " + testsOutlineFilename + " has been created"); +} + void Test::copyJPGtoPNG(QString sourceJPGFullFilename, QString destinationPNGFullFilename) { QFile::remove(destinationPNGFullFilename); diff --git a/tools/auto-tester/src/Test.h b/tools/auto-tester/src/Test.h index 64923da729..e69459fef2 100644 --- a/tools/auto-tester/src/Test.h +++ b/tools/auto-tester/src/Test.h @@ -53,6 +53,8 @@ public: void createAllMDFiles(); void createMDFile(QString topLevelDirectory); + void createTestsOutline(); + bool compareImageLists(bool isInteractiveMode, QProgressBar* progressBar); QStringList createListOfAll_imagesInDirectory(QString imageFormat, QString pathToImageDirectory); diff --git a/tools/auto-tester/src/ui/AutoTester.cpp b/tools/auto-tester/src/ui/AutoTester.cpp index fd001cc774..21acfe9569 100644 --- a/tools/auto-tester/src/ui/AutoTester.cpp +++ b/tools/auto-tester/src/ui/AutoTester.cpp @@ -44,6 +44,10 @@ void AutoTester::on_createAllMDFilesButton_clicked() { test->createAllMDFiles(); } +void AutoTester::on_createTestsOutlineButton_clicked() { + test->createTestsOutline(); +} + void AutoTester::on_closeButton_clicked() { exit(0); } diff --git a/tools/auto-tester/src/ui/AutoTester.h b/tools/auto-tester/src/ui/AutoTester.h index 643286563c..1788e97177 100644 --- a/tools/auto-tester/src/ui/AutoTester.h +++ b/tools/auto-tester/src/ui/AutoTester.h @@ -32,6 +32,7 @@ private slots: void on_createTestButton_clicked(); void on_createMDFileButton_clicked(); void on_createAllMDFilesButton_clicked(); + void on_createTestsOutlineButton_clicked(); void on_closeButton_clicked(); void saveImage(int index); diff --git a/tools/auto-tester/src/ui/AutoTester.ui b/tools/auto-tester/src/ui/AutoTester.ui index 391bb61fd4..2eb1314481 100644 --- a/tools/auto-tester/src/ui/AutoTester.ui +++ b/tools/auto-tester/src/ui/AutoTester.ui @@ -57,7 +57,7 @@ 360 - 75 + 35 220 40 @@ -99,7 +99,7 @@ 360 - 140 + 100 220 40 @@ -134,6 +134,19 @@ Create all MD files + + + + 20 + 180 + 220 + 40 + + + + Create Tests Outline + + From c458b587ac9d45554d9b6cceddf86c2b4d6b5ece Mon Sep 17 00:00:00 2001 From: NissimHadar Date: Wed, 11 Apr 2018 16:50:27 -0700 Subject: [PATCH 3/3] Completed creation of testsOutline.md. --- tools/auto-tester/src/Test.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/auto-tester/src/Test.cpp b/tools/auto-tester/src/Test.cpp index b5a0069701..99f9025fdd 100644 --- a/tools/auto-tester/src/Test.cpp +++ b/tools/auto-tester/src/Test.cpp @@ -711,6 +711,7 @@ void Test::createTestsOutline() { // We need to know our current depth, as this isn't given by QDirIterator int rootDepth { testsRootDirectory.count('/') }; + // Each test is shown as the folder name linking to the matching GitHub URL, and the path to the associated test.md file QDirIterator it(testsRootDirectory.toStdString().c_str(), QDirIterator::Subdirectories); while (it.hasNext()) { QString directory = it.next(); @@ -726,12 +727,28 @@ void Test::createTestsOutline() { continue; } + // The prefix is the MarkDown prefix needed for correct indentation + // It consists of 2 spaces for each level of indentation, folled by a dash sign int currentDepth = directory.count('/') - rootDepth; QString prefix = QString(" ").repeated(2 * currentDepth - 1) + " - "; - stream << prefix; - stream << directory.right(directory.length() - directory.lastIndexOf("/") - 1); - QFileInfo fileInfo(directory + "/" + TEST_FILENAME); - if (fileInfo.exists()) { + + // The directory name appears after the last slash (we are assured there is at least 1). + QString directoryName = directory.right(directory.length() - directory.lastIndexOf("/") - 1); + + // autoTester is run on a clone of the repository. We use relative paths, so we can use both local disk and GitHub + // For a test in "D:/GitHub/hifi_tests/tests/content/entity/zone/ambientLightInheritance" the + // GitHub URL is "./content/entity/zone/ambientLightInheritance?raw=true" + QString partialPath = directory.right(directory.length() - (directory.lastIndexOf("/tests/") + QString("/tests").length() + 1)); + QString url = "./" + partialPath; + + stream << prefix << "[" << directoryName << "](" << url << "?raw=true" << ")"; + QFileInfo fileInfo1(directory + "/test.md"); + if (fileInfo1.exists()) { + stream << " [(test description)](" << url << "/test.md)"; + } + + QFileInfo fileInfo2(directory + "/" + TEST_FILENAME); + if (fileInfo2.exists()) { stream << " (*)"; } stream << "\n";