mirror of
https://github.com/nlohmann/json.git
synced 2026-09-06 16:27:59 +00:00
De-duplicate the diagnostic-positions test files via define-based recompilation
tests/src/unit-class_parser_diagnostic_positions.cpp and tests/src/unit-diagnostic-positions-only.cpp were maintained as near-copies of unit-class_parser.cpp and unit-diagnostic-positions.cpp respectively, and had drifted: trailing-comma handling, the #5342 filter-array/filter-value sections, and the cross-input-adapter diagnostics test were never ported to the positions-enabled copy. Fold the position-specific assertions into the base files, guarded by #if JSON_DIAGNOSTIC_POSITIONS / #if JSON_DIAGNOSTICS, and compile each base file a second time with the relevant macro set via CMake COMPILE_DEFINITIONS (mirroring the existing test-comparison_legacy pattern) instead of maintaining a separate source file. This removes the duplication and, as a side effect, closes the coverage gaps above since the full test file now compiles under JSON_DIAGNOSTIC_POSITIONS=1 as well. Fixes #5417 Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -177,6 +177,24 @@ json_test_add_test_for(src/unit-comparison.cpp
|
||||
MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force}
|
||||
)
|
||||
|
||||
# test the parser again with JSON_DIAGNOSTIC_POSITIONS enabled
|
||||
json_test_set_test_options(test-class_parser_diagnostic_positions
|
||||
COMPILE_DEFINITIONS JSON_DIAGNOSTIC_POSITIONS=1
|
||||
)
|
||||
json_test_add_test_for(src/unit-class_parser.cpp
|
||||
NAME test-class_parser_diagnostic_positions
|
||||
MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force}
|
||||
)
|
||||
|
||||
# test diagnostic positions again without regular diagnostics (JSON pointer paths)
|
||||
json_test_set_test_options(test-diagnostic-positions_only
|
||||
COMPILE_DEFINITIONS JSON_DIAGNOSTICS=0
|
||||
)
|
||||
json_test_add_test_for(src/unit-diagnostic-positions.cpp
|
||||
NAME test-diagnostic-positions_only
|
||||
MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force}
|
||||
)
|
||||
|
||||
# *DO NOT* use json_test_set_test_options() below this line
|
||||
|
||||
#############################################################################
|
||||
|
||||
Reference in New Issue
Block a user