Showing the changes to tests/script-engine/src/ScriptEngineTests.cpp (1 of 3 files). Show all
Unified · Split
| @@ -218,6 +218,35 @@ void ScriptEngineTests::testRaiseException() { · 217 unmodified lines | |||
| 218 | QVERIFY(ex && ex->errorMessage.contains("Exception test")); | 218 | QVERIFY(ex && ex->errorMessage.contains("Exception test")); |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | void ScriptEngineTests::testRaiseExceptionAndCatch() { | ||
| 222 | QString script = | ||
| 223 | "try {" | ||
| 224 | " testClass.doRaiseTest();" | ||
| 225 | "} catch (err) {" | ||
| 226 | " if (err === \"Exception test!\") {" | ||
| 227 | " print(\"Caught!\");" | ||
| 228 | " }" | ||
| 229 | "}" | ||
| 230 | "Script.stop(true);" | ||
| 231 | ; | ||
| 232 | |||
| 233 | QString printed; | ||
| 234 | auto sm = makeManager(script, "testRaiseCatch.js"); | ||
| 235 | |||
| 236 | connect(sm.get(), &ScriptManager::printedMessage, [&printed](const QString& message, const QString& engineName){ | ||
| 237 | printed.append(message); | ||
| 238 | }); | ||
| 239 | |||
| 240 | |||
| 241 | sm->engine()->registerGlobalObject("testClass", new TestClass(sm->engine())); | ||
| 242 | |||
| 243 | sm->run(); | ||
| 244 | auto ex = sm->getUncaughtException(); | ||
| 245 | |||
| 246 | QVERIFY(!ex); | ||
| 247 | QVERIFY(printed == "Caught!"); | ||
| 248 | } | ||
| 249 | |||
| 221 | 250 | ||
| 222 | void ScriptEngineTests::scriptTest() { | 251 | void ScriptEngineTests::scriptTest() { |
| 223 | return; | 252 | return; |