Commit 3344fddc by Edward Thomson

refactor: `tests` is now `tests/libgit2`

Like we want to separate libgit2 and utility source code, we want to
separate libgit2 and utility tests.  Start by moving all the tests into
libgit2.
parent 91ba0896
......@@ -144,8 +144,8 @@ add_feature_info(threadsafe USE_THREADS "threadsafe support")
# ntlmclient
if(USE_NTLMCLIENT)
set(GIT_NTLM 1)
add_subdirectory("${libgit2_SOURCE_DIR}/deps/ntlmclient" "${libgit2_BINARY_DIR}/deps/ntlmclient")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/ntlmclient")
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/ntlmclient" "${PROJECT_BINARY_DIR}/deps/ntlmclient")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/ntlmclient")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:ntlmclient>")
endif()
add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
......
# tests: the unit and integration tests for libgit2
# The main libgit2 tests tree: this CMakeLists.txt includes the
# subprojects that make up core libgit2 support.
set(Python_ADDITIONAL_VERSIONS 3 2.7)
find_package(PythonInterp)
if(NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Could not find a python interpreter, which is needed to build the tests. "
"Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests")
ENDIF()
set(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/resources/")
set(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\")
add_definitions(-DCLAR_WIN32_LONGPATHS)
add_definitions(-D_FILE_OFFSET_BITS=64)
# Ensure that we do not use deprecated functions internally
add_definitions(-DGIT_DEPRECATE_HARD)
set(TEST_INCLUDES "${CLAR_PATH}" "${CMAKE_CURRENT_BINARY_DIR}")
file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
set(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c")
if(MSVC_IDE)
list(APPEND SRC_CLAR "precompiled.c")
endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h
COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf .
DEPENDS ${SRC_TEST}
WORKING_DIRECTORY ${CLAR_PATH}
)
set_source_files_properties(
${CLAR_PATH}/clar.c
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90)
set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS})
ide_split_sources(libgit2_tests)
#
# Old versions of gcc require us to declare our test functions; don't do
# this on newer compilers to avoid unnecessary recompilation.
#
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h")
endif()
if(MSVC_IDE)
# Precompiled headers
set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
set_source_files_properties("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
endif()
function(ADD_CLAR_TEST name)
if(NOT USE_LEAK_CHECKER STREQUAL "OFF")
add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
else()
add_test(${name} "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
endif()
endfunction(ADD_CLAR_TEST)
add_clar_test(offline -v -xonline)
add_clar_test(invasive -v -score::ftruncate -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root)
add_clar_test(online -v -sonline -xonline::customcert)
add_clar_test(online_customcert -v -sonline::customcert)
add_clar_test(gitdaemon -v -sonline::push)
add_clar_test(ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh)
add_clar_test(proxy -v -sonline::clone::proxy)
add_clar_test(auth_clone -v -sonline::clone::cred)
add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push)
#
# Header file validation project: ensure that we do not publish any sloppy
# definitions in our headers and that a consumer can include <git2.dll>
# even when they have aggressive C90 warnings enabled.
#
add_executable(headertest headertest.c)
set_target_properties(headertest PROPERTIES C_STANDARD 90)
set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF)
target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES})
if (MSVC)
target_compile_options(headertest PUBLIC /W4 /WX)
else()
target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror)
endif()
add_subdirectory(libgit2)
Writing Clar tests for libgit2
==============================
# libgit2 tests
For information on the Clar testing framework and a detailed introduction
please visit:
These are the unit and integration tests for the libgit2 projects.
https://github.com/vmg/clar
* `libgit2`
These tests exercise the core git functionality in libgit2 itself.
* `resources`
These are the resources for the tests, including files and git
repositories.
## Writing tests for libgit2
* Write your modules and tests. Use good, meaningful names.
libgit2 uses the [clar test framework](http://github.com/clar-test/clar), a
C testing framework.
* Make sure you actually build the tests by setting:
The best resources for learning clar are [clar itself](https://github.com/clar-test/clar)
and the existing tests within libgit2. In general:
cmake -DBUILD_TESTS=ON build/
* If you place a `.c` file into a test directory, it is eligible to contain
test cases.
* The function name for your test is important; test function names begin
with `test_`, followed by the folder path (underscore separated), two
underscores as a delimiter, then the test name. For example, a file
`merge/analysis.c` may contain a test `uptodate`:
* Test:
```
void test_merge_analysis__uptodate(void)
{
...
}
```
./build/libgit2_tests
* You can run an individual test by passing `-s` to the test runner. Tests
are referred to by their function names; for example, the function
`test_merge_analysis__uptodate` is referred to as `merge::analysis::uptodate`.
To run only that function you can use the `-s` option on the test runner:
* Make sure everything is fine.
```
libgit2_tests -smerge::analysis::uptodate
```
* Send your pull request. That's it.
Memory leak checks
------------------
## Memory leak checking
These are automatically run as part of CI, but if you want to check locally:
#### Linux
### Linux
Uses [`valgrind`](http://www.valgrind.org/):
......@@ -38,7 +54,7 @@ $ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppression
./libgit2_tests
```
#### macOS
### macOS
Uses [`leaks`](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html), which requires XCode installed:
......@@ -46,3 +62,13 @@ Uses [`leaks`](https://developer.apple.com/library/archive/documentation/Perform
$ MallocStackLogging=1 MallocScribble=1 MallocLogFile=/dev/null CLAR_AT_EXIT="leaks -quiet \$PPID" \
./libgit2_tests
```
### Windows
Build with the `WIN32_LEAKCHECK` option:
```console
$ cmake -DBUILD_TESTS=ON -DWIN32_LEAKCHECK=ON ..
$ cmake --build .
$ ./libgit2_tests
```
# tests: the unit and integration tests for libgit2
set(Python_ADDITIONAL_VERSIONS 3 2.7)
find_package(PythonInterp)
if(NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Could not find a python interpreter, which is needed to build the tests. "
"Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests")
ENDIF()
set(CLAR_FIXTURES "${PROJECT_SOURCE_DIR}/tests/resources/")
set(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\")
add_definitions(-DCLAR_WIN32_LONGPATHS)
add_definitions(-D_FILE_OFFSET_BITS=64)
# Ensure that we do not use deprecated functions internally
add_definitions(-DGIT_DEPRECATE_HARD)
set(TEST_INCLUDES "${CLAR_PATH}" "${CMAKE_CURRENT_BINARY_DIR}")
file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
set(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c")
if(MSVC_IDE)
list(APPEND SRC_CLAR "precompiled.c")
endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h
COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf .
DEPENDS ${SRC_TEST}
WORKING_DIRECTORY ${CLAR_PATH}
)
set_source_files_properties(
${CLAR_PATH}/clar.c
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90)
set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS})
ide_split_sources(libgit2_tests)
#
# Old versions of gcc require us to declare our test functions; don't do
# this on newer compilers to avoid unnecessary recompilation.
#
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h")
endif()
if(MSVC_IDE)
# Precompiled headers
set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
set_source_files_properties("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
endif()
function(ADD_CLAR_TEST name)
if(NOT USE_LEAK_CHECKER STREQUAL "OFF")
add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
else()
add_test(${name} "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
endif()
endfunction(ADD_CLAR_TEST)
add_clar_test(offline -v -xonline)
add_clar_test(invasive -v -score::ftruncate -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root)
add_clar_test(online -v -sonline -xonline::customcert)
add_clar_test(online_customcert -v -sonline::customcert)
add_clar_test(gitdaemon -v -sonline::push)
add_clar_test(ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh)
add_clar_test(proxy -v -sonline::clone::proxy)
add_clar_test(auth_clone -v -sonline::clone::cred)
add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push)
#
# Header file validation project: ensure that we do not publish any sloppy
# definitions in our headers and that a consumer can include <git2.dll>
# even when they have aggressive C90 warnings enabled.
#
add_executable(headertest headertest.c)
set_target_properties(headertest PROPERTIES C_STANDARD 90)
set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF)
target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES})
if (MSVC)
target_compile_options(headertest PUBLIC /W4 /WX)
else()
target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror)
endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment