Skip to content

Commit

Permalink
Isolate per-tool inputs and expected outputs
Browse files Browse the repository at this point in the history
Moving towards a more generic framework for testing all tools.
  • Loading branch information
LegalizeAdulthood committed Jan 21, 2024
1 parent 948df37 commit 9df6d51
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 17 deletions.
33 changes: 20 additions & 13 deletions Tools/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
set(INPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Inputs)
set(EXPECTED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Expected)
add_test(NAME test-add-tests-tool
COMMAND ${CMAKE_COMMAND}
-DCMAKE_COMMAND:STRING=${CMAKE_COMMAND}
-DTEST_NAME:STRING=add-tests
-DTEST_DIR:STRING=${CMAKE_BINARY_DIR}/ToolTests
-DINPUT_DIR:STRING=${INPUT_DIR}
-DEXPECTED_DIR:STRING=${EXPECTED_DIR}
-DTOOL=$<TARGET_FILE:add-tests>
-P ${CMAKE_CURRENT_SOURCE_DIR}/TestAddTests.cmake
)
set_tests_properties(test-add-tests-tool PROPERTIES LABELS add-tests)
function(add_tool_test tool)
set(INPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${tool}/Inputs)
set(EXPECTED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${tool}/Expected)

add_test(NAME test-${tool}-tool
COMMAND ${CMAKE_COMMAND}
-DCMAKE_COMMAND:STRING=${CMAKE_COMMAND}
-DTEST_NAME:STRING=${tool}
-DTEST_DIR:PATH=${CMAKE_BINARY_DIR}/ToolTests/${tool}
-DINPUT_DIR:PATH=${INPUT_DIR}
-DEXPECTED_DIR:PATH=${EXPECTED_DIR}
-DTOOL_NAME:STRING=${tool}
-DTOOL_COMMAND:PATH=$<TARGET_FILE:${tool}>
-P ${CMAKE_CURRENT_SOURCE_DIR}/TestTool.cmake
)
set_property(TEST test-${tool}-tool PROPERTY LABELS ${tool} tool)
endfunction()

add_tool_test(add-tests)
#add_tool_test(renumber-tests)
39 changes: 35 additions & 4 deletions Tools/Tests/TestAddTests.cmake → Tools/Tests/TestTool.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
set(TEST_DIR "${TEST_DIR}/${TEST_NAME}")
set(DEBUG OFF)
if(DEBUG)
function(dump_var var)
message(STATUS "${var}=${${var}}")
endfunction()
foreach(var
CMAKE_COMMAND
TEST_NAME
TEST_DIR
INPUT_DIR
EXPECTED_DIR
TOOL_NAME
TOOL_COMMAND
)
dump_var(${var})
endforeach()
endif()

function(copy_input_subdir subdir)
if(DEBUG)
message(STATUS "copy_input_subdir ${subdir} COPY ${INPUT_DIR}/${subdir} DESTINATION ${TEST_DIR})")
endif()
if(EXISTS ${INPUT_DIR}/${subdir})
file(COPY ${INPUT_DIR}/${subdir} DESTINATION ${TEST_DIR})
endif()
endfunction()

# Delete any existing files in TEST_DIR
file(REMOVE_RECURSE ${TEST_DIR})

# copy INPUT_DIR contents to TEST_DIR
file(COPY ${INPUT_DIR}/Sources DESTINATION ${TEST_DIR})
file(COPY ${INPUT_DIR}/Results DESTINATION ${TEST_DIR})
copy_input_subdir(Sources)
copy_input_subdir(Results)

# run tool
if(DEBUG)
message(STATUS "execute_process COMMAND ${TOOL_COMMAND} ${TEST_DIR}/Sources R ${TEST_DIR}/Sources/TestRename.cpp ${TEST_DIR}/Results")
endif()
execute_process(
COMMAND ${TOOL} ${TEST_DIR}/Sources R ${TEST_DIR}/Sources/TestRename.cpp ${TEST_DIR}/Results
COMMAND ${TOOL_COMMAND} ${TEST_DIR}/Sources R ${TEST_DIR}/Sources/TestRename.cpp ${TEST_DIR}/Results
)

# compare TEST_DIR contents to EXPECTED_DIR
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9df6d51

Please sign in to comment.