forked from thiagofrosty/cpp-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
30 lines (21 loc) · 951 Bytes
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
cmake_minimum_required(VERSION 2.6)
project(cpp-test)
add_compile_options(-std=c++14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
function(add_challenge _CHALLENGE_NAME)
add_executable(${_CHALLENGE_NAME} ${_CHALLENGE_NAME}.cpp)
set(_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
file(GLOB_RECURSE _INPUT_FILES ${_WORKING_DIRECTORY}/ input*.txt)
foreach(_INPUT_FILE ${_INPUT_FILES})
set(_FILE_COUNT "")
string(REGEX MATCH "([0-9]+)\\.txt$" _FILE_COUNT ${_INPUT_FILE})
string(REGEX MATCH "[0-9]+" _FILE_COUNT ${_FILE_COUNT})
set(_TEST_COMMAND "diff -w -Z <(cat ${_WORKING_DIRECTORY}/input${_FILE_COUNT}.txt | $<TARGET_FILE:${_CHALLENGE_NAME}>) <(cat output${_FILE_COUNT}.txt)")
add_test(NAME ${_CHALLENGE_NAME}_test_${_FILE_COUNT}
COMMAND /bin/bash -c ${_TEST_COMMAND}
WORKING_DIRECTORY ${_WORKING_DIRECTORY})
endforeach()
endfunction()
enable_testing()
include(CTest)
add_subdirectory(challenges)