diff --git a/tests/src/from_gzip.cpp b/tests/src/from_gzip.cpp index 096bc21..d10250b 100644 --- a/tests/src/from_gzip.cpp +++ b/tests/src/from_gzip.cpp @@ -2,8 +2,8 @@ #include "eminem/from_text.hpp" #include "eminem/from_gzip.hpp" -#include "byteme/temp_file_path.hpp" +#include "temp_file_path.h" #include "simulate.h" #include "format.h" @@ -18,7 +18,7 @@ TEST(FromGzip, File) { auto coords = simulate_coordinate(NR, NC, 0.1); auto values = simulate_integer(coords.first.size(), -999, 999); - auto path = byteme::temp_file_path("file", ".mtx.gz"); + auto path = temp_file_path("gzipped"); { std::stringstream stored; format_coordinate(stored, NR, NC, coords.first, coords.second, values); @@ -85,7 +85,7 @@ TEST(FromGzip, Buffer) { stored << "\n"; // add an extra newline. auto contents = stored.str(); - auto path = byteme::temp_file_path("buffer", ".mtx.gz"); + auto path = temp_file_path("gzipped_buffer"); gzFile ohandle = gzopen(path.c_str(), "w"); gzwrite(ohandle, contents.data(), contents.size()); gzclose(ohandle); diff --git a/tests/src/from_text.cpp b/tests/src/from_text.cpp index 498d782..829f184 100644 --- a/tests/src/from_text.cpp +++ b/tests/src/from_text.cpp @@ -2,8 +2,8 @@ #include "eminem/from_text.hpp" #include "eminem/from_gzip.hpp" -#include "byteme/temp_file_path.hpp" +#include "temp_file_path.h" #include "simulate.h" #include "format.h" @@ -18,7 +18,7 @@ TEST(FromText, File) { auto coords = simulate_coordinate(NR, NC, 0.1); auto values = simulate_integer(coords.first.size(), -999, 999); - auto path = byteme::temp_file_path("file", ".mtx"); + auto path = temp_file_path("text"); { std::ofstream stored(path); format_coordinate(stored, NR, NC, coords.first, coords.second, values); diff --git a/tests/src/temp_file_path.h b/tests/src/temp_file_path.h new file mode 100644 index 0000000..6e7d629 --- /dev/null +++ b/tests/src/temp_file_path.h @@ -0,0 +1,23 @@ +#ifndef TEMP_FILE_PATH_H +#define TEMP_FILE_PATH_H + +#include +#include +#include + +inline std::string temp_file_path(const std::string& prefix) { + auto path = std::filesystem::temp_directory_path(); + path.append(prefix); + + std::random_device rd; + std::mt19937_64 rng(rd()); + std::filesystem::path full; + do { + full = path; + full += std::to_string(rng()); + } while (std::filesystem::exists(full)); + + return full; +} + +#endif