@@ -98,12 +98,20 @@ TEST_F(test_file, read_non_existing_file) {
98
98
std::string temp_file_path =
99
99
this ->make_temporary_directory () + " /does-not-exist.js" ;
100
100
101
- read_file_result file_content = read_file (temp_file_path.c_str ());
102
- EXPECT_FALSE (file_content.ok ());
103
- EXPECT_TRUE (file_content.is_not_found_error );
104
- EXPECT_THAT (file_content.error , HasSubstr (" does-not-exist.js" ));
105
- EXPECT_THAT (file_content.error ,
106
- AnyOf (HasSubstr (" No such file" ), HasSubstr (" cannot find" )));
101
+ boost::leaf::try_handle_all (
102
+ [&]() -> boost::leaf::result<void > {
103
+ boost::leaf::result<padded_string> file_content =
104
+ read_file_2 (temp_file_path.c_str ());
105
+ if (!file_content) return file_content.error ();
106
+ ADD_FAILURE () << " read_file_2 should have failed" ;
107
+ return {};
108
+ },
109
+ make_file_not_found_handler ([] {
110
+ // Test passed.
111
+ }),
112
+ make_read_file_error_handlers ([](const std::string& message) {
113
+ ADD_FAILURE () << " expected file-not-found error, but got: " << message;
114
+ }));
107
115
}
108
116
109
117
TEST_F (test_file, read_non_existing_file_sloppy_message) {
@@ -121,16 +129,19 @@ TEST_F(test_file, read_non_existing_file_sloppy_message) {
121
129
TEST_F (test_file, read_directory) {
122
130
std::string temp_file_path = this ->make_temporary_directory ();
123
131
124
- read_file_result file_content = read_file (temp_file_path.c_str ());
125
- EXPECT_FALSE (file_content.ok ());
126
- EXPECT_FALSE (file_content.is_not_found_error );
127
- EXPECT_THAT (file_content.error , HasSubstr (temp_file_path));
128
- EXPECT_THAT (
129
- file_content.error ,
130
- testing::AnyOf (
131
- HasSubstr (" Is a directory" ),
132
- HasSubstr (" Access is denied" ) // TODO(strager): Improve this message.
133
- ));
132
+ boost::leaf::try_handle_all (
133
+ [&]() -> boost::leaf::result<void > {
134
+ boost::leaf::result<padded_string> file_content =
135
+ read_file_2 (temp_file_path.c_str ());
136
+ if (!file_content) return file_content.error ();
137
+ ADD_FAILURE () << " read_file_2 should have failed" ;
138
+ return {};
139
+ },
140
+ make_file_not_found_handler (
141
+ [] { ADD_FAILURE () << " expected not file-not-found error" ; }),
142
+ make_read_file_error_handlers ([](const std::string&) {
143
+ // Test passed.
144
+ }));
134
145
}
135
146
136
147
TEST_F (test_file, read_directory_sloppy_message) {
0 commit comments