2021-03-15 17:42:53 +00:00
|
|
|
# This adds ctest support to the project
|
|
|
|
enable_testing()
|
|
|
|
|
2025-01-09 00:07:16 +00:00
|
|
|
# By default, ctest runs tests serially
|
2025-01-11 01:16:32 +00:00
|
|
|
# Support CTEST_PARALLEL_LEVEL as an environment variable in addition to a CMake variable
|
2025-01-09 00:07:16 +00:00
|
|
|
if(NOT CTEST_PARALLEL_LEVEL)
|
2025-01-11 01:16:32 +00:00
|
|
|
set(CTEST_PARALLEL_LEVEL $ENV{CTEST_PARALLEL_LEVEL})
|
|
|
|
if(NOT CTEST_PARALLEL_LEVEL)
|
|
|
|
include(ProcessorCount)
|
|
|
|
ProcessorCount(CORES)
|
|
|
|
set(CTEST_PARALLEL_LEVEL ${CORES})
|
|
|
|
endif()
|
2025-01-09 00:07:16 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2021-09-20 19:51:24 +00:00
|
|
|
# Put in a tests folder to reduce the top level targets in IDEs.
|
|
|
|
set(CMAKE_FOLDER tests)
|
|
|
|
|
2021-03-28 18:59:14 +00:00
|
|
|
# We will use 125 as a reserved exit code to indicate that a test has been skipped, i.e. it did not
|
|
|
|
# pass but it should not be considered a failed test run, either.
|
|
|
|
set(SKIP_RETURN_CODE 125)
|
|
|
|
|
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).
2021-08-08 23:31:50 +00:00
|
|
|
# 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.
|
2025-01-09 00:07:16 +00:00
|
|
|
# * It is not possible to set top-level CTest options/settings such as CTEST_PARALLEL_LEVEL from
|
|
|
|
# within the CMake configuration file.
|
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).
2021-08-08 23:31:50 +00:00
|
|
|
# * 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.
|
|
|
|
# * 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.
|
|
|
|
|
2021-11-26 21:07:40 +00:00
|
|
|
# The top-level test target is "fish_run_tests".
|
|
|
|
add_custom_target(fish_run_tests
|
2025-01-09 00:07:16 +00:00
|
|
|
COMMAND env CTEST_PARALLEL_LEVEL=${CTEST_PARALLEL_LEVEL} FISH_FORCE_COLOR=1
|
2021-10-18 15:00:19 +00:00
|
|
|
FISH_SOURCE_DIR=${CMAKE_SOURCE_DIR}
|
2021-09-07 16:33:56 +00:00
|
|
|
${CMAKE_CTEST_COMMAND} --force-new-ctest-process # --verbose
|
2021-08-29 21:03:23 +00:00
|
|
|
--output-on-failure --progress
|
2025-01-12 17:05:50 +00:00
|
|
|
DEPENDS fish fish_indent fish_key_reader fish_test_helper
|
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).
2021-08-08 23:31:50 +00:00
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2021-11-26 21:07:40 +00:00
|
|
|
|
|
|
|
# If CMP0037 is available, also make an alias "test" target.
|
|
|
|
# Note that this policy may not be available, in which case definining such a target silently fails.
|
|
|
|
cmake_policy(PUSH)
|
|
|
|
if(POLICY CMP0037)
|
|
|
|
cmake_policy(SET CMP0037 OLD)
|
|
|
|
add_custom_target(test DEPENDS fish_run_tests)
|
|
|
|
endif()
|
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).
2021-08-08 23:31:50 +00:00
|
|
|
cmake_policy(POP)
|
|
|
|
|
|
|
|
# CMake being CMake, you can't just add a DEPENDS argument to add_test to make it depend on any of
|
|
|
|
# your binaries actually being built before `make test` is executed (requiring `make all` first),
|
2024-01-07 11:00:19 +00:00
|
|
|
# and the only dependency a test can have is on another test. So we make building fish
|
|
|
|
# prerequisites to our entire top-level `test` target.
|
2021-07-31 00:07:17 +00:00
|
|
|
function(add_test_target NAME)
|
2021-11-10 01:07:15 +00:00
|
|
|
string(REPLACE "/" "-" NAME ${NAME})
|
|
|
|
add_custom_target("test_${NAME}" COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -R "^${NAME}$$"
|
2025-01-12 17:05:50 +00:00
|
|
|
DEPENDS fish fish_indent fish_key_reader fish_test_helper USES_TERMINAL)
|
2021-07-31 00:07:17 +00:00
|
|
|
endfunction()
|
|
|
|
|
2025-01-12 16:40:46 +00:00
|
|
|
add_executable(fish_test_helper tests/fish_test_helper.c)
|
|
|
|
|
2021-03-15 17:42:53 +00:00
|
|
|
FILE(GLOB FISH_CHECKS CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/tests/checks/*.fish)
|
|
|
|
foreach(CHECK ${FISH_CHECKS})
|
|
|
|
get_filename_component(CHECK_NAME ${CHECK} NAME)
|
|
|
|
get_filename_component(CHECK ${CHECK} NAME_WE)
|
|
|
|
add_test(NAME ${CHECK_NAME}
|
2025-01-12 16:44:31 +00:00
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/tests/test_driver.py --cachedir=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
|
2025-01-11 20:13:19 +00:00
|
|
|
checks/${CHECK}.fish
|
2025-01-12 16:44:31 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
|
2021-03-15 17:42:53 +00:00
|
|
|
)
|
2021-03-28 18:59:14 +00:00
|
|
|
set_tests_properties(${CHECK_NAME} PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
|
2022-04-10 20:40:51 +00:00
|
|
|
set_tests_properties(${CHECK_NAME} PROPERTIES ENVIRONMENT FISH_FORCE_COLOR=1)
|
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).
2021-08-08 23:31:50 +00:00
|
|
|
add_test_target("${CHECK_NAME}")
|
2021-03-15 17:42:53 +00:00
|
|
|
endforeach(CHECK)
|
2021-03-18 18:23:31 +00:00
|
|
|
|
|
|
|
FILE(GLOB PEXPECTS CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/tests/pexpects/*.py)
|
|
|
|
foreach(PEXPECT ${PEXPECTS})
|
|
|
|
get_filename_component(PEXPECT ${PEXPECT} NAME)
|
|
|
|
add_test(NAME ${PEXPECT}
|
2025-01-12 16:44:31 +00:00
|
|
|
COMMAND ${CMAKE_SOURCE_DIR}/tests/test_driver.py --cachedir=${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
|
2025-01-11 20:13:19 +00:00
|
|
|
pexpects/${PEXPECT}
|
2025-01-12 16:44:31 +00:00
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
|
2021-03-18 18:23:31 +00:00
|
|
|
)
|
2021-03-28 18:59:14 +00:00
|
|
|
set_tests_properties(${PEXPECT} PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
|
2022-04-10 20:40:51 +00:00
|
|
|
set_tests_properties(${PEXPECT} PROPERTIES ENVIRONMENT FISH_FORCE_COLOR=1)
|
2021-03-18 18:23:31 +00:00
|
|
|
add_test_target("${PEXPECT}")
|
|
|
|
endforeach(PEXPECT)
|
2023-01-14 22:56:24 +00:00
|
|
|
|
2024-01-13 00:26:28 +00:00
|
|
|
set(cargo_test_flags)
|
2023-01-14 22:56:24 +00:00
|
|
|
# Rust stuff.
|
2023-03-07 00:15:36 +00:00
|
|
|
if(DEFINED ASAN)
|
|
|
|
# Rust w/ -Zsanitizer=address requires explicitly specifying the --target triple or else linker
|
|
|
|
# errors pertaining to asan symbols will ensue.
|
|
|
|
if(NOT DEFINED Rust_CARGO_TARGET)
|
|
|
|
message(FATAL_ERROR "ASAN requires defining the CMake variable Rust_CARGO_TARGET to the
|
|
|
|
intended target triple")
|
|
|
|
endif()
|
2024-06-21 16:56:50 +00:00
|
|
|
endif()
|
2024-08-04 08:18:06 +00:00
|
|
|
if(DEFINED TSAN)
|
|
|
|
if(NOT DEFINED Rust_CARGO_TARGET)
|
|
|
|
message(FATAL_ERROR "TSAN requires defining the CMake variable Rust_CARGO_TARGET to the
|
|
|
|
intended target triple")
|
|
|
|
endif()
|
|
|
|
endif()
|
2024-06-21 16:56:50 +00:00
|
|
|
|
|
|
|
if(DEFINED Rust_CARGO_TARGET)
|
2024-01-13 00:26:28 +00:00
|
|
|
list(APPEND cargo_test_flags "--target" ${Rust_CARGO_TARGET})
|
|
|
|
list(APPEND cargo_test_flags "--lib")
|
2023-03-07 00:15:36 +00:00
|
|
|
endif()
|
|
|
|
|
2024-01-07 20:38:49 +00:00
|
|
|
add_test(
|
|
|
|
NAME "cargo-test"
|
2024-12-11 16:04:44 +00:00
|
|
|
COMMAND env ${VARS_FOR_CARGO} cargo test --no-default-features ${CARGO_FLAGS} --workspace --target-dir ${rust_target_dir} ${cargo_test_flags}
|
2024-01-07 20:38:49 +00:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
set_tests_properties("cargo-test" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
|
|
|
|
add_test_target("cargo-test")
|