This is an automated email from the ASF dual-hosted git repository.

lordgamez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 9a3616ff1557eb9d35a8a3c477b8ae6954808021
Author: Ferenc Gerlits <[email protected]>
AuthorDate: Thu Sep 8 12:25:30 2022 +0200

    MINIFICPP-1933 Fix Lua unit tests on Windows
    
    - use raw strings when setting up the package path
    - use the source path instead of the executable path to find test inputs
    - use the current source dir as the working directory for tests
    - set up Lua in the Windows CI job
    - enable Lua scripting in the Windows CI build
    
    Signed-off-by: Gabor Gyimesi <[email protected]>
    
    This closes #1415
---
 .github/workflows/ci.yml                                  |  4 +++-
 extensions/script/lua/LuaScriptEngine.cpp                 |  4 ++--
 extensions/script/tests/CMakeLists.txt                    |  3 +--
 .../tests/TestExecuteScriptProcessorWithLuaScript.cpp     | 15 ++++++---------
 4 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ff1350d8b..6e5e442c6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -56,6 +56,8 @@ jobs:
         uses: actions/setup-python@v4
         with:
           python-version: '3.10'
+      - name: Set up Lua
+        uses: xpol/[email protected]
       - id: install-sqliteodbc-driver
         run: |
           Invoke-WebRequest -Uri 
"http://www.ch-werner.de/sqliteodbc/sqliteodbc_w64.exe"; -OutFile 
"sqliteodbc_w64.exe"
@@ -65,7 +67,7 @@ jobs:
         run: |
           PATH %PATH%;C:\Program Files (x86)\Windows 
Kits\10\bin\10.0.19041.0\x64
           PATH %PATH%;C:\Program Files (x86)\Microsoft Visual 
Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn
-          win_build_vs.bat ..\b /64 /CI /S /A /PDH /SPLUNK /GCP /ELASTIC /K /L 
/R /Z /N /RO /PR /SCRIPTING
+          win_build_vs.bat ..\b /64 /CI /S /A /PDH /SPLUNK /GCP /ELASTIC /K /L 
/R /Z /N /RO /PR /SCRIPTING /LUA_SCRIPTING
         shell: cmd
       - name: test
         run: cd ..\b && ctest --timeout 300 --parallel %NUMBER_OF_PROCESSORS% 
