diff --git a/simulation/halsim_ds_socket/BUILD.bazel b/simulation/halsim_ds_socket/BUILD.bazel index ab5d9f2807..dd8d046165 100644 --- a/simulation/halsim_ds_socket/BUILD.bazel +++ b/simulation/halsim_ds_socket/BUILD.bazel @@ -78,7 +78,7 @@ cc_test( srcs = glob(["src/test/native/**/*.cpp"]), deps = [ "//simulation/halsim_ds_socket", - "//thirdparty/googletest", + "//thirdparty/catch2", ], ) diff --git a/simulation/halsim_ds_socket/build.gradle b/simulation/halsim_ds_socket/build.gradle index a1805c6d08..7e2f4e2abb 100644 --- a/simulation/halsim_ds_socket/build.gradle +++ b/simulation/halsim_ds_socket/build.gradle @@ -11,18 +11,13 @@ ext { apply plugin: 'google-test-test-suite' -ext { - staticGtestConfigs = [:] -} - -staticGtestConfigs["${pluginName}Test"] = [] -apply from: "${rootDir}/shared/googletest.gradle" +apply from: "${rootDir}/shared/catch2.gradle" apply from: "${rootDir}/shared/plugins/setupBuild.gradle" model { testSuites { - "${pluginName}Test"(GoogleTestTestSuiteSpec) { + "${pluginName}Catch2Test"(GoogleTestTestSuiteSpec) { for(NativeComponentSpec c : $.components) { if (c.name == pluginName) { testing c @@ -38,6 +33,9 @@ model { srcDirs 'src/test/native/include', 'src/main/native/cpp' } } + binaries.all { + lib project: ':thirdparty:catch2', library: 'catch2', linkage: 'static' + } } } binaries { diff --git a/simulation/halsim_ds_socket/src/test/native/cpp/main.cpp b/simulation/halsim_ds_socket/src/test/native/cpp/main.cpp index 8b833f274b..ad112afa40 100644 --- a/simulation/halsim_ds_socket/src/test/native/cpp/main.cpp +++ b/simulation/halsim_ds_socket/src/test/native/cpp/main.cpp @@ -2,13 +2,35 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include +#include + +#include +#include #include "wpi/hal/HAL.h" -int main(int argc, char** argv) { - HAL_Initialize(500, 0); - ::testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); - return ret; +namespace { + +bool IsCatchListCommand(int argc, char** argv) { + for (int i = 1; i < argc; ++i) { + std::string_view arg{argv[i]}; + if (arg == "--list-tests" || arg == "--list-tags" || + arg == "--list-reporters" || arg == "--list-listeners") { + return true; + } + } + return false; +} + +} // namespace + +TEST_CASE("HALSimDSSocket RuntimeType", "[simulation][halsim_ds_socket]") { + CHECK(HAL_RuntimeType::HAL_RUNTIME_SIMULATION == HAL_GetRuntimeType()); +} + +int main(int argc, char** argv) { + if (!IsCatchListCommand(argc, argv)) { + HAL_Initialize(500, 0); + } + return Catch::Session().run(argc, argv); } diff --git a/simulation/halsim_gui/BUILD.bazel b/simulation/halsim_gui/BUILD.bazel index 23f6bc0fa5..6a472aa0b2 100644 --- a/simulation/halsim_gui/BUILD.bazel +++ b/simulation/halsim_gui/BUILD.bazel @@ -130,7 +130,7 @@ cc_test( ], deps = [ ":halsim_gui", - "//thirdparty/googletest", + "//thirdparty/catch2", ], ) diff --git a/simulation/halsim_gui/build.gradle b/simulation/halsim_gui/build.gradle index 3334c87312..1e8f231bff 100644 --- a/simulation/halsim_gui/build.gradle +++ b/simulation/halsim_gui/build.gradle @@ -10,15 +10,34 @@ ext { apply plugin: 'google-test-test-suite' -ext { - staticGtestConfigs = [:] -} - -staticGtestConfigs["${pluginName}Test"] = [] -apply from: "${rootDir}/shared/googletest.gradle" +apply from: "${rootDir}/shared/catch2.gradle" apply from: "${rootDir}/shared/plugins/setupBuild.gradle" +model { + testSuites { + "${pluginName}Catch2Test"(GoogleTestTestSuiteSpec) { + for(NativeComponentSpec c : $.components) { + if (c.name == pluginName) { + testing c + break + } + } + sources.cpp { + source { + srcDirs 'src/test/native/cpp' + include '**/*.cpp' + } + exportedHeaders { + srcDirs 'src/test/native/include', 'src/main/native/cpp' + } + } + binaries.all { + lib project: ':thirdparty:catch2', library: 'catch2', linkage: 'static' + } + } + } +} model { binaries { @@ -48,5 +67,12 @@ model { } } } + withType(GoogleTestTestSuiteBinarySpec) { + project(':hal').addHalDependency(it, 'shared') + project(':ntcore').addNtcoreDependency(it, 'shared') + lib project: ':wpinet', library: 'wpinet', linkage: 'shared' + lib project: ':wpiutil', library: 'wpiutil', linkage: 'shared' + lib library: pluginName, linkage: 'shared' + } } } diff --git a/simulation/halsim_gui/src/test/native/cpp/main.cpp b/simulation/halsim_gui/src/test/native/cpp/main.cpp index 8b833f274b..435b5d805b 100644 --- a/simulation/halsim_gui/src/test/native/cpp/main.cpp +++ b/simulation/halsim_gui/src/test/native/cpp/main.cpp @@ -2,13 +2,35 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include +#include + +#include +#include #include "wpi/hal/HAL.h" -int main(int argc, char** argv) { - HAL_Initialize(500, 0); - ::testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); - return ret; +namespace { + +bool IsCatchListCommand(int argc, char** argv) { + for (int i = 1; i < argc; ++i) { + std::string_view arg{argv[i]}; + if (arg == "--list-tests" || arg == "--list-tags" || + arg == "--list-reporters" || arg == "--list-listeners") { + return true; + } + } + return false; +} + +} // namespace + +TEST_CASE("HALSimGui RuntimeType", "[simulation][halsim_gui]") { + CHECK(HAL_RuntimeType::HAL_RUNTIME_SIMULATION == HAL_GetRuntimeType()); +} + +int main(int argc, char** argv) { + if (!IsCatchListCommand(argc, argv)) { + HAL_Initialize(500, 0); + } + return Catch::Session().run(argc, argv); } diff --git a/simulation/halsim_ws_client/build.gradle b/simulation/halsim_ws_client/build.gradle index e8bd3313a9..f03f1420d2 100644 --- a/simulation/halsim_ws_client/build.gradle +++ b/simulation/halsim_ws_client/build.gradle @@ -9,15 +9,6 @@ ext { pluginName = 'halsim_ws_client' } -apply plugin: 'google-test-test-suite' - -ext { - staticGtestConfigs = [:] -} - -staticGtestConfigs["${pluginName}Test"] = [] -apply from: "${rootDir}/shared/googletest.gradle" - apply from: "${rootDir}/shared/plugins/setupBuild.gradle" model { diff --git a/simulation/halsim_ws_core/build.gradle b/simulation/halsim_ws_core/build.gradle index e18903b7c1..49157bfd3e 100644 --- a/simulation/halsim_ws_core/build.gradle +++ b/simulation/halsim_ws_core/build.gradle @@ -14,16 +14,6 @@ ext { pluginName = 'halsim_ws_core' } -apply plugin: 'google-test-test-suite' - - -ext { - staticGtestConfigs = [:] -} - -staticGtestConfigs["${pluginName}Test"] = [] -apply from: "${rootDir}/shared/googletest.gradle" - apply from: "${rootDir}/shared/config.gradle" apply from: "${rootDir}/shared/plugins/publish.gradle" diff --git a/simulation/halsim_ws_server/BUILD.bazel b/simulation/halsim_ws_server/BUILD.bazel index a25fcce1de..3a4e2eead1 100644 --- a/simulation/halsim_ws_server/BUILD.bazel +++ b/simulation/halsim_ws_server/BUILD.bazel @@ -89,7 +89,7 @@ cc_test( deps = [ ":halsim_ws_server", ":test_headers", - "//thirdparty/googletest", + "//thirdparty/catch2", ], ) diff --git a/simulation/halsim_ws_server/build.gradle b/simulation/halsim_ws_server/build.gradle index 2973e0b799..561c4afe3c 100644 --- a/simulation/halsim_ws_server/build.gradle +++ b/simulation/halsim_ws_server/build.gradle @@ -11,19 +11,13 @@ ext { apply plugin: 'google-test-test-suite' - -ext { - staticGtestConfigs = [:] -} - -staticGtestConfigs["${pluginName}Test"] = [] -apply from: "${rootDir}/shared/googletest.gradle" +apply from: "${rootDir}/shared/catch2.gradle" apply from: "${rootDir}/shared/plugins/setupBuild.gradle" model { testSuites { - "${pluginName}Test"(GoogleTestTestSuiteSpec) { + "${pluginName}Catch2Test"(GoogleTestTestSuiteSpec) { for(NativeComponentSpec c : $.components) { if (c.name == pluginName) { testing c @@ -39,6 +33,9 @@ model { srcDirs 'src/test/native/include', 'src/main/native/cpp' } } + binaries.all { + lib project: ':thirdparty:catch2', library: 'catch2', linkage: 'static' + } } } diff --git a/simulation/halsim_ws_server/src/test/native/cpp/main.cpp b/simulation/halsim_ws_server/src/test/native/cpp/main.cpp index 8c3544c857..3b1d8d8810 100644 --- a/simulation/halsim_ws_server/src/test/native/cpp/main.cpp +++ b/simulation/halsim_ws_server/src/test/native/cpp/main.cpp @@ -6,10 +6,12 @@ #include #include +#include #include #include -#include +#include +#include #include "WebServerClientTest.hpp" #include "wpi/hal/DriverStation.h" @@ -25,8 +27,7 @@ using namespace wpilibws; static const int POLLING_SPEED = 10; // 10 ms polling -class WebServerIntegrationTest : public ::testing::Test { - public: +struct WebServerIntegrationTest { WebServerIntegrationTest() { // Initialize server m_server.Initialize(); @@ -40,25 +41,42 @@ class WebServerIntegrationTest : public ::testing::Test { bool IsConnectedClientWS() { return m_webserverClient->IsConnectedWS(); } - protected: std::shared_ptr m_webserverClient; HALSimWSServer m_server; }; -TEST_F(WebServerIntegrationTest, DISABLED_DigitalOutput) { +namespace { + +bool IsCatchListCommand(int argc, char** argv) { + for (int i = 1; i < argc; ++i) { + std::string_view arg{argv[i]}; + if (arg == "--list-tests" || arg == "--list-tags" || + arg == "--list-reporters" || arg == "--list-listeners") { + return true; + } + } + return false; +} + +} // namespace + +TEST_CASE("WebServerIntegrationTest DigitalOutput", + "[simulation][halsim_ws_server][.]") { + WebServerIntegrationTest test; + // Create expected results const bool EXPECTED_VALUE = false; const int PIN = 0; bool done = false; // Attach timer to loop for test function - m_server.runner.ExecSync([&](auto& loop) { + test.m_server.runner.ExecSync([&](auto& loop) { auto timer = wpi::net::uv::Timer::Create(loop); timer->timeout.connect([&] { if (done) { return; } - if (IsConnectedClientWS()) { + if (test.IsConnectedClientWS()) { wpi::util::print("***** Setting DIO value for pin {} to {}\n", PIN, (EXPECTED_VALUE ? "true" : "false")); HALSIM_SetDIOValue(PIN, EXPECTED_VALUE); @@ -78,7 +96,7 @@ TEST_F(WebServerIntegrationTest, DISABLED_DigitalOutput) { std::string test_device; bool test_value = true; // Default value from HAL initialization try { - auto& msg = m_webserverClient->GetLastMessage(); + auto& msg = test.m_webserverClient->GetLastMessage(); test_type = msg.at("type").get_string(); test_device = msg.at("device").get_string(); auto& data = msg.at("data"); @@ -90,31 +108,34 @@ TEST_F(WebServerIntegrationTest, DISABLED_DigitalOutput) { } // Compare results - EXPECT_EQ("DIO", test_type); - EXPECT_EQ(std::to_string(PIN), test_device); - EXPECT_EQ(EXPECTED_VALUE, test_value); + CHECK("DIO" == test_type); + CHECK(std::to_string(PIN) == test_device); + CHECK(EXPECTED_VALUE == test_value); } -TEST_F(WebServerIntegrationTest, DISABLED_DigitalInput) { +TEST_CASE("WebServerIntegrationTest DigitalInput", + "[simulation][halsim_ws_server][.]") { + WebServerIntegrationTest test; + // Create expected results const bool EXPECTED_VALUE = false; const int PIN = 0; bool done = false; // Attach timer to loop for test function - m_server.runner.ExecSync([&](auto& loop) { + test.m_server.runner.ExecSync([&](auto& loop) { auto timer = wpi::net::uv::Timer::Create(loop); timer->timeout.connect([&] { if (done) { return; } - if (IsConnectedClientWS()) { + if (test.IsConnectedClientWS()) { wpi::util::json msg = wpi::util::json::object(); msg["type"] = "DIO"; msg["device"] = std::to_string(PIN); msg["data"] = wpi::util::json::object("<>value", EXPECTED_VALUE); wpi::util::print("***** Input JSON: {}\n", msg.to_string()); - m_webserverClient->SendMessage(msg); + test.m_webserverClient->SendMessage(msg); done = true; } }); @@ -128,22 +149,25 @@ TEST_F(WebServerIntegrationTest, DISABLED_DigitalInput) { // Compare results bool test_value = HALSIM_GetDIOValue(PIN); - EXPECT_EQ(EXPECTED_VALUE, test_value); + CHECK(EXPECTED_VALUE == test_value); } -TEST_F(WebServerIntegrationTest, DriverStation) { +TEST_CASE("WebServerIntegrationTest DriverStation", + "[simulation][halsim_ws_server]") { + WebServerIntegrationTest test; + // Create expected results const bool EXPECTED_VALUE = true; bool done = false; // Attach timer to loop for test function - m_server.runner.ExecSync([&](auto& loop) { + test.m_server.runner.ExecSync([&](auto& loop) { auto timer = wpi::net::uv::Timer::Create(loop); timer->timeout.connect([&] { if (done) { return; } - if (IsConnectedClientWS()) { + if (test.IsConnectedClientWS()) { auto data = wpi::util::json::object(); data[">enabled"] = EXPECTED_VALUE; data[">new_data"] = true; @@ -152,7 +176,7 @@ TEST_F(WebServerIntegrationTest, DriverStation) { msg["device"] = ""; msg["data"] = std::move(data); wpi::util::print("***** Input JSON: {}\n", msg.to_string()); - m_webserverClient->SendMessage(msg); + test.m_webserverClient->SendMessage(msg); done = true; } }); @@ -170,12 +194,12 @@ TEST_F(WebServerIntegrationTest, DriverStation) { HAL_ControlWord cw; HAL_GetControlWord(&cw); bool test_value = HAL_ControlWord_IsEnabled(cw); - EXPECT_EQ(EXPECTED_VALUE, test_value); + CHECK(EXPECTED_VALUE == test_value); } int main(int argc, char* argv[]) { - ::testing::InitGoogleTest(&argc, argv); - HAL_Initialize(500, 0); - int ret = RUN_ALL_TESTS(); - return ret; + if (!IsCatchListCommand(argc, argv)) { + HAL_Initialize(500, 0); + } + return Catch::Session().run(argc, argv); } diff --git a/simulation/halsim_xrp/build.gradle b/simulation/halsim_xrp/build.gradle index 6185c799dd..12d6465047 100644 --- a/simulation/halsim_xrp/build.gradle +++ b/simulation/halsim_xrp/build.gradle @@ -9,15 +9,6 @@ ext { pluginName = 'halsim_xrp' } -apply plugin: 'google-test-test-suite' - -ext { - staticGtestConfigs = [:] -} - -staticGtestConfigs["${pluginName}Test"] = [] -apply from: "${rootDir}/shared/googletest.gradle" - apply from: "${rootDir}/shared/plugins/setupBuild.gradle" model {