<commit_before># Compile and link with coverage
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")

link_libraries(${libs})
include_directories(${dirs})
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_LIST_DIR})

# Download and unpack googletest at configure time {{{
configure_file(
  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)

# }}}

function(unit_test file tests)
  set(multi_value_args SOURCES)

  cmake_parse_arguments("BIN" "" "" "${multi_value_args}" ${ARGN})

  # Prefix all sources needed by the tests with ../src/ so that the calls to the
  # unit_test function become cleaner
  SET(sources "")
  FOREACH(f ${BIN_SOURCES})
    LIST(APPEND sources "../src/${f}")
  ENDFOREACH(f)

  string(REPLACE "/" "_" testname ${file})
  set(name "unit_test.${testname}")
  add_executable(${name} unit_tests/${file}.cpp ${sources})

  # Link against googletest
  target_link_libraries(${name} gtest_main)

  add_test(NAME ${name} COMMAND ${name})

  # Add test to list of unit tests
  list(APPEND ${tests} "${name}")
  set(${tests} ${${tests}} PARENT_SCOPE)
endfunction()

unit_test(utils/color unit_tests)
unit_test(utils/math unit_tests)
unit_test(utils/memory unit_tests)
unit_test(utils/string unit_tests
  SOURCES
  utils/string.cpp)
unit_test(utils/file unit_tests
  SOURCES
  utils/command.cpp
  utils/file.cpp
  utils/env.cpp
  utils/process.cpp
  utils/io.cpp
  utils/string.cpp
  utils/concurrency.cpp
  components/logger.cpp)
unit_test(components/command_line unit_tests
  SOURCES
  components/command_line.cpp
  utils/string.cpp)

# Compile all unit tests with 'make all_unit_tests'
add_custom_target("all_unit_tests" DEPENDS ${unit_tests})
<commit_msg>tests: Don't include src dir<commit_after># Compile and link with coverage
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")

link_libraries(${libs})
include_directories(${dirs})
include_directories(${CMAKE_CURRENT_LIST_DIR})

# Download and unpack googletest at configure time {{{
configure_file(
  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)

# }}}

function(unit_test file tests)
  set(multi_value_args SOURCES)

  cmake_parse_arguments("BIN" "" "" "${multi_value_args}" ${ARGN})

  # Prefix all sources needed by the tests with ../src/ so that the calls to the
  # unit_test function become cleaner
  SET(sources "")
  FOREACH(f ${BIN_SOURCES})
    LIST(APPEND sources "../src/${f}")
  ENDFOREACH(f)

  string(REPLACE "/" "_" testname ${file})
  set(name "unit_test.${testname}")
  add_executable(${name} unit_tests/${file}.cpp ${sources})

  # Link against googletest
  target_link_libraries(${name} gtest_main)

  add_test(NAME ${name} COMMAND ${name})

  # Add test to list of unit tests
  list(APPEND ${tests} "${name}")
  set(${tests} ${${tests}} PARENT_SCOPE)
endfunction()

unit_test(utils/color unit_tests)
unit_test(utils/math unit_tests)
unit_test(utils/memory unit_tests)
unit_test(utils/string unit_tests
  SOURCES
  utils/string.cpp)
unit_test(utils/file unit_tests
  SOURCES
  utils/command.cpp
  utils/file.cpp
  utils/env.cpp
  utils/process.cpp
  utils/io.cpp
  utils/string.cpp
  utils/concurrency.cpp
  components/logger.cpp)
unit_test(components/command_line unit_tests
  SOURCES
  components/command_line.cpp
  utils/string.cpp)

# Compile all unit tests with 'make all_unit_tests'
add_custom_target("all_unit_tests" DEPENDS ${unit_tests})

{'fraction_non_alphanumeric': 0.11932042670881075, 'fraction_numerical': 0.0, 'mean_word_length': 5.258343634116192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1509106', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1766, 'n_words': 363}