Make test a custom target again and add top-level test targets

Even though we are using CMake's ctest for testing, we still define our
own `make test` target rather than use its default for many reasons:

 * CMake doesn't run tests in-proc or even add each tests as an
   individual node in the ninja dependency tree, instead it just bundles
   all tests into a target called `test` that always just shells out to
   `ctest`, so there are no build-related benefits to not doing that
   ourselves.
 * CMake devs insist that it is appropriate for `make test` to never
   depend on `make all`, i.e. running `make test` does not require any
   of the binaries to be built before testing.
 * The only way to have a test depend on a binary is to add a fake test
   with a name like "build_fish" that executes CMake recursively to
   build the `fish` target.
 * It is not possible to set top-level CTest options/settings such as
   CTEST_PARALLEL_LEVEL from within the CMake configuration file.
 * Circling back to the point about individual tests not being actual
   Makefile targets, CMake does not offer any way to execute a named
   test via the `make`/`ninja`/whatever interface; the only way to
   manually invoke test `foo` is to to manually run `ctest` and specify
   a regex matching `foo` as an argument, e.g. `ctest -R ^foo$`... which
   is really crazy.

With this patch, it is now possible to execute any single test by name,
by invoking the build directly, e.g. to run the `universal.fish` check:
`cmake --build build --target universal.fish` or
`ninja -C build universal.fish`. Unfortunately, this is not integrated
into the Makefile wrapper, so `make universal.fish` won't work (although
this can potentially be hacked around).
This commit is contained in:
Mahmoud Al-Qudsi
2021-08-08 18:31:50 -05:00
committed by Johannes Altmanninger
parent 26092456d4
commit aaac759d9a
3 changed files with 81 additions and 114 deletions

View File

@@ -21,8 +21,14 @@ die() {
# To keep things sane and to make error messages comprehensible, do not use relative paths anywhere
# in this script. Instead, make all paths relative to one of these or $homedir."
TESTS_ROOT="$(realpath "$(dirname "$0")")"
BUILD_ROOT="$(realpath "${TESTS_ROOT}/..")"
TESTS_ROOT="$(dirname "$0")"
BUILD_ROOT="${TESTS_ROOT}/.."
# macOS (still!) doesn't have `readlink -f` or `realpath`. That's OK, this is just for aesthetics.
if command -v realpath 1>/dev/null 2>/dev/null; then
TESTS_ROOT="$(realpath --no-symlinks "${TESTS_ROOT}")"
BUILD_ROOT="$(realpath --no-symlinks "${BUILD_ROOT}")"
fi
if ! test -z "$__fish_is_running_tests"; then
echo "Recursive test invocation detected!" 1>&2