// Throws Error on error.
void wipe_path(const std::string& path);
-// Write file data from a string. The file will be opened according to
-// `open_mode`, which always will include `std::ios::out` even if not specified
-// at the call site.
+// Write `data` to `path`. The file will be opened according to `open_mode`,
+// which always will include `std::ios::out` even if not specified at the call
+// site.
//
// Throws `Error` on error. The description contains the error message without
// the path.
void write_file(const std::string& path,
const std::string& data,
- std::ios_base::openmode open_mode = std::ios::out);
+ std::ios_base::openmode open_mode = std::ios::binary);
} // namespace Util
data = Util::read_file("test");
CHECK(data == "carpet");
+ Util::write_file("test", "\n", std::ios::app | std::ios::binary);
+ data = Util::read_file("test");
+ CHECK(data == "carpet\n");
+
+ Util::write_file("test", "\n", std::ios::app); // text mode
+ data = Util::read_file("test");
+#ifdef _WIN32
+ CHECK(data == "carpet\n\r\n");
+#else
+ CHECK(data == "carpet\n\n");
+#endif
CHECK_THROWS_WITH(Util::read_file("does/not/exist"),
"No such file or directory");