Test a require() loop, for testing whether the engine can deal with it

This commit is contained in:
Dale Glass 2023-11-06 18:36:27 +01:00
parent 3abd98b642
commit 91f59a96ab
5 changed files with 39 additions and 0 deletions

View file

@ -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));
}
}

View file

@ -27,6 +27,7 @@ class ScriptEngineNetworkedTests : public QObject {
private slots:
void initTestCase();
void testRequire();
void testRequireInfinite();
private:

View file

@ -0,0 +1,2 @@
module.exports = { value: 1 };
var a = Script.require('./require_inf_b.js');

View file

@ -0,0 +1,2 @@
module.exports = { value: 1 };
var a = Script.require('./require_inf_c.js');

View file

@ -0,0 +1,2 @@
module.exports = { value: 1 };
var a = Script.require('./require_inf_a.js');