From e1c22b5c7cd6d5542e13cb6ef74f2724d66f264a Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Sat, 15 Oct 2022 19:53:07 +0200 Subject: [PATCH] Initial support for a directory with test scripts This way there's no need to rebuild the test every time. Script dir is symlinked from the source into the binary dir. --- CMakeLists.txt | 2 ++ tests/script-engine/CMakeLists.txt | 19 +++++++++++++++++++ tests/script-engine/src/ScriptEngineTests.cpp | 14 ++++++++++---- .../script-engine/src/tests/001_test_print.js | 4 ++++ .../src/tests/002_console_log.js | 1 + 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/script-engine/src/tests/001_test_print.js create mode 100644 tests/script-engine/src/tests/002_console_log.js diff --git a/CMakeLists.txt b/CMakeLists.txt index 84f3a5a060..a901e8763e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ else() cmake_minimum_required(VERSION 3.2) endif() +# 3.14 is the minimum version that supports symlinks on Windows +cmake_minimum_required(VERSION 3.14) # Passing of variables to vcpkg # diff --git a/tests/script-engine/CMakeLists.txt b/tests/script-engine/CMakeLists.txt index 83c2999680..b6c9a184e8 100644 --- a/tests/script-engine/CMakeLists.txt +++ b/tests/script-engine/CMakeLists.txt @@ -5,6 +5,25 @@ macro (setup_testcase_dependencies) link_hifi_libraries(shared test-utils script-engine networking) package_libraries_for_deployment() + + + # The test system is a bit unusual in how it works, and generates targets on its own. + # This macro will be called for each of them, so we want to add stuff only to the + # right targets. + if("${TARGET_NAME}" STREQUAL "script-engine-ScriptEngineTests") + + # We're going with a symlink here for ease of development -- can change the test + # without recompiling. We probably never are going to package the tests, or use + # them outside of development. + # + # Symlinks should also work fine on Windows. They're a supported feature, though + # a very rarely used one. + add_custom_command(TARGET "${TARGET_NAME}" POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink + "${CMAKE_CURRENT_SOURCE_DIR}/src/tests" + "${CMAKE_CURRENT_BINARY_DIR}/tests" + ) + endif() endmacro () setup_hifi_testcase(Network) diff --git a/tests/script-engine/src/ScriptEngineTests.cpp b/tests/script-engine/src/ScriptEngineTests.cpp index 8907954266..093ddb797f 100644 --- a/tests/script-engine/src/ScriptEngineTests.cpp +++ b/tests/script-engine/src/ScriptEngineTests.cpp @@ -76,10 +76,16 @@ void ScriptEngineTests::scriptTest() { QVERIFY(!ac.isNull()); - ac->loadOneScript("test1.js"); - //ac->loadOneScript("test-missing.js"); - //ac->loadOneScript("test-hello.js"); - //ac->loadOneScript("test-divide-by-zero.js"); + QDir testScriptsDir("tests"); + QStringList testScripts = testScriptsDir.entryList(QStringList() << "*.js", QDir::Files); + testScripts.sort(); + + for(QString script : testScripts) { + script = "tests/" + script; + qInfo() << "Running test script: " << script; + ac->loadOneScript(script); + } + qDebug() << ac->getRunning(); diff --git a/tests/script-engine/src/tests/001_test_print.js b/tests/script-engine/src/tests/001_test_print.js new file mode 100644 index 0000000000..1522a9b6b2 --- /dev/null +++ b/tests/script-engine/src/tests/001_test_print.js @@ -0,0 +1,4 @@ +var v = 1; +for (v = 1; v < 30; v++){ + print(v); +} diff --git a/tests/script-engine/src/tests/002_console_log.js b/tests/script-engine/src/tests/002_console_log.js new file mode 100644 index 0000000000..a39de8f7f4 --- /dev/null +++ b/tests/script-engine/src/tests/002_console_log.js @@ -0,0 +1 @@ +console.log("I'm testing!");