test treewide: iwyu
These changes are done by running iwyu manually under clang14.
Suppressed some obvious impl or details headers. Kept the recommended
public headers.
IWYU can increase readability, make maintenance easier, and avoid errors
in some cases. See details in
https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md.
This commit also uses its best effort to correct obvious errors through
iwyu pragma.
See reference here:
https://github.com/include-what-you-use/include-what-you-use#how-to-correct-iwyu-mistakes
Tested: unit test passed.
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I983b6f75601707cbb0f2f04546c3362ff4ba7fee
diff --git a/redfish-core/ut/configfile_test.cpp b/redfish-core/ut/configfile_test.cpp
index 2c68c0b..1d95a79 100644
--- a/redfish-core/ut/configfile_test.cpp
+++ b/redfish-core/ut/configfile_test.cpp
@@ -1,9 +1,13 @@
+#include "http_response.hpp"
#include "ibm/management_console_rest.hpp"
-#include "nlohmann/json.hpp"
#include <string>
-#include "gmock/gmock.h"
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
namespace crow
{
diff --git a/redfish-core/ut/hex_utils_test.cpp b/redfish-core/ut/hex_utils_test.cpp
index 506dc5a..8fd4638 100644
--- a/redfish-core/ut/hex_utils_test.cpp
+++ b/redfish-core/ut/hex_utils_test.cpp
@@ -1,7 +1,15 @@
#include "utils/hex_utils.hpp"
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
+#include <cctype>
+#include <limits>
+
+#include <gmock/gmock.h> // IWYU pragma: keep
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
namespace
{
diff --git a/redfish-core/ut/ip_utils_test.cpp b/redfish-core/ut/ip_utils_test.cpp
index c7d600b..f358c51 100644
--- a/redfish-core/ut/ip_utils_test.cpp
+++ b/redfish-core/ut/ip_utils_test.cpp
@@ -1,6 +1,10 @@
#include "utils/ip_utils.hpp"
-#include "gtest/gtest.h"
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
namespace redfish::ip_util
{
diff --git a/redfish-core/ut/json_utils_test.cpp b/redfish-core/ut/json_utils_test.cpp
index a284428..826d437 100644
--- a/redfish-core/ut/json_utils_test.cpp
+++ b/redfish-core/ut/json_utils_test.cpp
@@ -1,10 +1,23 @@
+#include "http_request.hpp"
+#include "http_response.hpp"
#include "utils/json_utils.hpp"
+#include <boost/beast/http/status.hpp>
+#include <nlohmann/json.hpp>
+
+#include <cstdint>
+#include <optional>
#include <string>
+#include <system_error>
#include <vector>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
+#include <gmock/gmock.h> // IWYU pragma: keep
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
+// IWYU pragma: no_include <boost/intrusive/detail/list_iterator.hpp>
namespace redfish::json_util
{
diff --git a/redfish-core/ut/lock_test.cpp b/redfish-core/ut/lock_test.cpp
index 5c0df1f..c27ba68 100644
--- a/redfish-core/ut/lock_test.cpp
+++ b/redfish-core/ut/lock_test.cpp
@@ -1,9 +1,19 @@
#include "ibm/locks.hpp"
+#include <cstdint>
+#include <memory>
#include <string>
+#include <tuple>
+#include <utility>
+#include <variant>
+#include <vector>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
+#include <gmock/gmock.h> // IWYU pragma: keep
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
namespace crow::ibm_mc_lock
{
diff --git a/redfish-core/ut/privileges_test.cpp b/redfish-core/ut/privileges_test.cpp
index c5a7a87..2d0da02 100644
--- a/redfish-core/ut/privileges_test.cpp
+++ b/redfish-core/ut/privileges_test.cpp
@@ -1,10 +1,17 @@
-#include "nlohmann/json.hpp"
#include "privileges.hpp"
-#include <fstream>
-#include <string>
+#include <boost/beast/http/verb.hpp>
-#include "gmock/gmock.h"
+#include <array>
+
+#include <gmock/gmock.h> // IWYU pragma: keep
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
+// IWYU pragma: no_include <gmock/gmock-matchers.h>
+// IWYU pragma: no_include <gmock/gmock-more-matchers.h>
namespace redfish
{
diff --git a/redfish-core/ut/registries_test.cpp b/redfish-core/ut/registries_test.cpp
index 758d8b3..87b92dc 100644
--- a/redfish-core/ut/registries_test.cpp
+++ b/redfish-core/ut/registries_test.cpp
@@ -1,6 +1,10 @@
#include "registries.hpp"
-#include "gmock/gmock.h"
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
namespace redfish::registries
{
diff --git a/redfish-core/ut/stl_utils_test.cpp b/redfish-core/ut/stl_utils_test.cpp
index 0c8e8c1..f1febd0 100644
--- a/redfish-core/ut/stl_utils_test.cpp
+++ b/redfish-core/ut/stl_utils_test.cpp
@@ -2,8 +2,12 @@
#include <string>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
+#include <gmock/gmock.h> // IWYU pragma: keep
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
namespace redfish::stl_utils
{
diff --git a/redfish-core/ut/time_utils_test.cpp b/redfish-core/ut/time_utils_test.cpp
index e97e9a7..e390fbd 100644
--- a/redfish-core/ut/time_utils_test.cpp
+++ b/redfish-core/ut/time_utils_test.cpp
@@ -1,6 +1,13 @@
#include "utils/time_utils.hpp"
-#include <gmock/gmock.h>
+#include <gmock/gmock.h> // IWYU pragma: keep
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+// IWYU pragma: no_include <gtest/gtest-message.h>
+// IWYU pragma: no_include <gtest/gtest-test-part.h>
+// IWYU pragma: no_include "gtest/gtest_pred_impl.h"
+// IWYU pragma: no_include <gmock/gmock-matchers.h>
+// IWYU pragma: no_include <gtest/gtest-matchers.h>
namespace redfish::time_utils
{