Skip to content

Commit

Permalink
Stop relying on byteme::temp_file_path for tests.
Browse files Browse the repository at this point in the history
It's simple enough to write ourselves so there's no need to incur a dependency
on byteme's semi-internal testing functions.
  • Loading branch information
LTLA committed Dec 1, 2024
1 parent 0f9a19f commit d8aeccf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tests/src/from_gzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/src/from_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions tests/src/temp_file_path.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef TEMP_FILE_PATH_H
#define TEMP_FILE_PATH_H

#include <filesystem>
#include <random>
#include <string>

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

0 comments on commit d8aeccf

Please sign in to comment.