3 These are the unit and integration tests for the libgit2 projects.
6 These are benchmark tests that excercise the CLI.
8 This is [clar](https://github.com/clar-test/clar) the common test framework.
10 This is a simple project that ensures that our public headers are
11 compatible with extremely strict compilation options.
13 These tests exercise the core git functionality in libgit2 itself.
15 These are the resources for the tests, including files and git
18 These are tests of the common utility library.
20 ## Writing tests for libgit2
22 libgit2 uses the [clar test framework](http://github.com/clar-test/clar), a
25 The best resources for learning clar are [clar itself](https://github.com/clar-test/clar)
26 and the existing tests within libgit2. In general:
28 * If you place a `.c` file into a test directory, it is eligible to contain
30 * The function name for your test is important; test function names begin
31 with `test_`, followed by the folder path (underscore separated), two
32 underscores as a delimiter, then the test name. For example, a file
33 `merge/analysis.c` may contain a test `uptodate`:
36 void test_merge_analysis__uptodate(void)
42 * You can run an individual test by passing `-s` to the test runner. Tests
43 are referred to by their function names; for example, the function
44 `test_merge_analysis__uptodate` is referred to as `merge::analysis::uptodate`.
45 To run only that function you can use the `-s` option on the test runner:
48 libgit2_tests -smerge::analysis::uptodate
51 ## Memory leak checking
53 These are automatically run as part of CI, but if you want to check locally:
57 Uses [`valgrind`](http://www.valgrind.org/):
60 $ cmake -DBUILD_TESTS=ON -DVALGRIND=ON ..
62 $ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppressions=../libgit2_tests.supp \
68 Uses [`leaks`](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html), which requires XCode installed:
71 $ MallocStackLogging=1 MallocScribble=1 MallocLogFile=/dev/null CLAR_AT_EXIT="leaks -quiet \$PPID" \
77 Build with the `WIN32_LEAKCHECK` option:
80 $ cmake -DBUILD_TESTS=ON -DWIN32_LEAKCHECK=ON ..