[llvm] [Support] Report EISDIR when opening a directory (PR #79880)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 01:05:29 PDT 2024
================
@@ -1296,6 +1296,36 @@ TEST_F(FileSystemTest, UTF8ToUTF16DirectoryIteration) {
}
#endif
+#ifndef _WIN32
+TEST_F(FileSystemTest, OpenDirectoryAsFileForRead) {
+ ASSERT_NO_ERROR(fs::create_directory(Twine(TestDirectory)));
+ ASSERT_EQ(fs::create_directory(Twine(TestDirectory), false),
+ errc::file_exists);
+
+ std::string Buf(5, '?');
+ Expected<fs::file_t> FD = fs::openNativeFileForRead(TestDirectory);
+ ASSERT_NO_ERROR(errorToErrorCode(FD.takeError()));
----------------
jh7370 wrote:
This test fails on Windows here, because on Windows even attempting to opene the directory for read fails, so the `ASSERT_NO_ERROR` fires.
Side note: `ASSERT_NO_ERROR(errorToErrorCode(FD.takeError()));` can be simplified to `ASSERT_THAT_EXPECTED(FD, Succeeded());`. There are similar ones if you just want to check whether it failed with a particular message, for example (but in that case you wouldn't be able to check the actual value).
To fix this on Windows simply replace the `ASSERT_NO_ERROR` check with a check to make sure the returned error is in a failed state with the `is_directory` value (then skip the rest of the test).
https://github.com/llvm/llvm-project/pull/79880
More information about the llvm-commits
mailing list