From 84cc43b0d2717da2c3c62e30dab71c50da15b682 Mon Sep 17 00:00:00 2001 From: Jonas Weich Date: Mon, 25 Nov 2024 20:38:57 +0100 Subject: [PATCH] fix: Potential race for file access in DotTest (#249) * Use unique filenames * Use system-agnostic temp directory --- test/graaflib/io/dot_test.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/graaflib/io/dot_test.cpp b/test/graaflib/io/dot_test.cpp index b93037ec..0d8d7098 100644 --- a/test/graaflib/io/dot_test.cpp +++ b/test/graaflib/io/dot_test.cpp @@ -74,7 +74,8 @@ inline std::pair make_sorted_pair( TEST(DotTest, EmptyUndirectedGraph) { // GIVEN - const std::filesystem::path path{"./test.dot"}; + const std::filesystem::path path{std::filesystem::temp_directory_path() / + "DotTest_EmptyUndirectedGraph.dot"}; undirected_graph graph{}; // WHEN @@ -87,7 +88,8 @@ TEST(DotTest, EmptyUndirectedGraph) { TEST(DotTest, EmptyDirectedGraph) { // GIVEN - const std::filesystem::path path{"./test.dot"}; + const std::filesystem::path path{std::filesystem::temp_directory_path() / + "DotTest_EmptyDirectedGraph.dot"}; directed_graph graph{}; // WHEN @@ -100,7 +102,8 @@ TEST(DotTest, EmptyDirectedGraph) { TEST(DotTest, UndirectedGraph) { // GIVEN - const std::filesystem::path path{"./test.dot"}; + const std::filesystem::path path{std::filesystem::temp_directory_path() / + "DotTest_UndirectedGraph.dot"}; undirected_graph graph{}; const auto vertex_1{graph.add_vertex(10)}; @@ -144,7 +147,8 @@ TEST(DotTest, UndirectedGraph) { TEST(DotTest, DirectedGraph) { // GIVEN - const std::filesystem::path path{"./test.dot"}; + const std::filesystem::path path{std::filesystem::temp_directory_path() / + "DotTest_DirectedGraph.dot"}; directed_graph graph{}; const auto vertex_1{graph.add_vertex(10)}; @@ -198,7 +202,9 @@ TEST(DotTest, UserProvidedVertexAndEdgeClass) { std::string string_data{}; }; - const std::filesystem::path path{"./test.dot"}; + const std::filesystem::path path{ + std::filesystem::temp_directory_path() / + "DotTest_UserProvidedVertexAndEdgeClass.dot"}; directed_graph graph{}; const auto vertex_1{graph.add_vertex(vertex_t{10, "vertex 1"})}; @@ -228,7 +234,8 @@ TEST(DotTest, UserProvidedVertexAndEdgeClass) { TEST(DotTest, DefaultWriters) { // GIVEN - const std::filesystem::path path{"./test.dot"}; + const std::filesystem::path path{std::filesystem::temp_directory_path() / + "DotTest_DefaultWriters.dot"}; directed_graph graph{}; const auto vertex_1{graph.add_vertex(10)};