From a2d3b959db022b70552f8cdb5dc0571b6b63fe39 Mon Sep 17 00:00:00 2001 From: LTLA Date: Tue, 19 Nov 2024 10:26:51 -0800 Subject: [PATCH] Don't rely on byteme::temp_file_path to generate test file paths. It's simple enough to write ourselves so no need to incur a dependency on byteme's semi-internal testing functions. --- tests/src/check_collection_details.cpp | 5 ++--- tests/src/check_genes.cpp | 5 ++--- tests/src/check_indices.cpp | 7 +++---- tests/src/check_set_details.cpp | 5 ++--- tests/src/load_ranges.cpp | 13 ++++++------- tests/src/utils.h | 17 +++++++++++++++++ tests/src/validate_database.cpp | 9 ++++----- tests/src/validate_genes.cpp | 5 ++--- 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/tests/src/check_collection_details.cpp b/tests/src/check_collection_details.cpp index 1d6ef03..594f575 100644 --- a/tests/src/check_collection_details.cpp +++ b/tests/src/check_collection_details.cpp @@ -2,12 +2,11 @@ #include #include "gesel/check_collection_details.hpp" -#include "byteme/temp_file_path.hpp" #include "utils.h" TEST(CheckCollectionDetails, Success) { - auto path = byteme::temp_file_path("check_collections"); + auto path = temp_file_path("check_collections"); std::string payload1 = "aaron's collection\tthis is aaron's collection\t12345\tAaron Lun\thttps://aaron.net"; std::string payload2 = "yet another collection\tsomeone else's collection\t9999\tSomeone else\thttps://someone.else.com"; @@ -24,7 +23,7 @@ TEST(CheckCollectionDetails, Success) { } TEST(CheckCollectionDetails, Failure) { - auto path = byteme::temp_file_path("check_collections"); + auto path = temp_file_path("check_collections"); std::string payload1 = "aaron's collection\tthis is aaron's collection\t12345\tAaron Lun\thttps://aaron.net"; std::string payload2 = "yet another collection\tsomeone else's collection\t9999\tSomeone else\thttps://someone.else.com"; diff --git a/tests/src/check_genes.cpp b/tests/src/check_genes.cpp index 052429a..444e2fe 100644 --- a/tests/src/check_genes.cpp +++ b/tests/src/check_genes.cpp @@ -2,12 +2,11 @@ #include #include "gesel/check_genes.hpp" -#include "byteme/temp_file_path.hpp" #include "utils.h" TEST(CheckGenes, Success) { - auto path = byteme::temp_file_path("check_genes") + ".gz"; + auto path = temp_file_path("check_genes") + ".gz"; { byteme::GzipFileWriter gwriter(path); @@ -31,7 +30,7 @@ TEST(CheckGenes, Success) { } TEST(CheckGenes, Failure) { - auto path = byteme::temp_file_path("check_genes") + ".gz"; + auto path = temp_file_path("check_genes") + ".gz"; { byteme::GzipFileWriter gwriter(path); diff --git a/tests/src/check_indices.cpp b/tests/src/check_indices.cpp index db6539c..d1d77c9 100644 --- a/tests/src/check_indices.cpp +++ b/tests/src/check_indices.cpp @@ -2,7 +2,6 @@ #include #include "gesel/check_indices.hpp" -#include "byteme/temp_file_path.hpp" #include "utils.h" @@ -20,7 +19,7 @@ class TestCheckIndices : public ::testing::Test { }; TEST_F(TestCheckIndices, Success) { - auto path = byteme::temp_file_path("check_indices"); + auto path = temp_file_path("check_indices"); std::string payload = "0\t123\t45\n6\n780\t1\t234\t45\n\n67\t890\n"; { @@ -61,7 +60,7 @@ TEST_F(TestCheckIndices, Success) { } TEST_F(TestCheckIndices, RawFailure) { - auto path = byteme::temp_file_path("check_indices"); + auto path = temp_file_path("check_indices"); // Basic checks for correct integer parsing. { @@ -137,7 +136,7 @@ TEST_F(TestCheckIndices, RawFailure) { } TEST_F(TestCheckIndices, GzipFailure) { - auto path = byteme::temp_file_path("check_indices"); + auto path = temp_file_path("check_indices"); { byteme::RawFileWriter rwriter(path); diff --git a/tests/src/check_set_details.cpp b/tests/src/check_set_details.cpp index 6d28ad0..b447cd7 100644 --- a/tests/src/check_set_details.cpp +++ b/tests/src/check_set_details.cpp @@ -2,7 +2,6 @@ #include #include "gesel/check_set_details.hpp" -#include "byteme/temp_file_path.hpp" #include "utils.h" @@ -14,7 +13,7 @@ class TestCheckSetDetails : public ::testing::Test { }; TEST_F(TestCheckSetDetails, Success) { - auto path = byteme::temp_file_path("check_sets"); + auto path = temp_file_path("check_sets"); std::string payload1 = "aaron's set\tthis is aaron's set"; std::string payload2 = "another set\tyet another set"; @@ -31,7 +30,7 @@ TEST_F(TestCheckSetDetails, Success) { } TEST_F(TestCheckSetDetails, Failure) { - auto path = byteme::temp_file_path("check_sets"); + auto path = temp_file_path("check_sets"); std::string payload1 = "aaron's set\tthis is aaron's set"; std::string payload2 = "another set\tyet another set"; diff --git a/tests/src/load_ranges.cpp b/tests/src/load_ranges.cpp index bb443eb..7769fce 100644 --- a/tests/src/load_ranges.cpp +++ b/tests/src/load_ranges.cpp @@ -2,12 +2,11 @@ #include #include "gesel/load_ranges.hpp" -#include "byteme/temp_file_path.hpp" #include "utils.h" TEST(LoadRanges, Success) { - auto path = byteme::temp_file_path("load_ranges"); + auto path = temp_file_path("load_ranges"); { { @@ -33,7 +32,7 @@ TEST(LoadRanges, Success) { } TEST(LoadRanges, Failure) { - auto path = byteme::temp_file_path("load_ranges"); + auto path = temp_file_path("load_ranges"); { byteme::GzipFileWriter writer(path); @@ -79,7 +78,7 @@ TEST(LoadRanges, Failure) { } TEST(LoadRangesWithSizes, Success) { - auto path = byteme::temp_file_path("load_ranges_with_sizes"); + auto path = temp_file_path("load_ranges_with_sizes"); { byteme::GzipFileWriter writer(path); @@ -94,7 +93,7 @@ TEST(LoadRangesWithSizes, Success) { } TEST(LoadRangesWithSizes, Failure) { - auto path = byteme::temp_file_path("load_ranges_with_sizes"); + auto path = temp_file_path("load_ranges_with_sizes"); { byteme::GzipFileWriter writer(path); @@ -118,7 +117,7 @@ TEST(LoadRangesWithSizes, Failure) { } TEST(LoadNamedRanges, Success) { - auto path = byteme::temp_file_path("load_named_ranges"); + auto path = temp_file_path("load_named_ranges"); { byteme::GzipFileWriter writer(path); @@ -133,7 +132,7 @@ TEST(LoadNamedRanges, Success) { } TEST(LoadNamedRanges, Failure) { - auto path = byteme::temp_file_path("load_named_ranges"); + auto path = temp_file_path("load_named_ranges"); { byteme::GzipFileWriter writer(path); diff --git a/tests/src/utils.h b/tests/src/utils.h index 3e48513..7f17cbd 100644 --- a/tests/src/utils.h +++ b/tests/src/utils.h @@ -3,6 +3,8 @@ #include #include +#include +#include template void expect_error(Function_ fun, std::string match) { @@ -20,4 +22,19 @@ void expect_error(Function_ fun, std::string match) { ASSERT_TRUE(msg.find(match) != std::string::npos) << "function did not throw an exception with message '" << match << "' (got '" << msg << "' instead)"; } +inline std::string temp_file_path(const std::string& base) { + auto tmpdir = std::filesystem::temp_directory_path(); + auto prefix = tmpdir / base; + std::filesystem::path full; + + std::random_device rd; + std::mt19937_64 rng(rd()); + do { + full = prefix; + full += std::to_string(rng()); + } while (std::filesystem::exists(full)); + + return full; +} + #endif diff --git a/tests/src/validate_database.cpp b/tests/src/validate_database.cpp index 23377ce..b5440c3 100644 --- a/tests/src/validate_database.cpp +++ b/tests/src/validate_database.cpp @@ -7,7 +7,6 @@ #include #include -#include "byteme/temp_file_path.hpp" #include "gesel/validate_database.hpp" #include "utils.h" @@ -181,13 +180,13 @@ class TestValidateDatabase : public ::testing::Test { }; TEST_F(TestValidateDatabase, Basic) { - auto path = byteme::temp_file_path("validation"); + auto path = temp_file_path("validation"); mock_database(path, "9606_"); gesel::validate_database(path + "/9606_", max_genes); } TEST_F(TestValidateDatabase, CollectionFailures) { - auto path = byteme::temp_file_path("validation"); + auto path = temp_file_path("validation"); mock_database(path, "9606_"); // Verify that the collections are indeed checked. @@ -214,7 +213,7 @@ TEST_F(TestValidateDatabase, CollectionFailures) { } TEST_F(TestValidateDatabase, SetFailures) { - auto path = byteme::temp_file_path("validation"); + auto path = temp_file_path("validation"); mock_database(path, "9606_"); { @@ -299,7 +298,7 @@ TEST_F(TestValidateDatabase, SetFailures) { } TEST_F(TestValidateDatabase, SetToGeneFailures) { - auto path = byteme::temp_file_path("validation"); + auto path = temp_file_path("validation"); mock_database(path, "9606_"); { diff --git a/tests/src/validate_genes.cpp b/tests/src/validate_genes.cpp index 4d9becc..1540568 100644 --- a/tests/src/validate_genes.cpp +++ b/tests/src/validate_genes.cpp @@ -5,12 +5,11 @@ #include #include -#include "byteme/temp_file_path.hpp" #include "gesel/validate_genes.hpp" #include "utils.h" TEST(ValidateGenes, Basic) { - auto path = byteme::temp_file_path("validation"); + auto path = temp_file_path("validation"); if (std::filesystem::exists(path)) { std::filesystem::remove_all(path); } @@ -26,7 +25,7 @@ TEST(ValidateGenes, Basic) { } TEST(ValidateGenes, Failure) { - auto path = byteme::temp_file_path("validation"); + auto path = temp_file_path("validation"); if (std::filesystem::exists(path)) { std::filesystem::remove_all(path); }