feat: add a wrapper module for add_test#240
feat: add a wrapper module for add_test#240FeignClaims wants to merge 13 commits intoaminya:mainfrom
Conversation
aminya
left a comment
There was a problem hiding this comment.
Could you use the added functions in some of the test projects?
| if(${type} STREQUAL "library_test") | ||
| add_executable(${target_name}) | ||
| set(scope PRIVATE) | ||
| elseif(${type} STREQUAL "test_config") | ||
| add_library(${target_name} INTERFACE) | ||
| set(scope INTERFACE) | ||
| endif() |
There was a problem hiding this comment.
What happens in the else condition?
There was a problem hiding this comment.
The function _configure_target currently only supports type "library_test" and "test_config". Here the if-else checks the type to add the corresponding target, and set the scope correctly.
For instance, a "library_test" is an executable target, it will link all its libraries PRIVATE-ly; a "test_config" is an interface library as it is used to propagate the test configuration, and it will link its libraries libraries INTERFACE-ly.
| endif() | ||
| endfunction() | ||
|
|
||
| function(_configure_target target_name type) |
There was a problem hiding this comment.
I like how this function lumps together all the CMake functions making things more declarative. Could you name it as something like add_target?
There was a problem hiding this comment.
The problem here is whether I should split DEPENDENCIES_CONFIG, DEPENDENCIES and LIBRARIES to [PRIVATE|PUBLIC|INTERFACE]_DEPENDENCIES_CONFIG and so on.
Currently this function only supports "library_test" (executable) and "test_config" (header-only library), they are expected to only link one dependency type (PRIVATE for executable and INTERFACE for header-only library).
But for a non-header-only library, it might link a PRIVATE library, a PUBLIC library and a INTERFACE library at the same time. If this function is named as add_blah, users might expect this function also works on non-header-only libraries, so for a correct linkage, DEPENDENCIES_CONFIG must be split to [PRIVATE|PUBLIC|INTERFACE]_DEPENDENCIES_CONFIG.
a9a9de3 to
c50e227
Compare
|
Added these functions to test projects. |
5d5b74e to
1ef80b1
Compare
|
Changed test projects based on this feature and tested well, ready to merge. |
caf8071 to
9170c3b
Compare
ClausKlein
left a comment
There was a problem hiding this comment.
Add an example or document the use of add_test() with multiple args please.
| ## tests | ||
| enable_testing() | ||
| add_test(NAME main COMMAND main) | ||
| add_executable_test(main no_arg) |
There was a problem hiding this comment.
Why should I write no_arg?
There was a problem hiding this comment.
The add_executable_test actually creates a test named test.<executable>.<test_name>. Since users might write multiple tests for an executable, no_arg here is just a name saying this test has no arg.
| # tests | ||
| enable_testing() | ||
| add_test(NAME another_main COMMAND another_main) | ||
| add_executable_test(another_main no_arg) |
There was a problem hiding this comment.
Why should I write no_arg?
There's already an example in the document: https://github.com/FeignClaims/project_options/blob/9170c3b7b5e68840d01d79beed3b85948cd71d0e/src/Tests.cmake#L350-L355 Additionally, I added a use of add_executable_test(main no_arg)
add_executable_test(main with_arg
EXECUTE_ARGS hello world
) |
25fe7f3 to
f62419d
Compare
1bee95a to
f62419d
Compare
from aminya/cpp_vcpkg_project#35.
Additionally, add
[WORKING_DIRECTORY <dir>]and[WILL_FAIL]to specify the corresponding test property.