46 Commits

Author SHA1 Message Date
Edward Thomson
e6d93612e8 refactor: move utility tests into util 2022-02-22 22:07:45 -05:00
Edward Thomson
2b09b5d7a0 refactor: move headertest into separate test folder 2022-02-22 22:07:45 -05:00
Edward Thomson
3344fddc97 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.
2022-02-22 22:07:45 -05:00
Edward Thomson
5fcfada500 cmake: document CMakeLists.txt hierarchy 2022-02-22 22:07:44 -05:00
Dimitris Apostolou
90df43022a Fix typos 2022-01-05 16:35:52 +02:00
Josh Junon
c5cd71b203 cmake: use PROJECT_SOURCE_DIR of CMAKE_SOURCE_DIR
Also applies to *_BINARY_DIR.

This effectively reverts 84083dcc8b,
which broke all users of libgit2 that use it as a CMake subdirectory
(via `add_subdirectory()`). This is because CMAKE_SOURCE_DIR refers
to the root-most CMake directory, which in the case of
`add_subdirectory()` is a parent project to libgit2 and thus the paths
don't make any sense to the configuration files. Corollary,
CMAKE_SOURCE_DIR only makes sense if the CMake project is always the
root project - which can rarely be guaranteed.

In all honesty, CMake should deprecate and eventually remove
CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR. It's been the source of headaches
and confusion for years, they're rarely useful over
CMAKE_CURRENT_(SOURCE|BINARY)_DIR or PROJECT_(SOURCE|BINARY)_DIR,
and they cause a lot of confusing configuration and source
code layouts to boot.

Any time they are used, they break `add_subdirectory()` almost 100% of
the time, cause confusing error messages, and hide subtle bugs.
2021-12-23 18:23:34 +01:00
Edward Thomson
84083dcc8b cmake: use CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR
Instead of using the project-specific `libgit2_SOURCE_DIR` and
`libgit2_BINARY_DIR` variables, use `CMAKE_SOURCE_DIR` and
`CMAKE_BINARY_DIR`.
2021-11-22 09:27:59 -05:00
Edward Thomson
4a54d8e39e cmake: enable testing at the top level
Ensure that we `enable_testing()` at the top-level CMakeLists.txt or
else we'll need to navigate within the build directory to the correct
place in the hierarchy to run `ctest`.  Now we can `ctest` at the
top-level again.
2021-11-17 07:27:39 -05:00
Edward Thomson
86685f8f1d cmake: better explain why headertests exists 2021-11-16 17:10:08 -05:00
Peter Pettersson
5221e18548 Add target for testing libgit2 headers 2021-11-15 16:45:14 +01:00
Edward Thomson
395b3dc403 cmake: refactor global variables
Update the global variables `LIBGIT2_OBJECTS` to
`LIBGIT2_DEPENDENCY_OBJECTS` for clarity and consistency.
2021-11-14 07:25:41 -05:00
Edward Thomson
49f03c0305 tests: include test declarations for old gcc
Older versions of gcc do not believe that we've adequately declared our
test functions.  Include `clar_suite.h` conditionally for those old
versions.  Do not do this on newer compilers to avoid unnecessary
recompilation of the entire suite when we add or remove a test function.
2021-11-11 17:11:24 -05:00
Edward Thomson
d3a7a352d5 cmake: move test enablement into test cmake 2021-11-11 15:56:10 -05:00
Edward Thomson
52693ab44e cmake: stylistic refactoring
Ensure that we always use lowercase function names, and that we do not
have spaces preceding open parentheses, for consistency.
2021-10-18 08:30:14 -04:00
Edward Thomson
4e14d4c6a6 cmake: BUILD_CLAR is now BUILD_TESTS
Nobody knows what CLAR is.  The test building option should be
`BUILD_TESTS`.
2021-10-17 13:05:32 -04:00
Edward Thomson
0e04726866 opts: test GIT_OPT_SET_SSL_CERT_LOCATIONS
Include a self-signed certificate for test.libgit2.org:1443 that we can
use to verify that GIT_OPT_SET_SSL_CERT_LOCATIONS works.
2021-08-29 21:52:30 -04:00
lhchavez
b7dce05cb5 Make FIND_PACKAGE(PythonInterp) prefer python3
This change makes it possible to prefer a python (version 3) interpreter
on systems where python2 and python3 coexist (where python2 is found as
`/usr/bin/python`).
2021-07-14 05:29:27 -07:00
Edward Thomson
5368be3053 clar: support long paths on Windows 2021-05-05 23:11:52 +01:00
Edward Thomson
7fd9b3f597 ci: add NTLM tests
Download poxygit, a debugging git server, and clone from it using NTLM,
both IIS-style (with connection affinity) and Apache-style ("broken",
requiring constant reauthentication).
2020-01-24 10:39:56 -06:00
Edward Thomson
e5fb5fe5ad ci: perform SPNEGO tests
Attempt to obtain a Kerberos ticket from LIBGIT2.ORG and then clone the
Negotiate-protected site at test.libgit2.org with that ticket.
2020-01-24 09:54:28 -06:00
Patrick Steinhardt
ebabb88f24 cmake: update minimum CMake version to v3.5.1
Back in commit cf9f34521 (cmake: bump minimum version to 2.8.11,
2017-09-06), we have bumped the minimum CMake version to require at
least v2.8.11. The main hold-backs back then were distributions like
RHEL/CentOS as well as Ubuntu Trusty, which caused us to not target a
more modern version. Nowadays, Ubuntu Trusty has been EOL'd and CentOS 6
has CMake v3.6.1 available via the EPEL6 repository, and thus it seems
fair to upgrade to a more recent version.

