Skip to content

Commit

Permalink
test: run luacheck static analysis via CMake
Browse files Browse the repository at this point in the history
This patch introduces a separate target to run luacheck against all Lua
chunks within LuaJIT repository except those explicitly ignored in
.luacheckrc. There is also a single additional change over the 'luajit'
std defaults: to suppress all false positives related to <misc>
namespace introduced in 5a61e1a ('misc:
add C and Lua API for platform metrics'), this name is added to
<read_globals> list.

All Lua sources originally inherited from LuaJIT vanilla repository are
ignored, to leave them coherent with the upstream.

The new target is a dependency for the root <test> target.

Resolves tarantool/tarantool#5470
Part of tarantool/tarantool#4862

Reviewed-by: Timur Safin <[email protected]>
Reviewed-by: Sergey Kaplun <[email protected]>
Signed-off-by: Igor Munkin <[email protected]>
  • Loading branch information
igormunkin committed Feb 28, 2021
1 parent d9d5ab1 commit 6dd4724
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Use the default LuaJIT globals.
std = 'luajit'
-- This fork also introduces a new global for misc API namespace.
read_globals = { 'misc' }

-- These files are inherited from the vanilla LuaJIT and need to
-- be coherent with the upstream.
exclude_files = {
'dynasm/',
'src/',
}
30 changes: 30 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@
# See the rationale in the root CMakeLists.txt.
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

find_program(LUACHECK luacheck)
if(LUACHECK)
set(LUACHECK_RC ${PROJECT_SOURCE_DIR}/.luacheckrc)
file(GLOB_RECURSE LUACHECK_DEPS ${PROJECT_SOURCE_DIR}/*.lua)
add_custom_target(${PROJECT_NAME}-luacheck
DEPENDS ${LUACHECK_RC} ${LUACHECK_DEPS}
)
add_custom_command(TARGET ${PROJECT_NAME}-luacheck
COMMENT "Running luacheck static analysis"
COMMAND
${LUACHECK} ${PROJECT_SOURCE_DIR}
--codes
--config ${LUACHECK_RC}
# XXX: jit/vmdef.lua is an autogenerated Lua source, so
# there is no need to run luacheck against it. Hence
# explicitly exclude this file from the list for check.
--exclude-files ${LUAJIT_BINARY_DIR}/jit/vmdef.lua
# XXX: Filenames in .luacheckrc are considered relative to
# the working directory, hence luacheck should be run in the
# project root directory.
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
else()
add_custom_target(${PROJECT_NAME}-luacheck)
add_custom_command(TARGET ${PROJECT_NAME}-luacheck
COMMENT "`luacheck' is not found, so ${PROJECT_NAME}-luacheck target is dummy"
)
endif()

add_subdirectory(tarantool-tests)

add_custom_target(${PROJECT_NAME}-test DEPENDS
Expand All @@ -24,5 +53,6 @@ if(LUAJIT_USE_TEST)

add_custom_target(test DEPENDS
${PROJECT_NAME}-test
${PROJECT_NAME}-luacheck
)
endif()

0 comments on commit 6dd4724

Please sign in to comment.