Files
libgit2/tests
Sean Allred ea66ab0773 config: skip worktree config in get_backend_for_use
It would seem that `get_backend_for_use` is primarily used when
writing config data -- either to set keys or delete them (based on the
possible values of `backend_use`). When git-config(1) is used for
side-effects, it will modify only the local (repository-level)
configuration unless explicitly overridden.

From git-config(1):

    --local
        For writing options: write to the repository .git/config file.
	This is the default behavior.

`get_backend_for_use` does not have the ability to specify a config
level and typically is expected (it seems) to 'do the right thing'.
Taking its cue from git-config(1), don't update worktree-specific
config unless it's the only option.

If that functionality is needed by consumers, I assume they would find
the appropriate backend with `git_config_open_level` and feed that
`git_config` object through to the `git_config_set_*` functions (as
demonstrated in the provided test).
2024-02-21 15:54:00 -06:00
..
2022-02-27 23:44:19 -05:00

libgit2 tests

These are the unit and integration tests for the libgit2 projects.

  • benchmarks These are benchmark tests that excercise the CLI.
  • clar
    This is clar the common test framework.
  • headertest
    This is a simple project that ensures that our public headers are compatible with extremely strict compilation options.
  • libgit2
    These tests exercise the core git functionality in libgit2 itself.
  • resources
    These are the resources for the tests, including files and git repositories.
  • util
    These are tests of the common utility library.

Writing tests for libgit2

libgit2 uses the clar test framework, a C testing framework.

The best resources for learning clar are clar itself and the existing tests within libgit2. In general:

  • 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:

    void test_merge_analysis__uptodate(void)
    {
      ...
    }
    
  • 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:

    libgit2_tests -smerge::analysis::uptodate
    

Memory leak checking

These are automatically run as part of CI, but if you want to check locally:

Linux

Uses valgrind:

$ cmake -DBUILD_TESTS=ON -DVALGRIND=ON ..
$ cmake --build .
$ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppressions=../libgit2_tests.supp \
  ./libgit2_tests

macOS

Uses leaks, which requires XCode installed:

$ MallocStackLogging=1 MallocScribble=1 MallocLogFile=/dev/null CLAR_AT_EXIT="leaks -quiet \$PPID" \
  ./libgit2_tests

Windows

Build with the WIN32_LEAKCHECK option:

$ cmake -DBUILD_TESTS=ON -DWIN32_LEAKCHECK=ON ..
$ cmake --build .
$ ./libgit2_tests