Going through repology [1], one can see that all supported mainstream
distributions do in fact have CMake 3 available. Going through the list,
the minimum version that is supported by all mainstream distros is in
fact v3.5.1:

	- CentOS 6 via EPEL6: 3.6.1
	- Debian Oldstable: 3.7.2
	- Fedora 26: 3.8.2
	- OpenMandriva 3.x: 3.5.1
	- Slackware 14.2: 3.5.2
	- Ubuntu 16.04: 3.5.1

Consequentally, let's upgrade CMake to the minimum version of 3.5.1 and
remove all the version CMake checks that aren't required anymore.

[1]: https://repology.org/project/cmake/versions
2019-10-10 09:42:07 +02:00
Ian Hattendorf
42ea2f958a clone: whitespace in url ssh test 2019-07-25 13:15:20 -07:00
Patrick Steinhardt
d827b11b67 tests: execute leak checker via CTest directly
Right now, we have an awful hack in our test CI setup that extracts the
test command from CTest's output and then prepends the leak checker.
This is dependent on non-machine-parseable output from CMake and also
breaks on various ocassions, like for example when we have spaces in the
current path or when the path contains backslashes. Both conditions may
easily be triggered on Win32 systems, and in fact they do break our
Azure Pipelines builds.

Remove the awful hack in favour of a new CMake build option
"USE_LEAK_CHECKER". If specifying e.g. "-DUSE_LEAK_CHECKER=valgrind",
then we will set up all tests to be run under valgrind. Like this, we
can again simply execute ctest without needing to rely on evil sourcery.
2019-07-20 19:10:10 +02:00
Edward Thomson
7912db49d3 ci: enable all proxy tests 2019-06-10 19:58:22 +01:00
Edward Thomson
24ac9e0c97 deprecation: ensure we GIT_EXTERN deprecated funcs
Although the error functions were deprecated, we did not properly mark
them as deprecated.  We need to include the `deprecated.h` file in order
to ensure that the functions get their export attributes.

Similarly, do not define `GIT_DEPRECATE_HARD` within the library, or
those functions will also not get their export attributes.  Define that
only on the tests and examples.
2019-02-14 11:57:05 +00:00
Edward Thomson
423d3e738a ci: precisely identify the invasive tests 2019-01-19 00:08:05 +00:00
Etienne Samson
1b4ba8443f ci: enable some of the invasive testcases 2019-01-11 11:53:54 +01:00
Edward Thomson
943181c2ef Revert "clar: introduce CLAR_XML option"
This reverts commit a2d73f5643.
Using clar to propagate the XML settings was a mistake.
2018-09-10 15:03:23 +01:00
Edward Thomson
a2d73f5643 clar: introduce CLAR_XML option
Introduce a CLAR_XML option, to run the `ctest` commands with the new
`-r` flag to clar.  Permitted values are `OFF`, `ON` and a directory to
write the XML test results to.
2018-09-06 11:18:58 +01:00
Edward Thomson
ce798b256b tests: simplify cmake test configuration
Simplify the names for the tests, removing the unnecessary
"libgit2-clar" prefix.  Make "all" the new default test run, and include
the online tests by default (since HTTPS should always be enabled).

For the CI tests, create an offline-only test, then the various online
tests.
2018-07-26 14:07:00 +01:00
Patrick Steinhardt
e1a4a8ebfc cmake: enforce C90 standard
While the aim of libgit2 was to conform to C90 code, we never instructed
the compiler to enforce C90 compliance. Thus, quite a few violations
were able to get into our code base, which have been removed with the
previous commits. As we are now able to build libgit2 with C90 enforced,
we can set the C_STANDARD property for our own build targets.

