From ad0cb1f32ddfbdf7dbfee1ca92c0f1d9137c1a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 15 Aug 2022 10:07:37 +0200 Subject: [PATCH] wasm: add "skip" support to qtwasmtestlib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're not looking to skip faulty tests, but there are cases where we would like to indicate that a test function exists but can't run because some precondition is not met. Pick-to: 6.4 Change-Id: Ifaaafcfa7a55beaaf56d8b25fabbe3dc2566350f Reviewed-by: Tor Arne Vestbø Reviewed-by: Mikołaj Boc --- .../manual/wasm/qtwasmtestlib/qtwasmtestlib.cpp | 17 +++++++++++++++-- tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h | 1 + .../manual/wasm/qtwasmtestlib/qtwasmtestlib.js | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.cpp b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.cpp index 7d1db44cb0e..d86b8ee2c06 100644 --- a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.cpp +++ b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.cpp @@ -45,8 +45,22 @@ void verify(bool condition, std::string_view conditionString, std::string_view f // thread-safe and call be called from any thread. void completeTestFunction(TestResult result, std::string message) { + auto resultString = [](TestResult result) { + switch (result) { + case TestResult::Pass: + return "PASS"; + break; + case TestResult::Fail: + return "FAIL"; + break; + case TestResult::Skip: + return "SKIP"; + break; + } + }; + // Report test result to JavaScript test runner, on the main thread - runOnMainThread([resultString = result == TestResult::Pass ? "PASS" : "FAIL", message](){ + runOnMainThread([resultString = resultString(result), message](){ EM_ASM({ completeTestFunction(UTF8ToString($0), UTF8ToString($1), UTF8ToString($2)); }, g_currentTestName.c_str(), resultString, message.c_str()); @@ -97,7 +111,6 @@ std::string getTestFunctions() void runTestFunction(std::string name) { g_currentTestName = name; - QMetaObject::invokeMethod(g_testObject, "init"); QMetaObject::invokeMethod(g_testObject, name.c_str()); } diff --git a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h index c691f44600e..5dcc41419ef 100644 --- a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h +++ b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.h @@ -13,6 +13,7 @@ namespace QtWasmTest { enum TestResult { Pass, Fail, + Skip, }; std::string formatMessage(std::string_view file, diff --git a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.js b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.js index 96ff3d81a70..c9a393098de 100644 --- a/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.js +++ b/tests/manual/wasm/qtwasmtestlib/qtwasmtestlib.js @@ -156,8 +156,18 @@ function testFunctionStarted(name) { } function testFunctionCompleted(status) { - const color = status.startsWith("PASS") ? "green" : status.startsWith("FAIL") ? "red" : "black"; - let line = `${status}
`; + + const color = (status) => { + if (status.startsWith("PASS")) + return "green"; + if (status.startsWith("FAIL")) + return "red"; + if (status.startsWith("SKIP")) + return "tan"; + return "black"; + }; + + const line = `${status}
`; g_htmlLogElement.innerHTML += line; }