@@ -42,7 +42,8 @@ set ( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
4242#-------------------------------------
4343# Collect source files for the library
4444#-------------------------------------
45- set ( JF_LIB_SRCS src/json_module.f90 )
45+ set ( JF_LIB_SRCS src/json_module.f90 )
46+ set ( JF_TEST_SRCS src/json_example.f90 )
4647
4748#-----------------------------------------
4849# Collect all the mod files into their own
@@ -90,7 +91,7 @@ endif ( ENABLE_DYLIBS_USE_RPATH )
9091set ( LIB_NAME ${CMAKE_PROJECT_NAME} )
9192add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
9293add_library ( ${LIB_NAME} -static STATIC ${JF_LIB_SRCS} )
93- set_target_properties ( ${LIB_NAME} -static
94+ set_target_properties ( ${LIB_NAME} -static
9495 PROPERTIES
9596 OUTPUT_NAME ${LIB_NAME}
9697 PREFIX lib
@@ -102,6 +103,17 @@ set_target_properties ( ${LIB_NAME}
102103 SOVERSION ${VERSION_MAJOR} .${VERSION_MINOR}
103104 VERSION ${VERSION} )
104105
106+ #--------------------------
107+ # Build the test executable
108+ #--------------------------
109+ add_executable ( test -${CMAKE_PROJECT_NAME} ${JF_TEST_SRCS} )
110+ target_link_libraries ( test -${CMAKE_PROJECT_NAME} ${LIB_NAME} )
111+ add_executable ( test -${CMAKE_PROJECT_NAME} -static ${JF_TEST_SRCS} )
112+ target_link_libraries ( test -${CMAKE_PROJECT_NAME} -static ${LIB_NAME} -static )
113+ set_target_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME} -static
114+ PROPERTIES
115+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin )
116+
105117#-------------------------------------
106118# Build the documentation with ROBODoc
107119#-------------------------------------
@@ -125,7 +137,7 @@ if ( NOT ROBODOC_SKIP_DOC_GEN )
125137 add_custom_command ( OUTPUT ${ROBO_OUTPUTS}
126138 COMMAND "${CMAKE_COMMAND} " -E make_directory "${DOC_DIR} " # Ensure DOC_DIR exists at build time
127139 COMMAND "${ROBODOC} " ${REQUIRED_ROBODOC_OPTIONS} ${ROBODOC_OPTIONS}
128- DEPENDS "${CMAKE_SOURCE_DIR} /${JF_LIB_SRCS} "
140+ DEPENDS "${CMAKE_SOURCE_DIR} /${JF_LIB_SRCS} " " ${CMAKE_SOURCE_DIR} / ${JF_TEST_SRCS} "
129141 COMMENT "Building HTML documentation for ${CMAKE_PROJECT_NAME} using ROBODoc" )
130142 add_custom_target ( documentation ALL
131143 DEPENDS ${ROBO_OUTPUTS} )
@@ -139,7 +151,112 @@ endif ( NOT ROBODOC_SKIP_DOC_GEN )
139151#---------------------------------------------------------------------
140152# Add some tests to ensure that the software is performing as expected
141153#---------------------------------------------------------------------
142- # Not implemented yet
154+ enable_testing ()
155+ find_program ( JSONLINT jsonlint )
156+ find_program ( DIFF diff )
157+ set ( DATA_DIR ${CMAKE_BINARY_DIR} /files )
158+ configure_file ( ${CMAKE_SOURCE_DIR} /files /test1.json ${DATA_DIR} /test1.json COPYONLY )
159+ configure_file ( ${CMAKE_SOURCE_DIR} /files /test5.json ${DATA_DIR} /test5.json COPYONLY )
160+
161+ # Validate input
162+ if ( JSONLINT )
163+ add_test ( NAME validate-input1
164+ WORKING_DIRECTORY ${DATA_DIR}
165+ COMMAND ${JSONLINT} test1.json )
166+ add_test ( NAME validate-input5
167+ WORKING_DIRECTORY ${DATA_DIR}
168+ COMMAND ${JSONLINT} test5.json )
169+ endif ( JSONLINT )
170+ # As of now these are kind of sniff tests... Need to modify test program to indicate failure with `stop` codes
171+ # or more easily parsed results, and be able to validate json sent to stdout
172+
173+ # Dynamic lib
174+ add_test ( NAME test -${CMAKE_PROJECT_NAME}
175+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /bin/
176+ COMMAND test -${CMAKE_PROJECT_NAME} )
177+ # Validate output
178+ if ( JSONLINT )
179+ add_test ( NAME validate-test2
180+ WORKING_DIRECTORY ${DATA_DIR}
181+ COMMAND ${JSONLINT} test2.json )
182+ add_test ( NAME validate-test4
183+ WORKING_DIRECTORY ${DATA_DIR}
184+ COMMAND ${JSONLINT} test4.json )
185+ endif ( JSONLINT )
186+ # Check output for differences
187+ if ( DIFF )
188+ add_test ( NAME test2-regression
189+ WORKING_DIRECTORY ${DATA_DIR}
190+ COMMAND ${DIFF} -q test2.json ${CMAKE_SOURCE_DIR} /files /test2.json )
191+ add_test ( NAME test4-regression
192+ WORKING_DIRECTORY ${DATA_DIR}
193+ COMMAND ${DIFF} -q test4.json ${CMAKE_SOURCE_DIR} /files /test4.json )
194+ else ( DIFF )
195+ message ( WARNING
196+ "For full test coverage diff, or a similar tool must be present on your system" )
197+ endif ( DIFF )
198+ set_tests_properties ( validate-test2 test2-regression
199+ PROPERTIES
200+ DEPENDS test -${CMAKE_PROJECT_NAME}
201+ REQUIRED_FILES "${DATA_DIR} /test2.json"
202+ RESOURCE_LOCK "${DATA_DIR} /test2.json" )
203+ set_tests_properties ( validate-test4 test4-regression
204+ PROPERTIES
205+ DEPENDS test -${CMAKE_PROJECT_NAME}
206+ REQUIRED_FILES "${DATA_DIR} /test4.json"
207+ RESOURCE_LOCK "${DATA_DIR} /test4.json" )
208+
209+ # Static lib
210+ add_test ( NAME test -${CMAKE_PROJECT_NAME} -static
211+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /bin/"
212+ COMMAND test -${CMAKE_PROJECT_NAME} -static )
213+ # Validate output
214+ if ( JSONLINT )
215+ add_test ( NAME validate-test2-static
216+ WORKING_DIRECTORY ${DATA_DIR}
217+ COMMAND ${JSONLINT} test2.json )
218+ add_test ( NAME validate-test4-static
219+ WORKING_DIRECTORY ${DATA_DIR}
220+ COMMAND ${JSONLINT} test4.json )
221+ endif ( JSONLINT )
222+ # Check output for differences
223+ if ( DIFF )
224+ add_test ( NAME test2-regression-static
225+ WORKING_DIRECTORY ${DATA_DIR}
226+ COMMAND ${DIFF} -q test2.json ${CMAKE_SOURCE_DIR} /files /test2.json )
227+ add_test ( NAME test4-regression-static
228+ WORKING_DIRECTORY ${DATA_DIR}
229+ COMMAND ${DIFF} -q test4.json ${CMAKE_SOURCE_DIR} /files /test4.json )
230+ endif ( DIFF )
231+ set_tests_properties ( validate-test2-static test2-regression-static
232+ PROPERTIES
233+ DEPENDS test -${CMAKE_PROJECT_NAME} -static
234+ REQUIRED_FILES "${DATA_DIR} /test2.json"
235+ RESOURCE_LOCK "${DATA_DIR} /test2.json" )
236+ set_tests_properties ( validate-test4-static test4-regression-static
237+ PROPERTIES
238+ DEPENDS test -${CMAKE_PROJECT_NAME} -static
239+ REQUIRED_FILES "${DATA_DIR} /test4.json"
240+ RESOURCE_LOCK "${DATA_DIR} /test4.json" )
241+
242+ if ( JSONLINT )
243+ set_tests_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME} -static
244+ PROPERTIES
245+ FAIL_REGULAR_EXPRESSION "Error;ERROR;error"
246+ REQUIRED_FILES "${DATA_DIR} /test1.json;${DATA_DIR} /test5.json"
247+ RESOURCE_LOCK "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json"
248+ DEPENDS "validate-input1;validate-input5" )
249+ else ( JSONLINT ) # Don't force validation of input if no JSONLINT
250+ message ( WARNING
251+ "For full test coverage please download and install jsonlint, a NODEJS package <http://nodejs.org>" )
252+ set_tests_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME} -static
253+ PROPERTIES
254+ FAIL_REGULAR_EXPRESSION "Error;ERROR;error"
255+ REQUIRED_FILES "${DATA_DIR} /test1.json;${DATA_DIR} /test5.json"
256+ RESOURCE_LOCK "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json" )
257+ endif ( JSONLINT )
258+ set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
259+ "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json" )
143260
144261#-------------------------
145262# Perform the installation
0 commit comments