From 568299da25aaea412bac6f4ffc1de99d812063c2 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Mon, 18 Sep 2023 14:44:43 -0400 Subject: [PATCH] Fix windows tests, apply warnings flags --- .github/workflows/cmake.yml | 8 +-- glass/CMakeLists.txt | 1 + googletest/CMakeLists.txt | 2 + ntcore/CMakeLists.txt | 1 + .../src/test/native/cpp/LocalStorageTest.cpp | 56 +++++++++++-------- .../src/test/native/cpp/TableListenerTest.cpp | 4 +- .../test/native/cpp/net/ServerImplTest.cpp | 32 ++++++----- outlineviewer/CMakeLists.txt | 1 + wpigui/CMakeLists.txt | 1 + 9 files changed, 64 insertions(+), 42 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 9e44fcf384f..63d368814f7 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -45,11 +45,11 @@ jobs: run: python -m pip install jinja2 - name: configure - run: cmake -S . -B build -G "Ninja" ${{ matrix.flags }} + run: cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo ${{ matrix.flags }} - name: build working-directory: build - run: cmake --build . + run: cmake --build . --parallel $(nproc) - name: test working-directory: build @@ -75,8 +75,8 @@ jobs: run: python -m pip install jinja2 - name: configure - run: cmake -S . -B build -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE=Release -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DWITH_TESTS=OFF -DUSE_SYSTEM_FMTLIB=ON -DUSE_SYSTEM_LIBUV=ON -DUSE_SYSTEM_EIGEN=ON -DCMAKE_TOOLCHAIN_FILE=${{ runner.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_INSTALL_OPTIONS=--clean-after-build -DVCPKG_TARGET_TRIPLET=x64-windows-release -DVCPKG_HOST_TRIPLET=x64-windows-release + run: cmake -S . -B build -G "Ninja" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWITH_JAVA=OFF -DWITH_EXAMPLES=ON -DUSE_SYSTEM_FMTLIB=ON -DUSE_SYSTEM_LIBUV=ON -DUSE_SYSTEM_EIGEN=ON -DCMAKE_TOOLCHAIN_FILE=${{ runner.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_INSTALL_OPTIONS=--clean-after-build -DVCPKG_TARGET_TRIPLET=x64-windows-release -DVCPKG_HOST_TRIPLET=x64-windows-release - name: build working-directory: build - run: cmake --build . --parallel 1 --config Release + run: cmake --build . --parallel 1 diff --git a/glass/CMakeLists.txt b/glass/CMakeLists.txt index c41ca237e50..5bf89fb7b7a 100644 --- a/glass/CMakeLists.txt +++ b/glass/CMakeLists.txt @@ -65,6 +65,7 @@ endif() add_executable(glass ${glass_src} ${glass_resources_src} ${glass_rc} ${APP_ICON_MACOSX}) wpilib_link_macos_gui(glass) +wpilib_target_warnings(glass) target_link_libraries(glass libglassnt libglass) if (WIN32) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index bd6e588bcc2..e53fca1b21a 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -19,3 +19,5 @@ endif() target_compile_features(gtest PUBLIC cxx_std_20) target_compile_features(gtest_main PUBLIC cxx_std_20) +target_compile_features(gmock PUBLIC cxx_std_20) +target_compile_features(gmock_main PUBLIC cxx_std_20) diff --git a/ntcore/CMakeLists.txt b/ntcore/CMakeLists.txt index ff2d4038500..f7198f7a826 100644 --- a/ntcore/CMakeLists.txt +++ b/ntcore/CMakeLists.txt @@ -86,6 +86,7 @@ if (WITH_JAVA) endif() add_executable(ntcoredev src/dev/native/cpp/main.cpp) +wpilib_target_warnings(ntcoredev) target_link_libraries(ntcoredev ntcore) if (WITH_TESTS) diff --git a/ntcore/src/test/native/cpp/LocalStorageTest.cpp b/ntcore/src/test/native/cpp/LocalStorageTest.cpp index 64c17853888..eb57913a01a 100644 --- a/ntcore/src/test/native/cpp/LocalStorageTest.cpp +++ b/ntcore/src/test/native/cpp/LocalStorageTest.cpp @@ -254,9 +254,11 @@ TEST_F(LocalStorageTest, PubUnpubPub) { EXPECT_CALL(network, Publish(_, fooTopic, std::string_view{"foo"}, std::string_view{"boolean"}, wpi::json::object(), IsDefaultPubSubOptions())); - EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _, - "local subscribe to 'foo' disabled due to type " - "mismatch (wanted 'int', published as 'boolean')")); + EXPECT_CALL(logger, + Call(NT_LOG_INFO, _, _, + std::string_view{ + "local subscribe to 'foo' disabled due to type " + "mismatch (wanted 'int', published as 'boolean')"})); auto pub = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {}); auto val = Value::MakeBoolean(true, 5); @@ -298,9 +300,11 @@ TEST_F(LocalStorageTest, LocalPubConflict) { IsDefaultPubSubOptions())); auto pub1 = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {}); - EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _, - "local publish to 'foo' disabled due to type " - "mismatch (wanted 'int', currently 'boolean')")); + EXPECT_CALL( + logger, + Call(NT_LOG_INFO, _, _, + std::string_view{"local publish to 'foo' disabled due to type " + "mismatch (wanted 'int', currently 'boolean')"})); auto pub2 = storage.Publish(fooTopic, NT_INTEGER, "int", {}, {}); EXPECT_EQ(storage.GetTopicType(fooTopic), NT_BOOLEAN); @@ -337,9 +341,11 @@ TEST_F(LocalStorageTest, LocalSubConflict) { EXPECT_CALL(network, Subscribe(_, wpi::SpanEq({std::string{"foo"}}), IsDefaultPubSubOptions())); - EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _, - "local subscribe to 'foo' disabled due to type " - "mismatch (wanted 'int', published as 'boolean')")); + EXPECT_CALL(logger, + Call(NT_LOG_INFO, _, _, + std::string_view{ + "local subscribe to 'foo' disabled due to type " + "mismatch (wanted 'int', published as 'boolean')"})); storage.Subscribe(fooTopic, NT_INTEGER, "int", {}); } @@ -350,9 +356,11 @@ TEST_F(LocalStorageTest, RemotePubConflict) { storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {}); - EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _, - "network announce of 'foo' overriding local publish " - "(was 'boolean', now 'int')")); + EXPECT_CALL(logger, + Call(NT_LOG_INFO, _, _, + std::string_view{ + "network announce of 'foo' overriding local publish " + "(was 'boolean', now 'int')"})); storage.NetworkAnnounce("foo", "int", wpi::json::object(), {}); @@ -476,11 +484,10 @@ TEST_F(LocalStorageTest, SetValueEmptyUntypedEntry) { } TEST_F(LocalStorageTest, PublishUntyped) { - EXPECT_CALL( - logger, - Call( - NT_LOG_ERROR, _, _, - "cannot publish 'foo' with an unassigned type or empty type string")); + EXPECT_CALL(logger, + Call(NT_LOG_ERROR, _, _, + std::string_view{"cannot publish 'foo' with an unassigned " + "type or empty type string"})); EXPECT_EQ(storage.Publish(fooTopic, NT_UNASSIGNED, "", {}, {}), 0u); } @@ -697,8 +704,9 @@ void LocalStorageNumberVariantsTest::CreateSubscriber( void LocalStorageNumberVariantsTest::CreateSubscribers() { EXPECT_CALL(logger, Call(NT_LOG_INFO, _, _, - "local subscribe to 'foo' disabled due to type " - "mismatch (wanted 'boolean', published as 'double')")); + std::string_view{ + "local subscribe to 'foo' disabled due to type " + "mismatch (wanted 'boolean', published as 'double')"})); CreateSubscriber(&sub1, "subDouble", NT_DOUBLE, "double"); CreateSubscriber(&sub2, "subInteger", NT_INTEGER, "int"); CreateSubscriber(&sub3, "subFloat", NT_FLOAT, "float"); @@ -708,10 +716,12 @@ void LocalStorageNumberVariantsTest::CreateSubscribers() { } void LocalStorageNumberVariantsTest::CreateSubscribersArray() { - EXPECT_CALL(logger, - Call(NT_LOG_INFO, _, _, - "local subscribe to 'foo' disabled due to type " - "mismatch (wanted 'boolean[]', published as 'double[]')")); + EXPECT_CALL( + logger, + Call(NT_LOG_INFO, _, _, + std::string_view{ + "local subscribe to 'foo' disabled due to type " + "mismatch (wanted 'boolean[]', published as 'double[]')"})); CreateSubscriber(&sub1, "subDouble", NT_DOUBLE_ARRAY, "double[]"); CreateSubscriber(&sub2, "subInteger", NT_INTEGER_ARRAY, "int[]"); CreateSubscriber(&sub3, "subFloat", NT_FLOAT_ARRAY, "float[]"); diff --git a/ntcore/src/test/native/cpp/TableListenerTest.cpp b/ntcore/src/test/native/cpp/TableListenerTest.cpp index 70adf11e309..797c5052dc9 100644 --- a/ntcore/src/test/native/cpp/TableListenerTest.cpp +++ b/ntcore/src/test/native/cpp/TableListenerTest.cpp @@ -46,7 +46,7 @@ TEST_F(TableListenerTest, AddListener) { MockTableEventListener listener; table->AddListener(NT_EVENT_TOPIC | NT_EVENT_IMMEDIATE, listener.AsStdFunction()); - EXPECT_CALL(listener, Call(table.get(), "foovalue", _)); + EXPECT_CALL(listener, Call(table.get(), std::string_view{"foovalue"}, _)); PublishTopics(); EXPECT_TRUE(m_inst.WaitForListenerQueue(1.0)); } @@ -55,7 +55,7 @@ TEST_F(TableListenerTest, AddSubTableListener) { auto table = m_inst.GetTable("/foo"); MockSubTableListener listener; table->AddSubTableListener(listener.AsStdFunction()); - EXPECT_CALL(listener, Call(table.get(), "bar", _)); + EXPECT_CALL(listener, Call(table.get(), std::string_view{"bar"}, _)); PublishTopics(); EXPECT_TRUE(m_inst.WaitForListenerQueue(1.0)); } diff --git a/ntcore/src/test/native/cpp/net/ServerImplTest.cpp b/ntcore/src/test/native/cpp/net/ServerImplTest.cpp index 6660c653a5f..41951efba0e 100644 --- a/ntcore/src/test/native/cpp/net/ServerImplTest.cpp +++ b/ntcore/src/test/native/cpp/net/ServerImplTest.cpp @@ -33,6 +33,7 @@ using ::testing::Field; using ::testing::IsEmpty; using ::testing::Property; using ::testing::Return; +using ::testing::StrEq; using MockSetPeriodicFunc = ::testing::MockFunction; using MockConnected3Func = @@ -127,12 +128,15 @@ TEST_F(ServerImplTest, PublishLocal) { NT_Topic topicHandle3 = nt::Handle{0, 3, nt::Handle::kTopic}; { ::testing::InSequence seq; - EXPECT_CALL(local, NetworkAnnounce("test", "double", wpi::json::object(), - pubHandle)); - EXPECT_CALL(local, NetworkAnnounce("test2", "double", wpi::json::object(), - pubHandle2)); - EXPECT_CALL(local, NetworkAnnounce("test3", "double", wpi::json::object(), - pubHandle3)); + EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test"}, + std::string_view{"double"}, + wpi::json::object(), pubHandle)); + EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test2"}, + std::string_view{"double"}, + wpi::json::object(), pubHandle2)); + EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test3"}, + std::string_view{"double"}, + wpi::json::object(), pubHandle3)); } { @@ -158,7 +162,7 @@ TEST_F(ServerImplTest, PublishLocal) { "test", 3, "double", std::nullopt, wpi::json::object()}}); smsgs.emplace_back(net::ServerMessage{net::AnnounceMsg{ "test2", 8, "double", std::nullopt, wpi::json::object()}}); - EXPECT_CALL(wire, Text(EncodeText(smsgs))); // SendControl() + EXPECT_CALL(wire, Text(StrEq(EncodeText(smsgs)))); // SendControl() } EXPECT_CALL(wire, Flush()); // SendControl() EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendControl() @@ -166,7 +170,7 @@ TEST_F(ServerImplTest, PublishLocal) { std::vector smsgs; smsgs.emplace_back(net::ServerMessage{net::AnnounceMsg{ "test3", 11, "double", std::nullopt, wpi::json::object()}}); - EXPECT_CALL(wire, Text(EncodeText(smsgs))); // SendControl() + EXPECT_CALL(wire, Text(StrEq(EncodeText(smsgs)))); // SendControl() } EXPECT_CALL(wire, Flush()); // SendControl() } @@ -207,8 +211,9 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) { server.SetLocal(&local); NT_Publisher pubHandle = nt::Handle{0, 1, nt::Handle::kPublisher}; NT_Topic topicHandle = nt::Handle{0, 1, nt::Handle::kTopic}; - EXPECT_CALL( - local, NetworkAnnounce("test", "double", wpi::json::object(), pubHandle)); + EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test"}, + std::string_view{"double"}, + wpi::json::object(), pubHandle)); { std::vector msgs; @@ -231,7 +236,7 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) { std::vector smsgs; smsgs.emplace_back(net::ServerMessage{net::AnnounceMsg{ "test", 3, "double", std::nullopt, wpi::json::object()}}); - EXPECT_CALL(wire, Text(EncodeText(smsgs))); // SendValues() + EXPECT_CALL(wire, Text(StrEq(EncodeText(smsgs)))); // SendValues() } EXPECT_CALL(wire, Flush()); // SendValues() EXPECT_CALL(setPeriodic, Call(100)); // ClientSubscribe() @@ -289,8 +294,9 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) { Value value = Value::MakeDouble(5, -10); { ::testing::InSequence seq; - EXPECT_CALL(local, NetworkAnnounce("test", "double", wpi::json::object(), - pubHandle)) + EXPECT_CALL(local, NetworkAnnounce(std::string_view{"test"}, + std::string_view{"double"}, + wpi::json::object(), pubHandle)) .WillOnce(Return(topicHandle)); EXPECT_CALL(local, NetworkSetValue(topicHandle, defaultValue)); EXPECT_CALL(local, NetworkSetValue(topicHandle, value)); diff --git a/outlineviewer/CMakeLists.txt b/outlineviewer/CMakeLists.txt index e0690fc49e5..a92498e9ef5 100644 --- a/outlineviewer/CMakeLists.txt +++ b/outlineviewer/CMakeLists.txt @@ -19,6 +19,7 @@ endif() add_executable(outlineviewer ${outlineviewer_src} ${outlineviewer_resources_src} ${outlineviewer_rc} ${APP_ICON_MACOSX}) wpilib_link_macos_gui(outlineviewer) +wpilib_target_warnings(outlineviewer) target_link_libraries(outlineviewer libglassnt libglass) if (WIN32) diff --git a/wpigui/CMakeLists.txt b/wpigui/CMakeLists.txt index 2a6e6b213ab..edcc7fe4024 100644 --- a/wpigui/CMakeLists.txt +++ b/wpigui/CMakeLists.txt @@ -35,6 +35,7 @@ endif() add_executable(wpiguidev src/dev/native/cpp/main.cpp) wpilib_link_macos_gui(wpiguidev) +wpilib_target_warnings(wpiguidev) target_link_libraries(wpiguidev wpigui) install(TARGETS wpigui EXPORT wpigui)