Skip to content

Commit

Permalink
Add ExtraTestMacros target (#164)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Co-authored-by: Shameek Ganguly <[email protected]>
  • Loading branch information
mjcarroll and shameekganguly authored Nov 25, 2024
1 parent 5e1e78b commit c55b829
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 1 deletion.
23 changes: 23 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ cc_library(
],
)

cc_library(
name = "ExtraTestMacros",
hdrs = [
"include/gz/utils/ExtraTestMacros.hh",
"include/gz/utils/detail/ExtraTestMacros.hh",
],
includes = ["include"],
visibility = ["//visibility:public"],
deps = [
":SuppressWarning",
],
)

cc_test(
name = "ExtraTestMacros_TEST",
srcs = ["src/ExtraTestMacros_TEST.cc"],
deps = [
":ExtraTestMacros",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)

cc_library(
name = "ImplPtr",
hdrs = [
Expand Down
11 changes: 10 additions & 1 deletion include/gz/utils/ExtraTestMacros.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@
/// as part of the test suite execution.
/// The macro uses the Disabled_ prefix provided by googletest. See
/// https://chromium.googlesource.com/external/github.com/google/googletest/+/HEAD/googletest/docs/advanced.md
/// TODO(gz-utils4): remove the windows alias
#define GZ_UTILS_TEST_ENABLED_ONLY_ON_WINDOWS(TestName) \
DETAIL_GZ_UTILS_TEST_ENABLED_ONLY_ON_WINDOWS(TestName)
DETAIL_GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(TestName)

/// \brief Restrict the execution of the test to just the Windows platform
/// Other platforms will get the test compiled but it won't be run
/// as part of the test suite execution.
/// The macro uses the Disabled_ prefix provided by googletest. See
/// https://chromium.googlesource.com/external/github.com/google/googletest/+/HEAD/googletest/docs/advanced.md
#define GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(TestName) \
DETAIL_GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(TestName)

/// \brief Restrict the execution of the test for the Windows platform.
/// The test will be compiled on Windows too but will never be run as
Expand Down
96 changes: 96 additions & 0 deletions src/ExtraTestMacros_TEST.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <gtest/gtest.h>

#include <gz/utils/ExtraTestMacros.hh>

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_WIN32(OnlyWindowsOn))
{
#if defined __APPLE__
ADD_FAILURE() << "Windows only test on Apple platform";
#elif defined __linux__
ADD_FAILURE() << "Windows only test on Linux platform";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_WIN32(OnlyWindowsOff))
{
#if defined __WIN32
ADD_FAILURE() << "Ran on Windows platform";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_MAC(OnlyMacOn))
{
#if defined _WIN32
ADD_FAILURE() << "Apple only test on Windows platform";
#elif defined __linux__
ADD_FAILURE() << "Apple only test on Linux platform";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_MAC(OnlyMacOff))
{
#if defined __APPLE__
ADD_FAILURE() << "Ran on Apple platform";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(OnlyLinuxOn))
{
#if defined _WIN32
ADD_FAILURE() << "Linux only test on Windows platform";
#elif defined __APPLE__
ADD_FAILURE() << "Linux only test on Apple platform";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_LINUX(OnlyLinuxOff))
{
#if defined __linux__
ADD_FAILURE() << "Ran on Linux platform";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_ARM32(OnlyArm32On))
{
#if defined __aarch64__ || defined _M_ARM64
ADD_FAILURE() << "Ran on Arm64 arch";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_ARM32(OnlyArm32Off))
{
#if defined __arm__ || defined _M_ARM
ADD_FAILURE() << "Ran on Arm32 arch";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_ENABLED_ONLY_ON_ARM64(OnlyArm64On))
{
#if defined __arm__ || defined _M_ARM
ADD_FAILURE() << "Ran on Arm32 arch";
#endif
}

GTEST_TEST(ExtraTestMacros, GZ_UTILS_TEST_DISABLED_ON_ARM64(OnlyArm64Off))
{
#if defined __aarch64__ || defined _M_ARM64
ADD_FAILURE() << "Ran on Arm64 arch";
#endif
}

0 comments on commit c55b829

Please sign in to comment.