Generate a lua module to help pass build-related settings.

This allows us to avoid hard-coding paths and using environment
variables to communicate key information to unit tests, which fits
with the overall goal of making sure that folks driving CMake directly
can continue to do out-of-tree builds.
This commit is contained in:
John Szakmeister
2014-04-30 05:10:37 -04:00
parent 4fe0a51844
commit 7cb20fd1b0
4 changed files with 26 additions and 25 deletions

View File

@@ -136,16 +136,22 @@ if(NOT BUSTED_OUTPUT_TYPE)
endif() endif()
if(BUSTED_PRG) if(BUSTED_PRG)
get_target_property(NVIM_TEST_LIB nvim-test LOCATION) get_property(TEST_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
PROPERTY INCLUDE_DIRECTORIES)
get_target_property(TEST_LIBNVIM_PATH nvim-test LOCATION)
configure_file(
test/config/paths.lua.in
${CMAKE_BINARY_DIR}/test/config/paths.lua)
add_custom_target(unittest add_custom_target(unittest
COMMAND ${CMAKE_COMMAND} COMMAND ${CMAKE_COMMAND}
-DBUSTED_PRG=${BUSTED_PRG} -DBUSTED_PRG=${BUSTED_PRG}
-DLUA_PRG=${LUA_PRG} -DLUA_PRG=${LUA_PRG}
-DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DWORKING_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-DNVIM_TEST_LIB=${NVIM_TEST_LIB}
-DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE} -DBUSTED_OUTPUT_TYPE=${BUSTED_OUTPUT_TYPE}
-DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test -DTEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/test
-DTEST_INCLUDES=${CMAKE_BINARY_DIR}/test/includes/post -DBUILD_DIR=${CMAKE_BINARY_DIR}
-P ${CMAKE_MODULE_PATH}/RunUnittests.cmake -P ${CMAKE_MODULE_PATH}/RunUnittests.cmake
DEPENDS nvim-test unittest-headers) DEPENDS nvim-test unittest-headers)
endif() endif()

View File

@@ -1,13 +1,11 @@
get_filename_component(BUSTED_DIR ${BUSTED_PRG} PATH) get_filename_component(BUSTED_DIR ${BUSTED_PRG} PATH)
set(ENV{PATH} "${BUSTED_DIR}:$ENV{PATH}") set(ENV{PATH} "${BUSTED_DIR}:$ENV{PATH}")
set(ENV{NVIM_TEST_LIB} ${NVIM_TEST_LIB})
set(ENV{TEST_INCLUDES} ${TEST_INCLUDES})
if(DEFINED ENV{TEST_FILE}) if(DEFINED ENV{TEST_FILE})
set(TEST_DIR $ENV{TEST_FILE}) set(TEST_DIR $ENV{TEST_FILE})
endif() endif()
execute_process( execute_process(
COMMAND ${BUSTED_PRG} -o ${BUSTED_OUTPUT_TYPE} --pattern=.moon ${TEST_DIR} COMMAND ${BUSTED_PRG} -o ${BUSTED_OUTPUT_TYPE} --lpath=${BUILD_DIR}/?.lua --pattern=.moon ${TEST_DIR}
WORKING_DIRECTORY ${WORKING_DIR} WORKING_DIRECTORY ${WORKING_DIR}
RESULT_VARIABLE res) RESULT_VARIABLE res)

11
test/config/paths.lua.in Normal file
View File

@@ -0,0 +1,11 @@
local module = {}
module.include_paths = {}
for p in ("${TEST_INCLUDE_DIRS}" .. ";"):gmatch("[^;]+") do
table.insert(module.include_paths, p)
end
module.test_include_path = "${CMAKE_BINARY_DIR}/test/includes/post"
module.test_libnvim_path = "${TEST_LIBNVIM_PATH}"
return module

View File

@@ -3,24 +3,14 @@ lpeg = require 'lpeg'
formatc = require 'test.unit.formatc' formatc = require 'test.unit.formatc'
Set = require 'test.unit.set' Set = require 'test.unit.set'
Preprocess = require 'test.unit.preprocess' Preprocess = require 'test.unit.preprocess'
Paths = require 'test.config.paths'
-- add some standard header locations -- add some standard header locations
-- TODO(aktau, jszakmeister): optionally pass more header locations via env for i,p in ipairs(Paths.include_paths)
Preprocess.add_to_include_path('./src') Preprocess.add_to_include_path(p)
Preprocess.add_to_include_path('./.deps/usr/include')
Preprocess.add_to_include_path('./build/config')
if ffi.abi('32bit')
Preprocess.add_to_include_path('/opt/neovim-deps/32/include')
else
Preprocess.add_to_include_path('/opt/neovim-deps/include')
-- load neovim shared library -- load neovim shared library
testlib = os.getenv 'NVIM_TEST_LIB' libnvim = ffi.load Paths.test_libnvim_path
unless testlib
testlib = './build/src/libnvim-test.so'
libnvim = ffi.load testlib
trim = (s) -> trim = (s) ->
s\match'^%s*(.*%S)' or '' s\match'^%s*(.*%S)' or ''
@@ -91,12 +81,8 @@ cimport = (...) ->
return libnvim return libnvim
testinc = os.getenv 'TEST_INCLUDES'
unless testinc
testinc = './build/test/includes/post'
cppimport = (path) -> cppimport = (path) ->
return cimport testinc .. '/' .. path return cimport Paths.test_include_path .. '/' .. path
cimport './src/types.h' cimport './src/types.h'