clang-tidy:test suppress self-move warning
This test intentionally performs a self-move assignment to observe
how the FileDescriptor class handles such cases. While this is
undefined behavior in C++, the warning is suppressed locally using
Clang diagnostic pragmas to allow the test to compile and run.
Change-Id: I4213d23fcb41afc5d4af9c5f1b2b36f9ffb06d7c
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/test/file_descriptor_tests.cpp b/test/file_descriptor_tests.cpp
index ad63dd7..c13699e 100644
--- a/test/file_descriptor_tests.cpp
+++ b/test/file_descriptor_tests.cpp
@@ -130,8 +130,17 @@
EXPECT_EQ(descriptor(), fd);
EXPECT_TRUE(isValid(fd));
+// This is undefined behavior in C++, but suppress the warning
+// to observe how the class handles it.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wself-move"
+#endif
// Try to move object into itself
descriptor = static_cast<FileDescriptor&&>(descriptor);
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
// Verify object still contains file descriptor
EXPECT_EQ(descriptor(), fd);
diff --git a/test/temporary_file_tests.cpp b/test/temporary_file_tests.cpp
index 9eafa56..5f2bb29 100644
--- a/test/temporary_file_tests.cpp
+++ b/test/temporary_file_tests.cpp
@@ -149,8 +149,17 @@
// Save path to temporary file
fs::path path = file.getPath();
+// This is undefined behavior in C++, butsuppress the warning
+// to observe how the class handles it
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wself-move"
+#endif
// Try to move object into itself; should do nothing
file = static_cast<TemporaryFile&&>(file);
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
// Verify object still owns same temporary file and file exists
EXPECT_EQ(file.getPath(), path);
diff --git a/test/temporary_subdirectory_tests.cpp b/test/temporary_subdirectory_tests.cpp
index 0b0188f..6046382 100644
--- a/test/temporary_subdirectory_tests.cpp
+++ b/test/temporary_subdirectory_tests.cpp
@@ -110,8 +110,17 @@
// Save path to subdirectory
fs::path path = subdirectory.getPath();
+// This is undefined behavior in C++, but suppress the warning
+// to observe how the class handles it.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wself-move"
+#endif
// Try to move object into itself; should do nothing
subdirectory = static_cast<TemporarySubDirectory&&>(subdirectory);
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
// Verify object still owns same subdirectory and subdirectory exists
EXPECT_EQ(subdirectory.getPath(), path);