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 8b2e57d commit b3a3f20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/src/load_matrix.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <gtest/gtest.h>

#include "byteme/byteme.hpp"
#include "byteme/temp_file_path.hpp"
#include "eminem/eminem.hpp"
#include "tatami_test/tatami_test.hpp"

#include "tatami_mtx/tatami_mtx.hpp"
#include "temp_file_path.h"

#include <limits>
#include <fstream>
Expand Down Expand Up @@ -142,7 +142,7 @@ TEST_F(LoadMatrixInputTest, SimpleBuffer) {
TEST_F(LoadMatrixInputTest, SimpleText) {
initialize(100, 99, 59);

auto path = byteme::temp_file_path("tatami-tests-ext-MatrixMarket", ".mtx");
auto path = temp_file_path("tatami-tests-ext-MatrixMarket");
byteme::RawFileWriter writer(path.c_str());
write_coordinate(writer);

Expand Down Expand Up @@ -201,7 +201,7 @@ TEST_F(LoadMatrixInputTest, ZlibBuffer) {
TEST_F(LoadMatrixInputTest, GzipFile) {
initialize(102, 200, 100);

auto path = byteme::temp_file_path("tatami-tests-ext-MatrixMarket", ".mtx.gz");
auto path = temp_file_path("tatami-tests-ext-MatrixMarket");
byteme::GzipFileWriter writer(path.c_str());
write_coordinate(writer);

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 b3a3f20

Please sign in to comment.