Skip to content

Commit 79caa43

Browse files
committed
cost_analysis: harden test harness; scope runtime output dir
1 parent 4f5ab8a commit 79caa43

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

utilities/cost_analysis/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
include(FindOrFetchCLI11)
22
include(FindOrFetchJSON)
33

4-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
5-
64
add_executable(cost_analysis cost_analysis.cpp report.cpp)
7-
set_target_properties(cost_analysis PROPERTIES CXX_SCAN_FOR_MODULES OFF)
5+
set_target_properties(cost_analysis PROPERTIES
6+
CXX_SCAN_FOR_MODULES OFF
7+
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
88
target_link_libraries(cost_analysis PRIVATE
99
SeQuant::mbpt nlohmann_json::nlohmann_json CLI11::CLI11)
1010
target_set_warning_flags(cost_analysis)
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Runs cost_analysis on ${SRC}/${NAME}.json and diffs the report against
22
# ${SRC}/${NAME}.md.expected (volatile lines stripped). If ${DUMP} is set, also
33
# checks that the --dump_tree file for that result exists.
4-
execute_process(COMMAND ${EXE} --driver ${SRC}/${NAME}.json
5-
WORKING_DIRECTORY ${SRC} RESULT_VARIABLE rc)
4+
execute_process(COMMAND "${EXE}" --driver "${SRC}/${NAME}.json"
5+
WORKING_DIRECTORY "${SRC}" RESULT_VARIABLE rc)
66
if(NOT rc EQUAL 0)
77
message(FATAL_ERROR "cost_analysis exited ${rc}")
88
endif()
99

1010
function(strip_volatile in out)
11-
file(STRINGS ${in} lines)
11+
file(STRINGS "${in}" lines)
1212
set(kept "")
1313
foreach(line IN LISTS lines)
1414
if(NOT line MATCHES "^_SeQuant:")
@@ -20,20 +20,30 @@ function(strip_volatile in out)
2020
# hook, while the tool's live (gitignored) report always ends in one; only
2121
# the trailing-newline count should differ, so collapse both sides equally.
2222
string(REGEX REPLACE "\n+$" "\n" kept "${kept}")
23-
file(WRITE ${out} "${kept}")
23+
file(WRITE "${out}" "${kept}")
2424
endfunction()
2525

26-
strip_volatile(${SRC}/${NAME}.md ${SRC}/${NAME}.md.filtered)
27-
strip_volatile(${SRC}/${NAME}.md.expected ${SRC}/${NAME}.md.expected.filtered)
28-
execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files
29-
${SRC}/${NAME}.md.filtered ${SRC}/${NAME}.md.expected.filtered
26+
# file(STRINGS) treats a missing input as empty, so a report that was never
27+
# written would slip through strip_volatile as an empty file and misreport as a
28+
# content diff. Fail clearly instead.
29+
if(NOT EXISTS "${SRC}/${NAME}.md")
30+
message(FATAL_ERROR "report ${NAME}.md was not produced")
31+
endif()
32+
strip_volatile("${SRC}/${NAME}.md" "${SRC}/${NAME}.md.filtered")
33+
strip_volatile("${SRC}/${NAME}.md.expected" "${SRC}/${NAME}.md.expected.filtered")
34+
# compare_files: 0 == identical, 1 == differ, anything else == error; report
35+
# the last distinctly so a broken comparison isn't misread as a content diff.
36+
execute_process(COMMAND "${CMAKE_COMMAND}" -E compare_files
37+
"${SRC}/${NAME}.md.filtered" "${SRC}/${NAME}.md.expected.filtered"
3038
RESULT_VARIABLE diff)
31-
if(NOT diff EQUAL 0)
39+
if(diff EQUAL 1)
3240
message(FATAL_ERROR "report differs from expected")
41+
elseif(NOT diff EQUAL 0)
42+
message(FATAL_ERROR "compare_files failed (rc=${diff})")
3343
endif()
3444

3545
if(DUMP)
36-
if(NOT EXISTS ${SRC}/${DUMP}.tree.txt)
46+
if(NOT EXISTS "${SRC}/${DUMP}.tree.txt")
3747
message(FATAL_ERROR "expected dump file ${DUMP}.tree.txt not found")
3848
endif()
3949
endif()

0 commit comments

Comments
 (0)