From 303323fa3a7c4dbcdc744710349bedc4d165d63e Mon Sep 17 00:00:00 2001 From: Abhishek Malik Date: Mon, 28 Aug 2017 17:15:00 -0700 Subject: [PATCH] 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 --- CMakeLists.txt | 8 ++++++++ cmake/modules/FindNpm.cmake | 13 +++++++++++++ tests/CMakeLists.txt | 8 ++++++++ tests/runjsontest.cmake | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 cmake/modules/FindNpm.cmake create mode 100644 tests/runjsontest.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a6098cb..b2fc02fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,6 +149,14 @@ find_package (JPEG) # Find nodejs if (BUILDSWIGNODE) find_package (Node REQUIRED) + if (BUILDTESTS) + find_package (Npm REQUIRED) + if(NPM_EXECUTABLE) + message(STATUS "NPM Executable found at: ${NPM_EXECUTABLE}") + else() + message(FATAL_ERROR "Please install NPM first, you can't run tests without it") + endif() + endif (BUILDTESTS) endif (BUILDSWIGNODE) # Find JAVA/JNI diff --git a/cmake/modules/FindNpm.cmake b/cmake/modules/FindNpm.cmake new file mode 100644 index 00000000..5937b7b8 --- /dev/null +++ b/cmake/modules/FindNpm.cmake @@ -0,0 +1,13 @@ +# Finding and pointing a variable to the npm executable if found +# Only works on Linux systems as of now + +find_program(NPM_EXECUTABLE NAMES npm + HINTS + /usr +) + +if(NPM_EXECUTABLE) + message(STATUS "NPM Executable found at ${NPM_EXECUTABLE}") +else() + message(ERROR "Unable to find NPM installation, please install NPM") +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ca7f6509..f0e540d3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/runjsontest.cmake b/tests/runjsontest.cmake new file mode 100644 index 00000000..d9eec9e5 --- /dev/null +++ b/tests/runjsontest.cmake @@ -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})