-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GHI #13 Support install tests from multiple directories
Signed-off-by: doodspav <[email protected]>
- Loading branch information
Showing
10 changed files
with
193 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include(../cmake/CreateTest.cmake) | ||
|
||
create_test(BT example_add SOURCE example_add.cpp) | ||
create_test(BT example_sub SOURCE example_sub.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <gtest/gtest.h> | ||
#include <patomic/patomic.h> | ||
|
||
|
||
TEST(suite, name) | ||
{ | ||
ASSERT_EQ(5, patomic_example_add(2, 3)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <gtest/gtest.h> | ||
#include <patomic/patomic.h> | ||
|
||
|
||
TEST(suite2, name2) | ||
{ | ||
ASSERT_EQ(5, patomic_example_add(2, 3)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# ---- Create Test ---- | ||
|
||
# Creates a test executable and registers it with CTest. | ||
# | ||
# create_test( | ||
# BT|UT <name> | ||
# [INCLUDE <item>...] | ||
# [SOURCE <item>...] | ||
# ) | ||
function(create_test) | ||
cmake_parse_arguments( | ||
"ARG" | ||
"" | ||
"BT;UT" | ||
"INCLUDE;SOURCE" | ||
${ARGN} | ||
) | ||
|
||
|
||
# validate arguments | ||
|
||
set(args_valid TRUE) | ||
set(func_name "create_test") | ||
|
||
if(NOT ARG_BT AND NOT ARG_UT) | ||
message(WARNING "<BT|UT> option needs to be specified when invoking '${func_name}'") | ||
set(args_valid FALSE) | ||
elseif(ARG_BT AND ARG_UT) | ||
message(WARNING "Only one of <BT|UT> options may be specified when invoking '${func_name}'") | ||
set(args_valid FALSE) | ||
endif() | ||
|
||
if(DEFINED ARG_UNPARSED_ARGUMENTS) | ||
message(WARNING "The following arguments were not recognised when invoking '${func_name}': ${ARG_UNPARSED_ARGUMENTS}") | ||
set(args_valid FALSE) | ||
endif() | ||
|
||
if(NOT ${args_valid}) | ||
message(FATAL_ERROR "Aborting '${func_name}' due to invalid arguments") | ||
endif() | ||
|
||
|
||
# coalesce arguments | ||
|
||
set(name "${ARG_BT}") | ||
set(kind "bt") | ||
if(ARG_UT) | ||
set(name "${ARG_UT}") | ||
set(kind "ut") | ||
endif() | ||
|
||
|
||
# setup target | ||
|
||
set(target patomic_${kind}_${name}) | ||
|
||
add_executable( | ||
${target} | ||
${ARG_INCLUDE} | ||
${ARG_SOURCE} | ||
) | ||
|
||
target_link_libraries( | ||
${target} | ||
PRIVATE | ||
patomic::patomic | ||
GTest::gtest_main | ||
) | ||
|
||
target_compile_features(${target} PRIVATE cxx_std_14) | ||
|
||
|
||
# setup tests with CTest | ||
|
||
# must be run in same directory scope as target | ||
gtest_add_tests( | ||
TARGET ${target} | ||
TEST_LIST added_tests | ||
) | ||
|
||
# get these values from root target so we don't recompute every time | ||
get_target_property(deps_path patomic_test WIN_DEPS_PATH) | ||
get_target_property(win_and_shared patomic_test WIN_AND_SHARED) | ||
|
||
# set environment variable for each test so that CTest works automatically | ||
if(win_and_shared AND patomic_test_SET_CTEST_PATH_ENV_WINDOWS) | ||
foreach(test IN LISTS added_tests) | ||
set_property( | ||
TEST "${test}" | ||
PROPERTY ENVIRONMENT "PATH=${deps_path}" | ||
) | ||
endforeach() | ||
endif() | ||
|
||
|
||
# setup install of target | ||
|
||
set(component patomic_${kind}) | ||
|
||
if(NOT CMAKE_SKIP_INSTALL_RULES) | ||
install( | ||
TARGETS ${target} | ||
RUNTIME # | ||
COMPONENT ${component} | ||
DESTINATION "${CMAKE_INSTALL_TESTDIR}/patomic/${kind}" | ||
EXCLUDE_FROM_ALL | ||
) | ||
endif() | ||
|
||
|
||
# attach to root target | ||
|
||
add_dependencies(patomic_test ${target}) | ||
|
||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include(../cmake/CreateTest.cmake) | ||
|
||
create_test(UT example_add SOURCE example_add.cpp) | ||
create_test(UT example_sub SOURCE example_sub.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <gtest/gtest.h> | ||
#include <patomic/patomic.h> | ||
|
||
|
||
TEST(suite, name) | ||
{ | ||
ASSERT_EQ(5, patomic_example_add(2, 3)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <gtest/gtest.h> | ||
#include <patomic/patomic.h> | ||
|
||
|
||
TEST(suite2, name2) | ||
{ | ||
ASSERT_EQ(5, patomic_example_add(2, 3)); | ||
} |