mirror of
https://github.com/overte-org/overte.git
synced 2025-07-24 11:23:47 +02:00
Tests for runtime exceptions and throw()
This commit is contained in:
parent
cb0c62024d
commit
4beb5eceeb
2 changed files with 39 additions and 11 deletions
|
@ -87,11 +87,6 @@ ScriptManagerPointer ScriptEngineTests::makeManager(const QString &scriptSource,
|
||||||
qInfo() << "Running state changed. Running = " << sm->isRunning() << "; Stopped = " << sm->isStopped() << "; Finished = " << sm->isFinished();
|
qInfo() << "Running state changed. Running = " << sm->isRunning() << "; Stopped = " << sm->isStopped() << "; Finished = " << sm->isFinished();
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(sm->engine().get(), &ScriptEngine::exception, [](std::shared_ptr<ScriptException> exception){
|
|
||||||
qWarning() << "Exception from engine (direct): " << exception;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
connect(sm.get(), &ScriptManager::unhandledException, [](std::shared_ptr<ScriptException> exception){
|
connect(sm.get(), &ScriptManager::unhandledException, [](std::shared_ptr<ScriptException> exception){
|
||||||
qWarning() << "Exception from engine: " << exception;
|
qWarning() << "Exception from engine: " << exception;
|
||||||
});
|
});
|
||||||
|
@ -127,17 +122,12 @@ void ScriptEngineTests::testSyntaxError() {
|
||||||
auto sm = makeManager("this is not good syntax", "testSyntaxError.js");
|
auto sm = makeManager("this is not good syntax", "testSyntaxError.js");
|
||||||
bool exceptionHappened = false;
|
bool exceptionHappened = false;
|
||||||
|
|
||||||
|
|
||||||
//QSignalSpy spy(sm.get(), &ScriptManager::unhandledException);
|
|
||||||
|
|
||||||
|
|
||||||
connect(sm.get(), &ScriptManager::unhandledException, [&exceptionHappened](std::shared_ptr<ScriptException> exception){
|
connect(sm.get(), &ScriptManager::unhandledException, [&exceptionHappened](std::shared_ptr<ScriptException> exception){
|
||||||
exceptionHappened = true;
|
exceptionHappened = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
sm->run();
|
sm->run();
|
||||||
//spy.wait(1000);
|
|
||||||
|
|
||||||
std::shared_ptr<ScriptException> ex = sm->getUncaughtException();
|
std::shared_ptr<ScriptException> ex = sm->getUncaughtException();
|
||||||
|
|
||||||
|
@ -145,8 +135,44 @@ void ScriptEngineTests::testSyntaxError() {
|
||||||
|
|
||||||
QVERIFY(exceptionHappened);
|
QVERIFY(exceptionHappened);
|
||||||
QVERIFY(ex);
|
QVERIFY(ex);
|
||||||
|
QVERIFY(ex && ex->errorMessage.contains("SyntaxError"));
|
||||||
|
}
|
||||||
|
|
||||||
//QVERIFY(spy.count() == 1);
|
|
||||||
|
void ScriptEngineTests::testRuntimeError() {
|
||||||
|
auto sm = makeManager("nonexisting();", "testRuntimeError.js");
|
||||||
|
bool exceptionHappened = false;
|
||||||
|
|
||||||
|
connect(sm.get(), &ScriptManager::unhandledException, [&exceptionHappened](std::shared_ptr<ScriptException> exception){
|
||||||
|
exceptionHappened = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
sm->run();
|
||||||
|
|
||||||
|
std::shared_ptr<ScriptException> ex = sm->getUncaughtException();
|
||||||
|
|
||||||
|
qDebug() << "Exception:" << ex;
|
||||||
|
|
||||||
|
QVERIFY(exceptionHappened);
|
||||||
|
QVERIFY(ex);
|
||||||
|
QVERIFY(ex && ex->errorMessage.contains("ReferenceError"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptEngineTests::testJSThrow() {
|
||||||
|
auto sm = makeManager("throw(42);", "testThrow.js");
|
||||||
|
sm->run();
|
||||||
|
|
||||||
|
std::shared_ptr<ScriptException> ex = sm->getUncaughtException();
|
||||||
|
|
||||||
|
qDebug() << "Exception:" << ex;
|
||||||
|
|
||||||
|
auto runtime_ex = std::dynamic_pointer_cast<ScriptRuntimeException>(ex);
|
||||||
|
|
||||||
|
QVERIFY(ex);
|
||||||
|
QVERIFY(runtime_ex);
|
||||||
|
QVERIFY(runtime_ex && runtime_ex->thrownValue.toInt32() == 42);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngineTests::scriptTest() {
|
void ScriptEngineTests::scriptTest() {
|
||||||
|
|
|
@ -25,6 +25,8 @@ private slots:
|
||||||
void scriptTest();
|
void scriptTest();
|
||||||
void testTrivial();
|
void testTrivial();
|
||||||
void testSyntaxError();
|
void testSyntaxError();
|
||||||
|
void testRuntimeError();
|
||||||
|
void testJSThrow();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue