<commit_before>
if (Qt5Core_FOUND)
    find_package(Qt5Test)
endif()

set(testdir ${CMAKE_BINARY_DIR}/TestDir)
file(MAKE_DIRECTORY ${testdir})
add_definitions(-DTEST_DIR=${testdir})
remove_definitions(-DMAKE_LIBQGIT2_LIB)

set(existing_repository ${testdir}/existing_repository)
add_definitions(-DTEST_EXISTING_REPOSITORY=${existing_repository})
if(NOT EXISTS ${existing_repository})
    message(STATUS "Creating test repository ...")
    file(MAKE_DIRECTORY ${existing_repository})
    file(MAKE_DIRECTORY ${existing_repository}/.git)
    file(GLOB_RECURSE gitfiles RELATIVE ${CMAKE_SOURCE_DIR}/.git ${CMAKE_SOURCE_DIR}/.git/*)
    foreach(gitfile ${gitfiles})
        configure_file(${CMAKE_SOURCE_DIR}/.git/${gitfile} ${existing_repository}/.git/${gitfile} COPYONLY)
    endforeach()
endif()
message(STATUS "Using test repository at '${existing_repository}'")

include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(EXECUTABLE_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/bin)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libqgit2_id_rsa ${EXECUTABLE_OUTPUT_PATH}/libqgit2_id_rsa COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libqgit2_id_rsa.pub ${EXECUTABLE_OUTPUT_PATH}/libqgit2_id_rsa.pub COPYONLY)

macro(addTest name)
    set(_source ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp ${CMAKE_CURRENT_SOURCE_DIR}/TestHelpers.h)
    set(_moced ${CMAKE_CURRENT_BINARY_DIR}/${name}.moc)
    set_source_files_properties(${_source} PROPERTIES OBJECT_DEPENDS "${_moced}")
    set(testname test${name})
    add_executable(${testname} ${_source})
    target_link_libraries(test${name} qgit2 git2 ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY})
    add_test(NAME ${testname} COMMAND ${testname})
    if(Qt5Core_FOUND)
        qt5_use_modules(test${name} Test)
    else()
        qt4_generate_moc(${_source} ${_moced})
    endif()
endmacro()


addTest(Init)
addTest(Revision)
addTest(StatusOptions)
addTest(Clone)
addTest(Fetch)
addTest(Checkout)
addTest(Push)<commit_msg>Fix tests: qt4_generate_moc only has one input file<commit_after>
if (Qt5Core_FOUND)
    find_package(Qt5Test)
endif()

set(testdir ${CMAKE_BINARY_DIR}/TestDir)
file(MAKE_DIRECTORY ${testdir})
add_definitions(-DTEST_DIR=${testdir})
remove_definitions(-DMAKE_LIBQGIT2_LIB)

set(existing_repository ${testdir}/existing_repository)
add_definitions(-DTEST_EXISTING_REPOSITORY=${existing_repository})
if(NOT EXISTS ${existing_repository})
    message(STATUS "Creating test repository ...")
    file(MAKE_DIRECTORY ${existing_repository})
    file(MAKE_DIRECTORY ${existing_repository}/.git)
    file(GLOB_RECURSE gitfiles RELATIVE ${CMAKE_SOURCE_DIR}/.git ${CMAKE_SOURCE_DIR}/.git/*)
    foreach(gitfile ${gitfiles})
        configure_file(${CMAKE_SOURCE_DIR}/.git/${gitfile} ${existing_repository}/.git/${gitfile} COPYONLY)
    endforeach()
endif()
message(STATUS "Using test repository at '${existing_repository}'")

include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(EXECUTABLE_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/bin)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libqgit2_id_rsa ${EXECUTABLE_OUTPUT_PATH}/libqgit2_id_rsa COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libqgit2_id_rsa.pub ${EXECUTABLE_OUTPUT_PATH}/libqgit2_id_rsa.pub COPYONLY)

set(helper ${CMAKE_CURRENT_SOURCE_DIR}/TestHelpers.h)
if(NOT Qt5Core_FOUND)
    qt4_generate_moc(${helper} helper_moced)
endif()

macro(addTest name)
    set(_source ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp)
    set(_moced ${CMAKE_CURRENT_BINARY_DIR}/${name}.moc)
    set_source_files_properties(${_source} PROPERTIES OBJECT_DEPENDS "${_moced}")
    set(testname test${name})
    add_executable(${testname} ${_source}  ${helper} ${helper_moced})
    target_link_libraries(test${name} qgit2 git2 ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY})
    add_test(NAME ${testname} COMMAND ${testname})
    if(Qt5Core_FOUND)
        qt5_use_modules(test${name} Test)
    else()
        qt4_generate_moc(${_source} ${_moced})
    endif()
endmacro()


addTest(Init)
addTest(Revision)
addTest(StatusOptions)
addTest(Clone)
addTest(Fetch)
addTest(Checkout)
addTest(Push)
{'fraction_non_alphanumeric': 0.1309612058314801, 'fraction_numerical': 0.006671608598962194, 'mean_word_length': 7.540084388185654, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '728824', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1472, 'n_words': 196}