Note that we explicitly avoid setting the C standard for our third-party
dependencies. At least the zlib target does not build with C90 enforced,
and we do not want to fix them by deviating from upstream. Thus we
simply enforce no standard for them.
2018-07-13 08:25:12 +02:00
Patrick Steinhardt
c13e56f91c cmake: distinguish internal and system include directories
While we want to enforce strict C90 mode, this may cause issues with
system provided header files which are themselves not strictly
conforming. E.g. if a system header has C++ style comments, a compiler
in strict C90 mode would produce an error and abort the build. As the
user most likely doesn't want to change the system header, this would
completely break the build on such systems. One example of this is
mbedtls, which provides such header files.

The problem can be worked around by distinguishing between
system-provided and project-provided include directories. When adding
include directories via "-isystem" instead of "-I", the compiler will
skip certain checks and print out less warnings. To use system includes,
we can simply add the "SYSTEM" flag to CMake's `INCLUDE_DIRECTORIES` and
`TARGET_INCLUDE_DIRECTORIES` functions. Note that we have to split the
include directories into two variables because of this, as we definitely
still want to check for all warnings produced by our own header files.
2018-07-13 08:25:12 +02:00
Patrick Steinhardt
8ab470f513 cmake: remove now-useless LIBGIT2_LIBDIRS handling
With the recent change of always resolving pkg-config libraries to their
full path, we do not have to manage the LIBGIT2_LIBDIRS variable
anymore. The only other remaining user of LIBGIT2_LIBDIRS is winhttp,
which is a CMake-style library target and can thus be resolved by CMake
automatically.

Remove the variable to simplify our build system a bit.
2018-05-09 13:50:42 +02:00
Andreas Baumann
fac7eac451 fixed stack smashing due to wrong size of struct stat on the stack
on 32-bit systems with 64-bit file descriptor offsets enabled
(added -D_FILE_OFFSET_BITS=64 when compiling the test suite)
2018-04-19 15:21:52 +02:00
Patrick Steinhardt
5874e151d7 tests: create new test target for all SSH-based tests
Some tests shall be run against our own SSH server we spin up in Travis.
As those need to be run separate from our previous tests which run
against git-daemon, we have to do this in a separate step. Instead of
bundling all that knowledge in the CI script, move it into the test
build instructions by creating a new test target.
2018-01-03 11:50:39 +00:00
Patrick Steinhardt
54a1bf057a tests: online::clone: inline creds-test with nonexistent URL
Right now, we test our credential callback code twice, once via SSH on
localhost and once via a non-existent GitHub repository. While the first
URL makes sense to be configurable, it does not make sense to hard-code
the non-existing repository, which requires us to call tests multiple
times. Instead, we can just inline the URL into another set of tests.
2018-01-03 11:50:39 +00:00
Patrick Steinhardt
fea6092079 tests: online::clone: construct credential-URL from environment
We support two types of passing credentials to the proxy, either via the
URL or explicitly by specifying user and password. We test these types
by modifying the proxy URL and executing the tests twice, which is
in fact unnecessary and requires us to maintain the list of environment
variables and test executions across multiple CI infrastructures.

To fix the situation, we can just always pass the host, port, user and
password to the tests. The tests can then assemble the complete URL
either with or without included credentials, allowing us to test both
cases in-process.
2018-01-03 11:50:39 +00:00
Patrick Steinhardt
543ec149b8 tests: perf: build but exclude performance tests by default
Our performance tests (or to be more concrete, our single performance
test) are not built by default, as they are always #ifdef'd out. While
it is true that we don't want to run performance tests by default, not
compiling them at all may cause code rot and is thus an unfavorable
approach to handle this.

We can easily improve this situation: this commit removes the #ifdef,
causing the code to always be compiled. Furthermore, we add `-xperf` to
the default command line parameters of `generate.py`, thus causing the
tests to be excluded by default.

Due to this approach, we are now able to execute the performance tests
by passing `-sperf` to `libgit2_clar`. Unfortunately, we cannot execute
the performance tests on Travis or AppVeyor as they rely on history
being available for the libgit2 repository. As both do a shallow clone
only, though, this is not given.
2018-01-03 11:50:39 +00:00
Etienne Samson
9980be03c2 cmake: Add USE_HTTPS as a CMake option
It defaults to ON, e.g. "pick whatever default is appropriate for the platform".
It accepts one of SecureTransport, OpenSSL, WinHTTP, or OFF.
It errors if the backend library couldn't be found.
2017-10-23 20:04:21 +02:00
Etienne Samson
08c1b8fceb cmake: simplify some HTTPS tests 2017-10-23 20:02:35 +02:00
Patrick Steinhardt
4da74c83e4 cmake: use project-relative binary and source directories
Due to our split of CMake files into multiple modules, we had to replace
some uses of the `${CMAKE_CURRENT_SOURCE_DIR}` and
`${CMAKE_CURRENT_BINARY_DIR}` variables and replace them with
`${CMAKE_SOURCE_DIR}` and `${CMAKE_BINARY_DIR}`. This enabled us to
still be able to refer to top-level files when defining build
instructions inside of a subdirectory.

