cmake_minimum_required( VERSION 3.20 )
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../src)
add_executable( csv csv.cpp )
target_link_libraries( csv cparse )
# Smoke test: pins the walkthrough's documented "Trying it" transcript.
# Regression guard — this example previously called parse() to "set up
# the cursor" before driving nextRow(), which segfaulted (parse() tears
# the cursor down as soon as its own start() returns); replaced with the
# library's openStream(). This test would have caught that.
add_test(
NAME csv.smoke
COMMAND ${CMAKE_COMMAND}
-DEXE=$<TARGET_FILE:csv>
-DARG=${CMAKE_CURRENT_SOURCE_DIR}/../tests/fixture.csv
-DEXPECTED=${CMAKE_CURRENT_SOURCE_DIR}/../tests/expected.txt
-P ${CMAKE_CURRENT_SOURCE_DIR}/../../run_and_diff.cmake
)
# The malformed-input diagnostic: pins that the error points at the
# opening quote's line:col, not end-of-file (documented explicitly in
# the walkthrough's "Line/column reporting" section).
add_test(
NAME csv.malformed_diagnostic
COMMAND ${CMAKE_COMMAND}
-DEXE=$<TARGET_FILE:csv>
-DARG=${CMAKE_CURRENT_SOURCE_DIR}/../tests/malformed.csv
-DEXPECTED=${CMAKE_CURRENT_SOURCE_DIR}/../tests/expected-malformed.txt
-DMATCH=1
-P ${CMAKE_CURRENT_SOURCE_DIR}/../../run_and_diff.cmake
)
# Regression guard: running with no argument at all used to crash
# (std::string construction from argv[1]==nullptr throws std::logic_error)
# instead of printing a usage message and exiting 1.
add_test(
NAME csv.no_argument
COMMAND ${CMAKE_COMMAND}
-DEXE=$<TARGET_FILE:csv>
-DEXPECTED=${CMAKE_CURRENT_SOURCE_DIR}/../tests/expected-usage.txt
-DMATCH=1
-DRC=1
-P ${CMAKE_CURRENT_SOURCE_DIR}/../../run_and_diff.cmake
)