File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -205,8 +205,11 @@ read_file_result read_file(const char *path) {
205
205
/* hTemplateFile=*/ nullptr );
206
206
if (handle == INVALID_HANDLE_VALUE) {
207
207
DWORD error = ::GetLastError ();
208
- return read_file_result::failure (std::string (" failed to open " ) + path +
209
- " : " + windows_error_message (error));
208
+ read_file_result result =
209
+ read_file_result::failure (std::string (" failed to open " ) + path + " : " +
210
+ windows_error_message (error));
211
+ result.is_not_found_error = error == ERROR_FILE_NOT_FOUND;
212
+ return result;
210
213
}
211
214
windows_handle_file file (handle);
212
215
return read_file (path, file.ref ());
@@ -223,8 +226,10 @@ read_file_result read_file(const char *path) {
223
226
int fd = ::open (path, O_CLOEXEC | O_RDONLY);
224
227
if (fd == -1 ) {
225
228
int error = errno;
226
- return read_file_result::failure (std::string (" failed to open " ) + path +
227
- " : " + std::strerror (error));
229
+ read_file_result result = read_file_result::failure (
230
+ std::string (" failed to open " ) + path + " : " + std::strerror (error));
231
+ result.is_not_found_error = error == ENOENT;
232
+ return result;
228
233
}
229
234
posix_fd_file file (fd);
230
235
return read_file (path, file.ref ());
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ namespace quick_lint_js {
13
13
struct read_file_result {
14
14
padded_string content;
15
15
std::string error;
16
+ bool is_not_found_error = false ;
16
17
17
18
bool ok () const noexcept { return this ->error .empty (); }
18
19
void exit_if_not_ok () const ;
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ TEST_F(test_file, read_non_existing_file) {
71
71
72
72
read_file_result file_content = read_file (temp_file_path.c_str ());
73
73
EXPECT_FALSE (file_content.ok ());
74
+ EXPECT_TRUE (file_content.is_not_found_error );
74
75
EXPECT_THAT (file_content.error , HasSubstr (" does-not-exist.js" ));
75
76
EXPECT_THAT (file_content.error ,
76
77
AnyOf (HasSubstr (" No such file" ), HasSubstr (" cannot find" )));
@@ -81,6 +82,7 @@ TEST_F(test_file, read_directory) {
81
82
82
83
read_file_result file_content = read_file (temp_file_path.c_str ());
83
84
EXPECT_FALSE (file_content.ok ());
85
+ EXPECT_FALSE (file_content.is_not_found_error );
84
86
EXPECT_THAT (
85
87
file_content.error ,
86
88
testing::AnyOf (
You can’t perform that action at this time.
0 commit comments