From 58f757c8f02f909bee9eb190896d49a7a958c10d Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Tue, 24 Sep 2024 01:04:50 -0500 Subject: [PATCH] wip v2 --- lib/CMakeLists.txt | 3 +++ tests/CMakeLists.txt | 15 ++++++++++--- tests/libtest.lua | 53 -------------------------------------------- tests/lua_test.sh | 17 +++++++++++++- tests/test_basic.lua | 4 +--- 5 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 tests/libtest.lua diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d70218b..6eedf68 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -7,6 +7,9 @@ file(GLOB lua_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.lua" "${CMAKE_CURRENT_SOURCE_DIR}/porch/*.lua") +add_custom_target(libs + DEPENDS core) + add_custom_target(lint COMMAND echo LINTING FOR LUA 5.3 COMMAND luacheck --std=lua53 ${lua_SOURCES} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 67a2885..450b4c7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,13 @@ -add_custom_target(check - COMMAND true # env PORCHBIN="${CMAKE_BINARY_DIR}/src/porch" PORCHLUA_PATH="${CMAKE_SOURCE_DIR}/lib" sh "${CMAKE_CURRENT_SOURCE_DIR}/basic_test.sh" - COMMAND env PORCHLIB_PATH="${CMAKE_BINARY_DIR}/lib" PORCHLUA_PATH="${CMAKE_SOURCE_DIR}/lib" sh "${CMAKE_CURRENT_SOURCE_DIR}/lua_test.sh" +add_custom_target(check-install + COMMAND "${CMAKE_COMMAND}" --build . --target install) + +add_custom_target(check-cli + COMMAND env PORCHBIN="${CMAKE_BINARY_DIR}/src/porch" PORCHLUA_PATH="${CMAKE_SOURCE_DIR}/lib" sh "${CMAKE_CURRENT_SOURCE_DIR}/basic_test.sh" + DEPENDS porch) + +add_custom_target(check-lib + COMMAND env PORCHLIB_PATH="${CMAKE_BINARY_DIR}/lib" PORCHLUA_PATH="${CMAKE_SOURCE_DIR}/lib" LUA_VERSION_MAJOR="${LUA_VERSION_MAJOR}" LUA_VERSION_MINOR="${LUA_VERSION_MINOR}" sh "${CMAKE_CURRENT_SOURCE_DIR}/lua_test.sh" + DEPENDS libs check-install WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") + +add_custom_target(check DEPENDS check-cli check-lib) diff --git a/tests/libtest.lua b/tests/libtest.lua deleted file mode 100644 index eac7ed1..0000000 --- a/tests/libtest.lua +++ /dev/null @@ -1,53 +0,0 @@ -local ltest = {} - -local libpath = os.getenv("PORCHLIB_PATH") -local luapath = os.getenv("PORCHLUA_PATH") - -local function porchloader(modname) - if not modname:match("^porch") then - return nil - end - - local function loadlua(modname, chunk) - return chunk() - end - - if modname == "porch" then - return loadlua, loadfile(luapath .. "/" .. modname .. ".lua", "t") - end - - assert(modname:match("^porch.")) - modname = modname:sub(#"porch." + 1) - - local function lua_path(name) - return luapath .. "/porch/" .. name .. ".lua" - end - local function clib_path(name, ext) - return libpath .. "/" .. name .. "/" .. name .. ext - end - local function try_lua(name) - return loadfile(lua_path(name), "t") - end - - local chunk = try_lua(modname) - if chunk then - return loadlua, chunk - end - - -- Must be a C module - local ext = package.cpath:match(".so") or package.cpath:match(".dylib") - assert(ext, "Unsure of shlib extension for this platform") - - local openfunc = assert(package.loadlib(clib_path(modname, ext), "luaopen_porch_" .. - modname), "Failed to load " .. modname .. " as C lib") - - local function loadc(modname, openfunc) - return openfunc() - end - - return loadc, openfunc -end - -package.searchers[#package.searchers + 1] = porchloader - -return ltest diff --git a/tests/lua_test.sh b/tests/lua_test.sh index fbb3e03..fed158b 100644 --- a/tests/lua_test.sh +++ b/tests/lua_test.sh @@ -1,5 +1,20 @@ #!/bin/sh +schemes="lua${LUA_VERSION_MAJOR}${LUA_VERSION_MINOR}" +schemes="$schemes lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}" + +for bin in $schemes; do + if command -v $bin >/dev/null; then + LUA="$bin" + break + fi +done + +if [ -z "$LUA" ]; then + 1>&2 "Could not find suitable binary named any of: $schemes" + exit 1 +fi + for x in test_*.lua; do #XXX WRONG - lua54 "$x" #XXX WRONG + command $LUA "$x" done diff --git a/tests/test_basic.lua b/tests/test_basic.lua index e8f5a8e..a8115b3 100644 --- a/tests/test_basic.lua +++ b/tests/test_basic.lua @@ -1,5 +1,3 @@ -local ltest = require('./libtest') - local porch = require('porch') - +print(porch)