mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 20:23:04 +02:00
Test a require() loop, for testing whether the engine can deal with it
This commit is contained in:
parent
3abd98b642
commit
91f59a96ab
5 changed files with 39 additions and 0 deletions
|
@ -155,3 +155,35 @@ void ScriptEngineNetworkedTests::testRequire() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ScriptEngineNetworkedTests::testRequireInfinite() {
|
||||||
|
auto sm = makeManager(
|
||||||
|
"print(\"Starting\");"
|
||||||
|
"Script.require('./tests/require_inf_a.js');"
|
||||||
|
"print(\"Done\");"
|
||||||
|
"Script.stop(true);", "testRequireInf.js");
|
||||||
|
QStringList printed;
|
||||||
|
QStringList expected {"Starting", "Value from A: 6", "Value from B: 6", "Done"};
|
||||||
|
|
||||||
|
|
||||||
|
QVERIFY(!sm->isRunning());
|
||||||
|
QVERIFY(!sm->isStopped());
|
||||||
|
QVERIFY(!sm->isFinished());
|
||||||
|
|
||||||
|
connect(sm.get(), &ScriptManager::printedMessage, [&printed](const QString& message, const QString& engineName){
|
||||||
|
printed.append(message);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
qInfo() << "About to run script";
|
||||||
|
sm->run();
|
||||||
|
|
||||||
|
QVERIFY(!sm->isRunning());
|
||||||
|
QVERIFY(!sm->isStopped());
|
||||||
|
QVERIFY(sm->isFinished());
|
||||||
|
|
||||||
|
QVERIFY(printed.length() == expected.length());
|
||||||
|
for(int i=0;i<printed.length();i++) {
|
||||||
|
QString nomatch = QString("Result '%1' didn't match expected '%2'").arg(printed[i]).arg(expected[i]);
|
||||||
|
QVERIFY2(printed[i] == expected[i], qPrintable(nomatch));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class ScriptEngineNetworkedTests : public QObject {
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void testRequire();
|
void testRequire();
|
||||||
|
void testRequireInfinite();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
2
tests/script-engine/src/tests/require_inf_a.js
Normal file
2
tests/script-engine/src/tests/require_inf_a.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module.exports = { value: 1 };
|
||||||
|
var a = Script.require('./require_inf_b.js');
|
2
tests/script-engine/src/tests/require_inf_b.js
Normal file
2
tests/script-engine/src/tests/require_inf_b.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module.exports = { value: 1 };
|
||||||
|
var a = Script.require('./require_inf_c.js');
|
2
tests/script-engine/src/tests/require_inf_c.js
Normal file
2
tests/script-engine/src/tests/require_inf_c.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
module.exports = { value: 1 };
|
||||||
|
var a = Script.require('./require_inf_a.js');
|
Loading…
Reference in a new issue