diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-12-16 12:52:32 +1000 |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2010-12-16 12:52:32 +1000 |
commit | 276354547cedabe3b41795793f3f94387f15a7ac (patch) | |
tree | 9d54375ab9e6cf7471e29347655d78d9f1aa1c03 | |
parent | c5be97bce730a728930ceb2f6a4496ae4d67abcd (diff) |
Run named test functions from the command-line
Data tags are not currently supported.
-rw-r--r-- | src/imports/testlib/TestCase.qml | 41 | ||||
-rw-r--r-- | src/quicktestlib/quicktestresult.cpp | 11 | ||||
-rw-r--r-- | src/quicktestlib/quicktestresult_p.h | 4 | ||||
-rw-r--r-- | tests/qmlauto/selftests/tst_selftests.qml | 1 |
4 files changed, 55 insertions, 2 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index b61a44d..1165c3a 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -381,6 +381,32 @@ Item { } running = true + // Check the run list to see if this class is mentioned. + var functionsToRun = qtest_results.functionsToRun + if (functionsToRun.length > 0) { + var found = false + var list = [] + if (name.length > 0) { + var prefix = name + "::" + for (var index in functionsToRun) { + if (functionsToRun[index].indexOf(prefix) == 0) { + list.push(functionsToRun[index]) + found = true + } + } + } + if (!found) { + completed = true + if (!TestLogger.log_complete_test(qtest_testId)) { + qtest_results.stopLogging() + Qt.quit() + } + qtest_results.testCaseName = "" + return + } + functionsToRun = list + } + // Run the initTestCase function. qtest_results.functionName = "initTestCase" qtest_results.functionType = TestResult.InitFunc @@ -402,10 +428,17 @@ Item { } testList.sort() } + var checkNames = (functionsToRun.length > 0) for (var index in testList) { var prop = testList[index] var datafunc = prop + "_data" var isBenchmark = (prop.indexOf("benchmark_") == 0) + if (checkNames) { + var index = functionsToRun.indexOf(name + "::" + prop) + if (index < 0) + continue + functionsToRun.splice(index, 1) + } qtest_results.functionName = prop if (datafunc in testCase) { qtest_results.functionType = TestResult.DataFunc @@ -444,6 +477,10 @@ Item { qtest_results.functionType = TestResult.CleanupFunc qtest_runInternal("cleanupTestCase") + // Complain about missing functions that we were supposed to run. + if (functionsToRun.length > 0) + qtest_results.fail("Could not find functions: " + functionsToRun, "", 0) + // Clean up and exit. running = false completed = true @@ -494,10 +531,10 @@ Item { var tail = prop.lastIndexOf("_data"); if (tail != -1 && tail == (prop.length - 5)) continue + // Note: cannot run functions in TestCase elements + // that lack a name. if (name.length > 0) testList.push(name + "::" + prop + "()") - else - testList.push(prop + "()") } testList.sort() for (var index in testList) diff --git a/src/quicktestlib/quicktestresult.cpp b/src/quicktestlib/quicktestresult.cpp index 53f0070..0ceb191 100644 --- a/src/quicktestlib/quicktestresult.cpp +++ b/src/quicktestlib/quicktestresult.cpp @@ -45,6 +45,7 @@ #include "qtestresult_p.h" #include "qtesttable_p.h" #include "qtestlog_p.h" +#include "qtestoptions_p.h" #include "qbenchmark.h" #include "qbenchmark_p.h" #include <QtCore/qset.h> @@ -306,6 +307,16 @@ int QuickTestResult::skipCount() const } /*! + \qmlproperty list<string> TestResult::functionsToRun + + This property returns the list of function names to be run. +*/ +QStringList QuickTestResult::functionsToRun() const +{ + return QTest::testFunctions; +} + +/*! \qmlmethod TestResult::reset() Resets all pass/fail/skip counters and prepare for testing. diff --git a/src/quicktestlib/quicktestresult_p.h b/src/quicktestlib/quicktestresult_p.h index a3c67be..d9ae694 100644 --- a/src/quicktestlib/quicktestresult_p.h +++ b/src/quicktestlib/quicktestresult_p.h @@ -45,6 +45,7 @@ #include <QtQuickTest/quicktestglobal.h> #include <QtCore/qobject.h> #include <QtCore/qstring.h> +#include <QtCore/qstringlist.h> #include <QtCore/qscopedpointer.h> QT_BEGIN_NAMESPACE @@ -65,6 +66,7 @@ class Q_QUICK_TEST_EXPORT QuickTestResult : public QObject Q_PROPERTY(int passCount READ passCount) Q_PROPERTY(int failCount READ failCount) Q_PROPERTY(int skipCount READ skipCount) + Q_PROPERTY(QStringList functionsToRun READ functionsToRun) public: QuickTestResult(QObject *parent = 0); ~QuickTestResult(); @@ -108,6 +110,8 @@ public: int failCount() const; int skipCount() const; + QStringList functionsToRun() const; + public Q_SLOTS: void reset(); diff --git a/tests/qmlauto/selftests/tst_selftests.qml b/tests/qmlauto/selftests/tst_selftests.qml index 875a242..bcf53b9 100644 --- a/tests/qmlauto/selftests/tst_selftests.qml +++ b/tests/qmlauto/selftests/tst_selftests.qml @@ -52,6 +52,7 @@ TestCase { property string failmsg: "cleaned" property string actual: "" property string expected: "" + property variant functionsToRun: [] function fail(msg, file, line) { failmsg = msg |