Skip to content

Commit

Permalink
Tests: make it possible to run specific tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Dec 3, 2019
1 parent ee37f9f commit 91602ed
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions src/tests/src/main.cpp
Expand Up @@ -38,18 +38,54 @@ along with this program. If not, see <https://gnu.org/licenses>.

int main(int pArgC, char *pArgV[])
{
// Retrieve the requested tests, if any

QStringList requestedTests = QStringList();

for (int i = 1; i < pArgC; ++i) {
requestedTests << pArgV[i];
}

// The different groups of tests that are to be run
// Note: -1 for iMax because tests ends with our separator...

QString tests = OpenCOR::fileContents(":/tests").first();
QMap<QString, QStringList> testsGroups;
QStringList testItems = tests.split('|');
QString testGroup;
QString testTest;
bool addTest;
int nbOfTests = 0;

for (int i = 0, iMax = testItems.count()-1; i < iMax; i += 2) {
testGroup = testItems[i];
testTest = testItems[i+1];

if (pArgC == 1) {
addTest = true;
} else {
addTest = false;

for (const auto &requestedTest : requestedTests) {
QStringList requestedTestItems = requestedTest.split("::");
QString requestedTestGroup = requestedTestItems[0];
QString requestedTestTest = (requestedTestItems.count() > 1)?requestedTestItems[1].toLower():QString();

if ( (testGroup == requestedTestGroup)
&& ( requestedTestTest.isEmpty()
|| (testTest == requestedTestTest))) {
addTest = true;

break;
}
}
}

if (addTest) {
testsGroups.insert(testGroup, QStringList(testsGroups.value(testGroup)) << testTest);

testsGroups.insert(testGroup, QStringList(testsGroups.value(testGroup)) << testItems[i+1]);
++nbOfTests;
}
}

// On Windows, go to the directory that contains our plugins, so that we can
Expand Down Expand Up @@ -102,14 +138,23 @@ int main(int pArgC, char *pArgV[])

// Reporting

std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
if (nbOfTests != 0) {
std::cout << std::endl;
std::cout << std::endl;
std::cout << std::endl;
}

std::cout << "********* Reporting *********" << std::endl;
std::cout << std::endl;

if (failedTests.isEmpty()) {
std::cout << "All the tests passed!" << std::endl;
if (nbOfTests == 0) {
std::cout << "No tests were run!" << std::endl;
} else if (nbOfTests == 1) {
std::cout << "The test passed!" << std::endl;
} else {
std::cout << "All the tests passed!" << std::endl;
}
} else {
if (failedTests.count() == 1) {
std::cout << "The following test failed:" << std::endl;
Expand Down

0 comments on commit 91602ed

Please sign in to comment.