History

Capture exceptions that happen in signals in ScriptEngine, add test

Dale Glass committed 3 years ago

Commit 6ac25961 parent 1e1b9674 files · +45 −9Browse files

Showing the changes to tests/script-engine/src/ScriptEngineTests.cpp (1 of 4 files). Show all

Unified · Split

tests/script-engine/src/ScriptEngineTests.cpp+31−0
@@ -271,6 +271,37 @@ void ScriptEngineTests::testSignal() { · 270 unmodified lines
271271 QVERIFY(printed.length() >= 10);
272272 }
273273
274+void ScriptEngineTests::testSignalWithException() {
275+ QString script =
276+ "var count = 0;"
277+ "Script.update.connect(function(deltaTime) {"
278+ " count++;"
279+ " print(deltaTime);"
280+ " if (count >= 3) {"
281+ " Script.stop(true);"
282+ " }"
283+ " nonExist();"
284+ "});";
285+
286+ QStringList printed;
287+ int exceptionCount = 0;
288+
289+ auto sm = makeManager(script, "testSignalWithException.js");
290+
291+ connect(sm.get(), &ScriptManager::printedMessage, [&printed](const QString& message, const QString& engineName){
292+ printed.append(message);
293+ });
294+
295+ connect(sm.get(), &ScriptManager::unhandledException, [&exceptionCount](std::shared_ptr<ScriptException> exception){
296+ exceptionCount++;
297+ });
298+
299+
300+ sm->run();
301+ QVERIFY(printed.length() >= 3);
302+ QVERIFY(exceptionCount >= 3);
303+}
304+
274305
275306 void ScriptEngineTests::scriptTest() {
276307 return;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t