2021-03-16 01:42:53 +08:00
|
|
|
# This adds ctest support to the project
|
|
|
|
enable_testing()
|
|
|
|
|
2021-09-21 03:51:24 +08:00
|
|
|
# Put in a tests folder to reduce the top level targets in IDEs.
|
|
|
|
set(CMAKE_FOLDER tests)
|
|
|
|
|
2021-03-29 02:59:14 +08: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-09 07:31:50 +08: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.
|
|
|
|
# * 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-27 05:07:40 +08:00
|
|
|
# The top-level test target is "fish_run_tests".
|
|
|
|
add_custom_target(fish_run_tests
|
2024-03-30 23:10:12 +08:00
|
|
|
COMMAND env FISH_FORCE_COLOR=1
|
2021-10-18 23:00:19 +08:00
|
|
|
FISH_SOURCE_DIR=${CMAKE_SOURCE_DIR}
|
2021-09-08 00:33:56 +08:00
|
|
|
${CMAKE_CTEST_COMMAND} --force-new-ctest-process # --verbose
|
2021-08-30 05:03:23 +08:00
|
|
|
--output-on-failure --progress
|
2024-01-07 19:00:19 +08:00
|
|
|
DEPENDS tests_dir funcs_dir tests_buildroot_target
|
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-09 07:31:50 +08:00
|
|
|
USES_TERMINAL
|
|
|
|
)
|
2021-11-27 05:07:40 +08: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-09 07:31:50 +08:00
|
|
|
cmake_policy(POP)
|
|
|
|
|
2017-10-05 12:34:48 +08:00
|
|
|
# The "test" directory.
|
2020-03-15 07:11:35 +08:00
|
|
|
set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/test)
|
2017-10-05 12:34:48 +08:00
|
|
|
|
|
|
|
# The directory into which fish is installed.
|
2020-03-15 07:11:35 +08:00
|
|
|
set(TEST_INSTALL_DIR ${TEST_DIR}/buildroot)
|
2017-10-05 12:34:48 +08:00
|
|
|
|
|
|
|
# The directory where the tests expect to find the fish root (./bin, etc)
|
2020-03-15 07:11:35 +08:00
|
|
|
set(TEST_ROOT_DIR ${TEST_DIR}/root)
|
2017-10-05 12:34:48 +08:00
|
|
|
|
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-09 07:31:50 +08:00
|
|
|
# Copy needed directories for out-of-tree builds
|
2020-03-15 07:11:35 +08:00
|
|
|
if(NOT FISH_IN_TREE_BUILD)
|
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-09 07:31:50 +08:00
|
|
|
add_custom_target(funcs_dir)
|
|
|
|
add_custom_command(TARGET funcs_dir
|
2024-11-13 04:23:28 +08:00
|
|
|
POST_BUILD
|
2021-09-02 23:27:10 +08:00
|
|
|
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/share
|
|
|
|
# Don't run ln twice or it will create a new link in the link.
|
|
|
|
COMMAND test -e ${CMAKE_BINARY_DIR}/share/functions || ln -sf
|
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-09 07:31:50 +08:00
|
|
|
${CMAKE_SOURCE_DIR}/share/functions/ ${CMAKE_BINARY_DIR}/share/functions
|
|
|
|
COMMENT "Symlinking fish functions to binary dir"
|
|
|
|
VERBATIM)
|
|
|
|
|
|
|
|
add_custom_target(tests_dir DEPENDS tests)
|
|
|
|
add_custom_command(TARGET tests_dir
|
2024-11-13 04:23:28 +08:00
|
|
|
POST_BUILD
|
2018-01-23 17:35:43 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
|
|
|
${CMAKE_SOURCE_DIR}/tests/ ${CMAKE_BINARY_DIR}/tests/
|
|
|
|
COMMENT "Copying test files to binary dir"
|
|
|
|
VERBATIM)
|
2020-03-15 07:11:35 +08:00
|
|
|
endif()
|
2017-09-01 15:31:51 +08:00
|
|
|
|
2019-06-10 02:13:31 +08:00
|
|
|
# Copy littlecheck.py
|
2020-03-15 07:11:35 +08:00
|
|
|
configure_file(build_tools/littlecheck.py littlecheck.py COPYONLY)
|
2019-06-10 02:13:31 +08:00
|
|
|
|
2020-03-03 07:20:29 +08:00
|
|
|
# Copy pexpect_helper.py
|
|
|
|
configure_file(build_tools/pexpect_helper.py pexpect_helper.py COPYONLY)
|
|
|
|
|
2021-09-19 13:09:31 +08:00
|
|
|
# Suppress generating Xcode schemes for all tests, there's too many.
|
|
|
|
set(CMAKE_XCODE_GENERATE_SCHEME 0)
|
|
|
|
|
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-09 07:31:50 +08:00
|
|
|
# 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 19:00:19 +08: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 08:07:17 +08:00
|
|
|
function(add_test_target NAME)
|
2021-11-10 09:07:15 +08:00
|
|
|
string(REPLACE "/" "-" NAME ${NAME})
|
|
|
|
add_custom_target("test_${NAME}" COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -R "^${NAME}$$"
|
2024-01-07 19:00:19 +08:00
|
|
|
DEPENDS tests_dir funcs_dir tests_buildroot_target USES_TERMINAL )
|
2021-07-31 08:07:17 +08:00
|
|
|
endfunction()
|
|
|
|
|
2020-03-15 07:11:35 +08:00
|
|
|
add_custom_target(tests_buildroot_target
|
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-09 07:31:50 +08:00
|
|
|
# Make the directory in which to run tests:
|
2017-10-05 12:34:48 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_INSTALL_DIR}
|
2021-10-22 17:27:19 +08:00
|
|
|
COMMAND env DESTDIR=${TEST_INSTALL_DIR} ${CMAKE_COMMAND}
|
2017-10-05 12:34:48 +08:00
|
|
|
--build ${CMAKE_CURRENT_BINARY_DIR} --target install
|
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-09 07:31:50 +08:00
|
|
|
# Put fish_test_helper there too:
|
2019-04-07 13:22:11 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/fish_test_helper
|
|
|
|
${TEST_INSTALL_DIR}/${CMAKE_INSTALL_PREFIX}/bin
|
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-09 07:31:50 +08:00
|
|
|
# Also symlink fish to where the tests expect it to be:
|
2017-10-05 12:34:48 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E create_symlink
|
|
|
|
${TEST_INSTALL_DIR}/${CMAKE_INSTALL_PREFIX}
|
|
|
|
${TEST_ROOT_DIR}
|
2019-04-07 13:22:11 +08:00
|
|
|
DEPENDS fish fish_test_helper)
|
2017-10-05 12:34:48 +08:00
|
|
|
|
2021-03-16 01:42:53 +08: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}
|
2024-01-20 16:10:46 +08:00
|
|
|
COMMAND sh ${CMAKE_CURRENT_BINARY_DIR}/tests/test_driver.sh
|
2021-03-16 01:42:53 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/test.fish ${CHECK}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
|
|
|
|
)
|
2021-03-29 02:59:14 +08:00
|
|
|
set_tests_properties(${CHECK_NAME} PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
|
2022-04-11 04:40:51 +08: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-09 07:31:50 +08:00
|
|
|
add_test_target("${CHECK_NAME}")
|
2021-03-16 01:42:53 +08:00
|
|
|
endforeach(CHECK)
|
2021-03-19 02:23:31 +08: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}
|
2024-01-20 16:10:46 +08:00
|
|
|
COMMAND sh ${CMAKE_CURRENT_BINARY_DIR}/tests/test_driver.sh
|
2021-03-19 02:23:31 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/tests/interactive.fish ${PEXPECT}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests
|
|
|
|
)
|
2021-03-29 02:59:14 +08:00
|
|
|
set_tests_properties(${PEXPECT} PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
|
2022-04-11 04:40:51 +08:00
|
|
|
set_tests_properties(${PEXPECT} PROPERTIES ENVIRONMENT FISH_FORCE_COLOR=1)
|
2021-03-19 02:23:31 +08:00
|
|
|
add_test_target("${PEXPECT}")
|
|
|
|
endforeach(PEXPECT)
|
2023-01-15 06:56:24 +08:00
|
|
|
|
2024-01-13 08:26:28 +08:00
|
|
|
set(cargo_test_flags)
|
2023-01-15 06:56:24 +08:00
|
|
|
# Rust stuff.
|
2023-03-07 08:15:36 +08: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-22 00:56:50 +08:00
|
|
|
endif()
|
2024-08-04 16:18:06 +08: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-22 00:56:50 +08:00
|
|
|
|
|
|
|
if(DEFINED Rust_CARGO_TARGET)
|
2024-01-13 08:26:28 +08:00
|
|
|
list(APPEND cargo_test_flags "--target" ${Rust_CARGO_TARGET})
|
|
|
|
list(APPEND cargo_test_flags "--lib")
|
2023-03-07 08:15:36 +08:00
|
|
|
endif()
|
|
|
|
|
2024-01-08 04:38:49 +08:00
|
|
|
add_test(
|
|
|
|
NAME "cargo-test"
|
2024-12-12 00:04:44 +08:00
|
|
|
COMMAND env ${VARS_FOR_CARGO} cargo test --no-default-features ${CARGO_FLAGS} --workspace --target-dir ${rust_target_dir} ${cargo_test_flags}
|
2024-01-08 04:38:49 +08:00
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
|
|
|
)
|
|
|
|
set_tests_properties("cargo-test" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE})
|
|
|
|
add_test_target("cargo-test")
|