-C Release --output-on-failure
diff --git a/extensions/script/lua/LuaScriptEngine.cpp 
b/extensions/script/lua/LuaScriptEngine.cpp
index 48183c7b1..28142c760 100644
--- a/extensions/script/lua/LuaScriptEngine.cpp
+++ b/extensions/script/lua/LuaScriptEngine.cpp
@@ -63,9 +63,9 @@ LuaScriptEngine::LuaScriptEngine() {
 void LuaScriptEngine::executeScriptWithAppendedModulePaths(std::string& 
script) {
   for (const auto& module_path : module_paths_) {
     if 
(std::filesystem::is_regular_file(std::filesystem::status(module_path))) {
-      script = utils::StringUtils::join_pack("package.path = package.path .. 
\";", module_path, "\"\n", script);
+      script = utils::StringUtils::join_pack("package.path = package.path .. 
[[;", module_path, "]]\n", script);
     } else {
-      script = utils::StringUtils::join_pack("package.path = package.path .. 
\";", module_path, "/?.lua\"\n", script);
+      script = utils::StringUtils::join_pack("package.path = package.path .. 
[[;", module_path, "/?.lua]]\n", script);
     }
   }
   lua_.script(script, sol::script_throw_on_error);
diff --git a/extensions/script/tests/CMakeLists.txt 
b/extensions/script/tests/CMakeLists.txt
index 23e2cf6f7..c70f967c7 100644
--- a/extensions/script/tests/CMakeLists.txt
+++ b/extensions/script/tests/CMakeLists.txt
@@ -89,8 +89,7 @@ FOREACH(testfile ${EXECUTESCRIPT_LUA_TESTS})
     target_link_libraries(${testfilename} ${CATCH_MAIN_LIB})
     createTests("${testfilename}")
     MATH(EXPR EXTENSIONS_TEST_COUNT "${EXTENSIONS_TEST_COUNT}+1")
-    add_test(NAME "${testfilename}" COMMAND "${testfilename}" 
WORKING_DIRECTORY ${TEST_DIR})
-    file(COPY "${CMAKE_SOURCE_DIR}/extensions/script/tests/test_lua_scripts" 
DESTINATION "${CMAKE_BINARY_DIR}/bin/")
+    add_test(NAME "${testfilename}" COMMAND "${testfilename}" 
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 ENDFOREACH()
 
 message("-- Finished building ${EXTENSIONS_TEST_COUNT} ExecuteScript related 
test file(s)...")
diff --git 
a/extensions/script/tests/TestExecuteScriptProcessorWithLuaScript.cpp 
b/extensions/script/tests/TestExecuteScriptProcessorWithLuaScript.cpp
index 95d011e35..d7c44d19c 100644
--- a/extensions/script/tests/TestExecuteScriptProcessorWithLuaScript.cpp
+++ b/extensions/script/tests/TestExecuteScriptProcessorWithLuaScript.cpp
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+#include <filesystem>
 #include <memory>
 #include <string>
 #include <set>
@@ -398,7 +399,6 @@ TEST_CASE("Lua: Test Require", "[executescriptLuaRequire]") 
{
 
 TEST_CASE("Lua: Test Module Directory property", 
"[executescriptLuaModuleDirectoryProperty]") {
   using org::apache::nifi::minifi::utils::file::concat_path;
-  using org::apache::nifi::minifi::utils::file::get_executable_dir;
 
   TestController testController;
 
@@ -406,12 +406,6 @@ TEST_CASE("Lua: Test Module Directory property", 
"[executescriptLuaModuleDirecto
   logTestController.setDebug<TestPlan>();
   logTestController.setDebug<minifi::processors::ExecuteScript>();
 
-  const std::string SCRIPT_FILES_DIRECTORY = concat_path(get_executable_dir(), 
"test_lua_scripts");
-
-  auto getScriptFullPath = [&SCRIPT_FILES_DIRECTORY](const std::string& 
script_file_name) {
-    return concat_path(SCRIPT_FILES_DIRECTORY, script_file_name);
-  };
-
   auto plan = testController.createPlan();
 
   auto getFile = plan->addProcessor("GetFile", "getFile");
@@ -420,9 +414,12 @@ TEST_CASE("Lua: Test Module Directory property", 
"[executescriptLuaModuleDirecto
                                           core::Relationship("success", 
"description"),
                                           true);
 
+  const auto SCRIPT_FILES_DIRECTORY = 
std::filesystem::path(__FILE__).parent_path() / "test_lua_scripts";
+
   plan->setProperty(executeScript, 
minifi::processors::ExecuteScript::ScriptEngine.getName(), "lua");
-  plan->setProperty(executeScript, 
minifi::processors::ExecuteScript::ScriptFile.getName(), 
getScriptFullPath("foo_bar_processor.lua"));
-  plan->setProperty(executeScript, 
minifi::processors::ExecuteScript::ModuleDirectory.getName(), 
getScriptFullPath("foo_modules/foo.lua") + "," + 
getScriptFullPath("bar_modules"));
+  plan->setProperty(executeScript, 
minifi::processors::ExecuteScript::ScriptFile.getName(), 
(SCRIPT_FILES_DIRECTORY / "foo_bar_processor.lua").string());
+  plan->setProperty(executeScript, 
minifi::processors::ExecuteScript::ModuleDirectory.getName(),
+      (SCRIPT_FILES_DIRECTORY / "foo_modules" / "foo.lua").string() + "," + 
(SCRIPT_FILES_DIRECTORY / "bar_modules").string());
 
   auto getFileDir = testController.createTempDirectory();
   plan->setProperty(getFile, minifi::processors::GetFile::Directory.getName(), 
getFileDir);

Reply via email to