@@ -274,13 +274,11 @@ if ( ENABLE_TESTS )
274
274
275
275
find_program ( JSONLINT jsonlint )
276
276
find_program ( DIFF diff )
277
- file ( COPY "${CMAKE_SOURCE_DIR} /files"
278
- DESTINATION "${CMAKE_BINARY_DIR} /" )
279
277
280
- set ( DATA_DIR "${CMAKE_BINARY_DIR } /files" )
278
+ set ( DATA_DIR "${CMAKE_SOURCE_DIR } /files" )
281
279
282
280
set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
283
- "${DATA_DIR} /test2.json; ${DATA_DIR} /test4.json; ${ FORD_CLEAN_OUTPUTS} " )
281
+ "${FORD_CLEAN_OUTPUTS} " )
284
282
285
283
# Validate input
286
284
if ( JSONLINT )
@@ -294,26 +292,38 @@ if ( ENABLE_TESTS )
294
292
foreach ( VALID_JSON ${JSON_INPUTS} )
295
293
get_filename_component ( TESTNAME "${VALID_JSON} " NAME )
296
294
add_test ( NAME validate-${TESTNAME}
297
- WORKING_DIRECTORY "${DATA_DIR} /inputs"
298
- COMMAND ${JSONLINT} "--allow=nonescape-characters" "${VALID_JSON} " )
295
+ WORKING_DIRECTORY "${DATA_DIR} /inputs"
296
+ COMMAND ${JSONLINT} "--allow=nonescape-characters" "${VALID_JSON} " )
299
297
endforeach ()
300
298
301
299
foreach ( INVALID ${INVALID_JSON} )
302
300
get_filename_component ( TESTNAME "${INVALID} " NAME )
303
301
add_test ( NAME validate-${TESTNAME}
304
- WORKING_DIRECTORY "${DATA_DIR} /inputs"
305
- COMMAND ${JSONLINT} "${INVALID} " )
302
+ WORKING_DIRECTORY "${DATA_DIR} /inputs"
303
+ COMMAND ${JSONLINT} "${INVALID} " )
306
304
set_property ( TEST validate-${TESTNAME}
307
- PROPERTY
308
- WILL_FAIL TRUE )
305
+ PROPERTY
306
+ WILL_FAIL TRUE )
309
307
endforeach ()
310
308
endif ()
311
309
310
+ add_test (NAME jf-cleanup-fixture
311
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} "
312
+ COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR} /files" )
313
+ set_tests_properties (jf-cleanup-fixture
314
+ PROPERTIES FIXTURES_SETUP JF)
315
+ add_test (NAME jf-setup-fixture
316
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} "
317
+ COMMAND ${CMAKE_COMMAND} -E copy_directory "${DATA_DIR} " "${CMAKE_BINARY_DIR} /files" )
318
+ set_tests_properties (jf-setup-fixture
319
+ PROPERTIES FIXTURES_SETUP JF
320
+ DEPENDS jf-cleanup-fixture)
321
+
312
322
set ( UNIT_TESTS '' )
313
323
foreach ( UNIT_TEST ${JF_TEST_SRCS} )
314
324
get_filename_component ( TEST ${UNIT_TEST} NAME_WE )
315
325
if (MSVC_IDE )
316
- link_directories (${CMAKE_BINARY_DIR} /lib)
326
+ link_directories (${CMAKE_BINARY_DIR} /lib)
317
327
endif ()
318
328
add_executable ( ${TEST} EXCLUDE_FROM_ALL ${UNIT_TEST} )
319
329
target_link_libraries ( ${TEST} ${LIB_NAME} )
@@ -325,11 +335,13 @@ if ( ENABLE_TESTS )
325
335
add_test ( NAME ${TEST}
326
336
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} /bin
327
337
COMMAND ./${TEST} )
338
+ set_tests_properties ( ${TEST}
339
+ PROPERTIES FIXTURES_REQUIRED JF)
328
340
list ( APPEND UNIT_TESTS ${TEST} )
329
341
if ( JSONLINT )
330
342
set_property ( TEST ${TEST}
331
- APPEND
332
- PROPERTY DEPENDS validate-input1 validate-input2 )
343
+ APPEND
344
+ PROPERTY DEPENDS validate-input1 validate-input2 )
333
345
endif ()
334
346
endforeach ( UNIT_TEST )
335
347
@@ -338,34 +350,37 @@ if ( ENABLE_TESTS )
338
350
PROPERTY DEPENDS jf_test_02 )
339
351
340
352
# Validate output
353
+ file ( GLOB EXPECTED_OUTPUTS "${DATA_DIR} /expected-outputs/*.json" )
354
+ if (NOT ${ENABLE_UNICODE} )
355
+ list ( REMOVE_ITEM EXPECTED_OUTPUTS "${DATA_DIR} /expected-outputs/hello-world-ucs4.json" )
356
+ endif ()
357
+ list ( REMOVE_ITEM EXPECTED_OUTPUTS "${DATA_DIR} /expected-outputs/example2.json" )
358
+
341
359
if ( JSONLINT )
342
- file ( GLOB JSON_FILES "${DATA_DIR} /*.json" )
343
- foreach ( JSON_FILE ${JSON_FILES} )
360
+ foreach ( JSON_FILE ${EXPECTED_OUTPUTS} )
344
361
get_filename_component ( TESTNAME ${JSON_FILE} NAME )
345
362
add_test ( NAME validate-output -${TESTNAME}
346
- WORKING_DIRECTORY "${DATA_DIR} "
347
- COMMAND ${JSONLINT} "--allow=nonescape-characters" ${TESTNAME} )
363
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /files "
364
+ COMMAND ${JSONLINT} "--allow=nonescape-characters" ${TESTNAME} )
348
365
set_property ( TEST validate-output -${TESTNAME}
349
- APPEND
350
- PROPERTY
351
- DEPENDS ${UNIT_TESTS}
352
- REQUIRED_FILES ${JSON_FILES} )
366
+ APPEND
367
+ PROPERTY
368
+ DEPENDS ${UNIT_TESTS} )
353
369
endforeach ( JSON_FILE )
354
370
endif ()
355
371
356
372
# Check output for differences
357
373
if ( DIFF )
358
- file ( GLOB JSON_FILES "${DATA_DIR} /*.json" )
359
- foreach ( JSON_FILE ${JSON_FILES} )
360
- get_filename_component ( JSON_STEM ${JSON_FILE} NAME_WE )
361
- add_test ( NAME regression-${JSON_STEM} .json
362
- WORKING_DIRECTORY "${DATA_DIR} "
363
- COMMAND ${DIFF} -q ${JSON_STEM} .json expected-outputs/${JSON_STEM} .json )
364
- set_property ( TEST regression-${JSON_STEM} .json
365
- APPEND
366
- PROPERTY
367
- DEPENDS ${UNIT_TESTS}
368
- REQUIRED_FILES ${JSON_FILES} )
374
+ foreach ( JSON_FILE ${EXPECTED_OUTPUTS} )
375
+ get_filename_component (OUTPUT ${JSON_FILE} NAME )
376
+ add_test ( NAME regression-${OUTPUT}
377
+ WORKING_DIRECTORY "${CMAKE_BINARY_DIR} /files"
378
+ COMMAND ${DIFF} -q ${OUTPUT} expected-outputs/${OUTPUT} )
379
+ set_property ( TEST regression-${OUTPUT}
380
+ APPEND
381
+ PROPERTY
382
+ DEPENDS ${UNIT_TESTS}
383
+ REQUIRED_FILES ${EXPECTED_OUTPUTS} )
369
384
endforeach ( JSON_FILE )
370
385
else ()
371
386
message ( WARNING
0 commit comments