diff options
Diffstat (limited to 'src/imports/testlib/TestCase.qml')
-rw-r--r-- | src/imports/testlib/TestCase.qml | 84 |
1 files changed, 78 insertions, 6 deletions
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 0212c83..1165c3a 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -135,8 +135,12 @@ Item { var act = qtest_formatValue(actual) var exp = qtest_formatValue(expected) var success = qtest_compareInternal(actual, expected) - if (msg === undefined) - msg = "" + if (msg === undefined) { + if (success) + msg = "COMPARE()" + else + msg = "Compared values are not the same" + } if (!qtest_results.compare(success, msg, act, exp, Qt.qtest_caller_file(), Qt.qtest_caller_line())) throw new Error("QtQuickTest::fail") } @@ -174,19 +178,27 @@ Item { } function expectFail(tag, msg) { - if (tag === undefined) + if (tag === undefined) { + warn("tag argument missing from expectFail()") tag = "" - if (msg === undefined) + } + if (msg === undefined) { + warn("message argument missing from expectFail()") msg = "" + } if (!qtest_results.expectFail(tag, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())) throw new Error("QtQuickTest::expectFail") } function expectFailContinue(tag, msg) { - if (tag === undefined) + if (tag === undefined) { + warn("tag argument missing from expectFailContinue()") tag = "" - if (msg === undefined) + } + if (msg === undefined) { + warn("message argument missing from expectFailContinue()") msg = "" + } if (!qtest_results.expectFailContinue(tag, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())) throw new Error("QtQuickTest::expectFail") } @@ -355,6 +367,11 @@ Item { } function qtest_run() { + if (Qt.qtest_printAvailableFunctions) { + completed = true + return + } + if (TestLogger.log_start_test()) { qtest_results.reset() qtest_results.testCaseName = name @@ -364,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 @@ -385,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 @@ -427,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 @@ -469,6 +523,24 @@ Item { } Component.onCompleted: { + if (Qt.qtest_printAvailableFunctions) { + var testList = [] + for (var prop in testCase) { + if (prop.indexOf("test_") != 0 && prop.indexOf("benchmark_") != 0) + continue + 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 + "()") + } + testList.sort() + for (var index in testList) + console.log(testList[index]) + return + } qtest_testId = TestLogger.log_register_test(name) if (optional) TestLogger.log_optional_test(qtest_testId) |