bake
bake copied to clipboard
How do you build & run unit tests?
In cmake, you'd use this kind of monstrosity:
# Download and unpack googletest at configure time
configure_file(${CMAKE_SOURCE_DIR}/cmake/GoogleTest-CMakeLists.txt.in ${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL)
# Now simply link against gtest or gtest_main as needed. Eg
add_executable(mylib_test
src/main.cpp
...
)
Before bake was forked, it was integrated with the corto test framework, and I'm currently porting the ability to run tests over to the new bake version. The way this worked (and will work) was:
Bake had a command foreach
, that automatically discovered all projects in a tree, and ran a specified command for them. For example:
bake foreach pwd
would print the directories of all discovered bake projects.
The corto test framework did something like this (simplified for brevity):
bake foreach "corto test"
which would execute a test suite if there was one. Porting the foreach
feature is high on my list of TODOs, as it is currently something that I need for my own projects as well.