@@ -42,7 +42,8 @@ set ( VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
42
42
#-------------------------------------
43
43
# Collect source files for the library
44
44
#-------------------------------------
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 )
46
47
47
48
#-----------------------------------------
48
49
# Collect all the mod files into their own
@@ -90,7 +91,7 @@ endif ( ENABLE_DYLIBS_USE_RPATH )
90
91
set ( LIB_NAME ${CMAKE_PROJECT_NAME} )
91
92
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
92
93
add_library ( ${LIB_NAME} -static STATIC ${JF_LIB_SRCS} )
93
- set_target_properties ( ${LIB_NAME} -static
94
+ set_target_properties ( ${LIB_NAME} -static
94
95
PROPERTIES
95
96
OUTPUT_NAME ${LIB_NAME}
96
97
PREFIX lib
@@ -104,6 +105,17 @@ set_target_properties ( ${LIB_NAME}
104
105
VERSION ${VERSION}
105
106
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /lib )
106
107
108
+ #--------------------------
109
+ # Build the test executable
110
+ #--------------------------
111
+ add_executable ( test -${CMAKE_PROJECT_NAME} ${JF_TEST_SRCS} )
112
+ target_link_libraries ( test -${CMAKE_PROJECT_NAME} ${LIB_NAME} )
113
+ add_executable ( test -${CMAKE_PROJECT_NAME}-static ${JF_TEST_SRCS} )
114
+ target_link_libraries ( test -${CMAKE_PROJECT_NAME}-static ${LIB_NAME} -static )
115
+ set_target_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME}-static
116
+ PROPERTIES
117
+ RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} /bin )
118
+
107
119
#-------------------------------------
108
120
# Build the documentation with ROBODoc
109
121
#-------------------------------------
@@ -132,7 +144,7 @@ if ( NOT ROBODOC_SKIP_DOC_GEN )
132
144
add_custom_command ( OUTPUT ${ROBODOC_OUTPUTS}
133
145
COMMAND "${CMAKE_COMMAND} " -E make_directory "${DOC_DIR} " # Ensure DOC_DIR exists at build time
134
146
COMMAND "${ROBODOC} " ${REQUIRED_ROBODOC_OPTIONS} ${ROBODOC_OPTIONS}
135
- DEPENDS "${CMAKE_SOURCE_DIR} /${JF_LIB_SRCS} "
147
+ DEPENDS "${CMAKE_SOURCE_DIR} /${JF_LIB_SRCS} " " ${CMAKE_SOURCE_DIR} / ${JF_TEST_SRCS} "
136
148
COMMENT "Building HTML documentation for ${CMAKE_PROJECT_NAME} using ROBODoc" )
137
149
add_custom_target ( documentation ALL
138
150
DEPENDS ${ROBODOC_OUTPUTS} )
@@ -145,7 +157,112 @@ endif ( NOT ROBODOC_SKIP_DOC_GEN )
145
157
#---------------------------------------------------------------------
146
158
# Add some tests to ensure that the software is performing as expected
147
159
#---------------------------------------------------------------------
148
- # Not implemented yet
160
+ enable_testing ()
161
+ find_program ( JSONLINT jsonlint )
162
+ find_program ( DIFF diff )
163
+ set ( DATA_DIR ${CMAKE_BINARY_DIR} /files )
164
+ configure_file ( ${CMAKE_SOURCE_DIR} /files/test1.json ${DATA_DIR} /test1.json COPYONLY )
165
+ configure_file ( ${CMAKE_SOURCE_DIR} /files/test5.json ${DATA_DIR} /test5.json COPYONLY )
166
+
167
+ # Validate input
168
+ if ( JSONLINT )
169
+ add_test ( NAME validate-input1
170
+ WORKING_DIRECTORY ${DATA_DIR}
171
+ COMMAND ${JSONLINT} test1.json )
172
+ add_test ( NAME validate-input5
173
+ WORKING_DIRECTORY ${DATA_DIR}
174
+ COMMAND ${JSONLINT} test5.json )
175
+ endif ( JSONLINT )
176
+ # As of now these are kind of sniff tests... Need to modify test program to indicate failure with `stop` codes
177
+ # or more easily parsed results, and be able to validate json sent to stdout
178
+
179
+ # Dynamic lib
180
+ add_test ( NAME test -${CMAKE_PROJECT_NAME}
181
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /bin/
182
+ COMMAND test -${CMAKE_PROJECT_NAME} )
183
+ # Validate output
184
+ if ( JSONLINT )
185
+ add_test ( NAME validate-test2
186
+ WORKING_DIRECTORY ${DATA_DIR}
187
+ COMMAND ${JSONLINT} test2.json )
188
+ add_test ( NAME validate-test4
189
+ WORKING_DIRECTORY ${DATA_DIR}
190
+ COMMAND ${JSONLINT} test4.json )
191
+ endif ( JSONLINT )
192
+ # Check output for differences
193
+ if ( DIFF )
194
+ add_test ( NAME test2-regression
195
+ WORKING_DIRECTORY ${DATA_DIR}
196
+ COMMAND ${DIFF} -q test2.json ${CMAKE_SOURCE_DIR} /files/test2.json )
197
+ add_test ( NAME test4-regression
198
+ WORKING_DIRECTORY ${DATA_DIR}
199
+ COMMAND ${DIFF} -q test4.json ${CMAKE_SOURCE_DIR} /files/test4.json )
200
+ else ( DIFF )
201
+ message ( WARNING
202
+ "For full test coverage diff, or a similar tool must be present on your system" )
203
+ endif ( DIFF )
204
+ set_tests_properties ( validate-test2 test2-regression
205
+ PROPERTIES
206
+ DEPENDS test -${CMAKE_PROJECT_NAME}
207
+ REQUIRED_FILES "${DATA_DIR} /test2.json"
208
+ RESOURCE_LOCK "${DATA_DIR} /test2.json" )
209
+ set_tests_properties ( validate-test4 test4-regression
210
+ PROPERTIES
211
+ DEPENDS test -${CMAKE_PROJECT_NAME}
212
+ REQUIRED_FILES "${DATA_DIR} /test4.json"
213
+ RESOURCE_LOCK "${DATA_DIR} /test4.json" )
214
+
215
+ # Static lib
216
+ add_test ( NAME test -${CMAKE_PROJECT_NAME}-static
217
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /bin/"
218
+ COMMAND test -${CMAKE_PROJECT_NAME}-static )
219
+ # Validate output
220
+ if ( JSONLINT )
221
+ add_test ( NAME validate-test2-static
222
+ WORKING_DIRECTORY ${DATA_DIR}
223
+ COMMAND ${JSONLINT} test2.json )
224
+ add_test ( NAME validate-test4-static
225
+ WORKING_DIRECTORY ${DATA_DIR}
226
+ COMMAND ${JSONLINT} test4.json )
227
+ endif ( JSONLINT )
228
+ # Check output for differences
229
+ if ( DIFF )
230
+ add_test ( NAME test2-regression-static
231
+ WORKING_DIRECTORY ${DATA_DIR}
232
+ COMMAND ${DIFF} -q test2.json ${CMAKE_SOURCE_DIR} /files/test2.json )
233
+ add_test ( NAME test4-regression-static
234
+ WORKING_DIRECTORY ${DATA_DIR}
235
+ COMMAND ${DIFF} -q test4.json ${CMAKE_SOURCE_DIR} /files/test4.json )
236
+ endif ( DIFF )
237
+ set_tests_properties ( validate-test2-static test2-regression-static
238
+ PROPERTIES
239
+ DEPENDS test -${CMAKE_PROJECT_NAME}-static
240
+ REQUIRED_FILES "${DATA_DIR} /test2.json"
241
+ RESOURCE_LOCK "${DATA_DIR} /test2.json" )
242
+ set_tests_properties ( validate-test4-static test4-regression-static
243
+ PROPERTIES
244
+ DEPENDS test -${CMAKE_PROJECT_NAME}-static
245
+ REQUIRED_FILES "${DATA_DIR} /test4.json"
246
+ RESOURCE_LOCK "${DATA_DIR} /test4.json" )
247
+
248
+ if ( JSONLINT )
249
+ set_tests_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME}-static
250
+ PROPERTIES
251
+ FAIL_REGULAR_EXPRESSION "Error;ERROR;error"
252
+ REQUIRED_FILES "${DATA_DIR} /test1.json;${DATA_DIR} /test5.json"
253
+ RESOURCE_LOCK "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json"
254
+ DEPENDS "validate-input1;validate-input5" )
255
+ else ( JSONLINT ) # Don't force validation of input if no JSONLINT
256
+ message ( WARNING
257
+ "For full test coverage please download and install jsonlint, a NODEJS package <http://nodejs.org>" )
258
+ set_tests_properties ( test -${CMAKE_PROJECT_NAME} test -${CMAKE_PROJECT_NAME}-static
259
+ PROPERTIES
260
+ FAIL_REGULAR_EXPRESSION "Error;ERROR;error"
261
+ REQUIRED_FILES "${DATA_DIR} /test1.json;${DATA_DIR} /test5.json"
262
+ RESOURCE_LOCK "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json" )
263
+ endif ( JSONLINT )
264
+ set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
265
+ "${DATA_DIR} /test2.json;${DATA_DIR} /test4.json" )
149
266
150
267
#-------------------------
151
268
# Perform the installation
0 commit comments