Skip to content

Commit c5aa7d3

Browse files
committed
TESTING: Use fixtures to copy and cleanup files
- Fixes #413 - Also fixes regression testing and output validation
1 parent b41abbb commit c5aa7d3

File tree

4 files changed

+79
-44
lines changed

4 files changed

+79
-44
lines changed

CMakeLists.txt

+47-32
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,11 @@ if ( ENABLE_TESTS )
274274

275275
find_program ( JSONLINT jsonlint )
276276
find_program ( DIFF diff )
277-
file ( COPY "${CMAKE_SOURCE_DIR}/files"
278-
DESTINATION "${CMAKE_BINARY_DIR}/" )
279277

280-
set ( DATA_DIR "${CMAKE_BINARY_DIR}/files" )
278+
set ( DATA_DIR "${CMAKE_SOURCE_DIR}/files" )
281279

282280
set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
283-
"${DATA_DIR}/test2.json;${DATA_DIR}/test4.json;${FORD_CLEAN_OUTPUTS}" )
281+
"${FORD_CLEAN_OUTPUTS}" )
284282

285283
# Validate input
286284
if ( JSONLINT )
@@ -294,26 +292,38 @@ if ( ENABLE_TESTS )
294292
foreach ( VALID_JSON ${JSON_INPUTS} )
295293
get_filename_component ( TESTNAME "${VALID_JSON}" NAME )
296294
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}" )
299297
endforeach ()
300298

301299
foreach ( INVALID ${INVALID_JSON} )
302300
get_filename_component ( TESTNAME "${INVALID}" NAME )
303301
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}" )
306304
set_property ( TEST validate-${TESTNAME}
307-
PROPERTY
308-
WILL_FAIL TRUE)
305+
PROPERTY
306+
WILL_FAIL TRUE)
309307
endforeach ()
310308
endif ()
311309

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+
312322
set ( UNIT_TESTS '' )
313323
foreach ( UNIT_TEST ${JF_TEST_SRCS} )
314324
get_filename_component ( TEST ${UNIT_TEST} NAME_WE )
315325
if(MSVC_IDE)
316-
link_directories(${CMAKE_BINARY_DIR}/lib)
326+
link_directories(${CMAKE_BINARY_DIR}/lib)
317327
endif()
318328
add_executable ( ${TEST} EXCLUDE_FROM_ALL ${UNIT_TEST} )
319329
target_link_libraries ( ${TEST} ${LIB_NAME} )
@@ -325,11 +335,13 @@ if ( ENABLE_TESTS )
325335
add_test( NAME ${TEST}
326336
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
327337
COMMAND ./${TEST})
338+
set_tests_properties( ${TEST}
339+
PROPERTIES FIXTURES_REQUIRED JF)
328340
list ( APPEND UNIT_TESTS ${TEST} )
329341
if ( JSONLINT )
330342
set_property ( TEST ${TEST}
331-
APPEND
332-
PROPERTY DEPENDS validate-input1 validate-input2 )
343+
APPEND
344+
PROPERTY DEPENDS validate-input1 validate-input2 )
333345
endif()
334346
endforeach ( UNIT_TEST )
335347

@@ -338,34 +350,37 @@ if ( ENABLE_TESTS )
338350
PROPERTY DEPENDS jf_test_02 )
339351

340352
# 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+
341359
if ( JSONLINT )
342-
file ( GLOB JSON_FILES "${DATA_DIR}/*.json" )
343-
foreach ( JSON_FILE ${JSON_FILES} )
360+
foreach ( JSON_FILE ${EXPECTED_OUTPUTS} )
344361
get_filename_component ( TESTNAME ${JSON_FILE} NAME )
345362
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} )
348365
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})
353369
endforeach ( JSON_FILE )
354370
endif ()
355371

356372
# Check output for differences
357373
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} )
369384
endforeach ( JSON_FILE )
370385
else ()
371386
message ( WARNING

files/expected-outputs/test12.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"only one value"
8686
],
8787
"page": [
88-
"The quick brown fox",
88+
"The quick brown fox ",
8989
"jumps over the lazy dog."
9090
]
9191
}

files/expected-outputs/test2.json

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"inputs": {
3-
"t0": 0.1E+0,
4-
"tf": 0.11E+1,
3+
"t0": 0.10000000000000001E+0,
4+
"tf": 0.11000000000000001E+1,
55
"x0": 0.9999E+4,
66
"integer_scalar": 1,
77
"integer_array": [
@@ -20,7 +20,14 @@
2020
false,
2121
true
2222
],
23-
"null_variable": null
23+
"null_variable": null,
24+
"special chars": "\\ /",
25+
"special chars in key \\ /": "\\ /",
26+
"bspace": "\b",
27+
"horizontal_tab": "\t",
28+
"newline": "\n",
29+
"formfeed": "\f",
30+
"carriage_return": "\r"
2431
},
2532
"trajectory": [
2633
{
@@ -58,35 +65,35 @@
5865
},
5966
{
6067
"VARIABLE": "Vx",
61-
"UNITS": "km\/s",
68+
"UNITS": "km/s",
6269
"FRAME": "J2000",
6370
"CENTER": "EARTH",
6471
"DATA": [
6572
0.1E-2,
6673
0.2E-2,
67-
0.3E-2
74+
0.30000000000000001E-2
6875
]
6976
},
7077
{
7178
"VARIABLE": "Vy",
72-
"UNITS": "km\/s",
79+
"UNITS": "km/s",
7380
"FRAME": "J2000",
7481
"CENTER": "EARTH",
7582
"DATA": [
7683
0.2E-2,
7784
0.2E-1,
78-
0.3E-2
85+
0.30000000000000001E-2
7986
]
8087
},
8188
{
8289
"VARIABLE": "Vz",
83-
"UNITS": "km\/s",
90+
"UNITS": "km/s",
8491
"FRAME": "J2000",
8592
"CENTER": "EARTH",
8693
"DATA": [
87-
0.3E-2,
88-
0.3E-1,
89-
0.4E-1
94+
0.30000000000000001E-2,
95+
0.29999999999999999E-1,
96+
0.40000000000000001E-1
9097
]
9198
}
9299
]

files/expected-outputs/test21.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"value": [
3+
0.14142135623730951E+1,
4+
0.17320508075688772E+1,
5+
0.26457513110645907E+1,
6+
0.14142135623730951E+3,
7+
0.54772255750516615E+3,
8+
0.26457513110645905E+4,
9+
0.17976931348623157E+309,
10+
0.22250738585072014E-307,
11+
0.22204460492503131E-15
12+
]
13+
}

0 commit comments

Comments
 (0)