From a96583615ffbcb32726df56d206953f4b238e98d Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Sun, 3 Oct 2010 17:10:28 +1000 Subject: Add support for optional TestCase elements --- QtTest/TestCase.qml | 15 +++++++++++++++ QtTest/testlogger.js | 16 ++++++++++++++++ examples/ItemTests.qml | 9 +++++++++ 3 files changed, 40 insertions(+) diff --git a/QtTest/TestCase.qml b/QtTest/TestCase.qml index 3625140..3f28490 100644 --- a/QtTest/TestCase.qml +++ b/QtTest/TestCase.qml @@ -17,6 +17,10 @@ Item { // Set to true when the test is running but not yet complete. property bool running: false + // Set to true if the test doesn't have to run (because some + // other test failed which this one depends on). + property bool optional: false + // Internal private state property string currentTestCase property bool expectingFail @@ -149,8 +153,19 @@ Item { } } + onOptionalChanged: { + if (!completed) { + if (optional) + TestLogger.log_optional_test(testId) + else + TestLogger.log_mandatory_test(testId) + } + } + Component.onCompleted: { testId = TestLogger.log_register_test(name) + if (optional) + TestLogger.log_optional_test(testId) prevWhen = when if (when && !completed && !running) run() diff --git a/QtTest/testlogger.js b/QtTest/testlogger.js index 34e73a0..7f360f1 100644 --- a/QtTest/testlogger.js +++ b/QtTest/testlogger.js @@ -81,6 +81,22 @@ function log_register_test(name) return testId } +function log_optional_test(testId) +{ + log_init_results() + var index = Qt.testResults.testCases.indexOf(testId) + if (index >= 0) + Qt.testResults.testCases.splice(index, 1) +} + +function log_mandatory_test(testId) +{ + log_init_results() + var index = Qt.testResults.testCases.indexOf(testId) + if (index == -1) + Qt.testResults.testCases.push(testId) +} + function log_start_test() { log_init_results() diff --git a/examples/ItemTests.qml b/examples/ItemTests.qml index a150735..a83e514 100644 --- a/examples/ItemTests.qml +++ b/examples/ItemTests.qml @@ -30,4 +30,13 @@ Rectangle { verify(bar) } } + + TestCase { + when: false + optional: true + + function test_not_run() { + verify(false) + } + } } -- cgit v1.2.3