When replacing all variables, it was assumed that the absolute set of
variables is always relative to the current project. But in fact, this
is not the case, as these variables always point to the source and
binary directory as given by the top-levl project. So the change
actually broke the ability to include libgit2 directly as a subproject,
as source files cannot be found anymore.

Fix this by instead using project-specific source and binary directories
with `${libgit2_SOURCE_DIR}` and `${libgit2_BINARY_DIR}`.
2017-10-20 07:38:34 +02:00
Patrick Steinhardt
d8d2f21e24 cmake: unify version check for target include directories
There are two locations where we check whether CMake supports
`TARGET_INCLUDE_DIRECTORIES`. While the first one uses `VERSION_LESS
2.8.12`, the second one uses `VERSION_GREATER 2.8.11`, which are
obviously equivalent to each other. It'd still be easier to grep for
specific CMake versions being required for some features if both used
the same conditional mentioning the actual target version required. So
this commit refactors these conditions to make them equal.
2017-09-20 15:26:26 +02:00
Patrick Steinhardt
1d9dd882b3 cmake: distinguish libgit2 objects and sources
Distinguish variables keeping track of our internal libgit2 sources and
the final objects which shall be linked into the library. This will ease
the transition to use object libraries for our bundled dependencies
instead of linking them in.
2017-09-20 15:26:26 +02:00
Patrick Steinhardt
8e31cc2580 cmake: keep track of libraries and includes via lists
Later on, we will move detection of required libraries, library
directories as well as include directories into a separate
CMakeLists.txt file inside of the source directory. Obviously, we want
to avoid duplication here regarding these parameters.

To prepare for the split, put the parameters into three variables
LIBGIT2_LIBS, LIBGIT2_LIBDIRS and LIBGIT2_INCLUDES, tracking the
required libraries, linking directory as well as include directories.
These variables can later be exported into the parent scope from inside
of the source build instructions, making them readily available for the
other subdirectories.
2017-08-16 07:12:38 +02:00
Patrick Steinhardt
a390a8464e cmake: move defines into "features.h" header
In a future commit, we will split out the build instructions for our
library directory and move them into a subdirectory. One of the benefits
is fixing scoping issues, where e.g. defines do not leak to build
targets where they do not belong to. But unfortunately, this does also
pose the problem of how to propagate some defines which are required by
both the library and the test suite.

One way would be to create another variable keeping track of all added
defines and declare it inside of the parent scope. While this is the
most obvious and simplest way of going ahead, it is kind of unfortunate.
The main reason to not use this is that these defines become implicit
dependencies between the build targets. By simply observing a define
inside of the CMakeLists.txt file, one cannot reason whether this define
is only required by the current target or whether it is required by
different targets, as well.

Another approach would be to use an internal header file keeping track
of all defines shared between targets. While configuring the library, we
will set various variables and let CMake configure the file, adding or
removing defines based on what has been configured. Like this, one can
easily keep track of the current environment by simply inspecting the
header file. Furthermore, these dependencies are becoming clear inside
the CMakeLists.txt, as instead of simply adding a define, we now call
e.g. `SET(GIT_THREADSAFE 1)`.

Having this header file though requires us to make sure it is always
included before any "#ifdef"-preprocessor checks are executed. As we
have already refactored code to always include the "common.h" header
file before any statement inside of a file, this becomes easy: just make
sure "common.h" includes the new "features.h" header file first.
2017-08-16 07:12:38 +02:00
Patrick Steinhardt
35087f0eef cmake: create separate CMakeLists.txt for tests
Our CMakeLists.txt is very unwieldy in its current size, spanning more
than 700 lines of code. Furthermore, it has several issues regarding
scoping, where for example some defines, includes, etc. from our test
suite are also applied to our normal library code.

To fix this, we can separate out build instructions for our tests and
move them into their own CMakeLists.txt in the "tests" directory. This
reduced complexity of the root CMakeLists.txt file and fixes the issues
regarding leaking build context from tests into the library.
2017-08-16 07:12:38 +02:00