Skip to content

Commit

Permalink
fix: Potential race for file access in DotTest (#249)
Browse files Browse the repository at this point in the history
* Use unique filenames
* Use system-agnostic temp directory
  • Loading branch information
joweich authored Nov 25, 2024
1 parent 4dbde3d commit 84cc43b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/graaflib/io/dot_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ inline std::pair<vertex_id_t, vertex_id_t> 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<int, int> graph{};

// WHEN
Expand All @@ -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<int, int> graph{};

// WHEN
Expand All @@ -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<int, int> graph{};

const auto vertex_1{graph.add_vertex(10)};
Expand Down Expand Up @@ -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<int, int> graph{};

const auto vertex_1{graph.add_vertex(10)};
Expand Down Expand Up @@ -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<vertex_t, edge_t> graph{};

const auto vertex_1{graph.add_vertex(vertex_t{10, "vertex 1"})};
Expand Down Expand Up @@ -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<int, float> graph{};

const auto vertex_1{graph.add_vertex(10)};
Expand Down

0 comments on commit 84cc43b

Please sign in to comment.