JSON: Adding ctest

This commit adds node based tests provided by Nico to the ctest
framework already established in UPM.

Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Abhishek Malik
2017-08-28 17:15:00 -07:00
parent 0bf4a38f5e
commit 303323fa3a
4 changed files with 65 additions and 0 deletions

View File

@ -74,3 +74,11 @@ if (BUILDSWIGPYTHON AND PYTHON3INTERP_FOUND)
${CMAKE_SOURCE_DIR}/examples/python/*.py
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/src/)
endif (BUILDSWIGPYTHON AND PYTHON3INTERP_FOUND)
# add JSON test
if(NPM_EXECUTABLE)
add_test (NAME check_jsons COMMAND ${CMAKE_COMMAND}
-DNPMEXEC=${NPM_EXECUTABLE}
-DUPMBASEDIR=${CMAKE_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/tests/runjsontest.cmake)
endif(NPM_EXECUTABLE)

36
tests/runjsontest.cmake Normal file
View File

@ -0,0 +1,36 @@
# This macro sets up the initial JSON test environment
# it copies over everything required by the test over to the
# build directory so that the tests can be run from there
macro(SETUP_JSON_COLLATERAL UBD NE)
execute_process(COMMAND mkdir -p ${UBD}/build/node_test;
COMMAND cp ${UBD}/tests/node/package.json ${UBD}/build/node_test/;
COMMAND cp ${UBD}/tests/node/jsonlint.js ${UBD}/build/node_test/;
COMMAND cp ${UBD}/tests/node/test.js ${UBD}/build/node_test/;
COMMAND ${NE} install --prefix=${UBD}/build/node_test/;
RESULT_VARIABLE ret_val
)
if(ret_val)
message(FATAL_ERROR "value of result of first test: ${ret_val_1}")
endif()
endmacro()
# This macro runs the json test and checks the json files for
# their validity and also checks for the required fields
macro(EXEC_JSON_TEST UBD NE)
execute_process(COMMAND ${NE} test --prefix=${UBD}/build/node_test/
RESULT_VARIABLE ret_val
)
execute_process(COMMAND rm -rf ${UBD}/build/node_test)
if(ret_val)
message(FATAL_ERROR "value of the result of the second test: ${ret_val_2}")
endif()
endmacro()
# this macro removes all the JSON collateral from the build directory
#macro(REMOVE_JSON_COLLATERAL UBD)
# execute_process(COMMAND rm -rf ${UBD}/build/node_test)
#endmacro()
setup_json_collateral(${UPMBASEDIR} ${NPMEXEC})
exec_json_test(${UPMBASEDIR} ${NPMEXEC})
#remove_json_collateral(${UPMBASEDIR})