From 91f59a96ab02136e4ef5e71ed2e66972291340ea Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Mon, 6 Nov 2023 18:36:27 +0100 Subject: [PATCH] Test a require() loop, for testing whether the engine can deal with it --- .../src/ScriptEngineNetworkedTests.cpp | 32 +++++++++++++++++++ .../src/ScriptEngineNetworkedTests.h | 1 + .../script-engine/src/tests/require_inf_a.js | 2 ++ .../script-engine/src/tests/require_inf_b.js | 2 ++ .../script-engine/src/tests/require_inf_c.js | 2 ++ 5 files changed, 39 insertions(+) create mode 100644 tests/script-engine/src/tests/require_inf_a.js create mode 100644 tests/script-engine/src/tests/require_inf_b.js create mode 100644 tests/script-engine/src/tests/require_inf_c.js diff --git a/tests/script-engine/src/ScriptEngineNetworkedTests.cpp b/tests/script-engine/src/ScriptEngineNetworkedTests.cpp index 53a6b3d420..d73323a75b 100644 --- a/tests/script-engine/src/ScriptEngineNetworkedTests.cpp +++ b/tests/script-engine/src/ScriptEngineNetworkedTests.cpp @@ -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