From 0ca053872a5bb864eccb3d2c9ef2c9ea4c67e13a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Wed, 10 Nov 2021 18:01:18 +0100
Subject: [PATCH] Change location of generated files to PUGS_BINARY_DIR/tests/

The use of the temp dir (/tmp) could be problematic when running
several test bases at same time (different builds).
---
 tests/mpi_test_main.cpp                        | 4 ++--
 tests/test_BinaryExpressionProcessor_raw.cpp   | 5 +++--
 tests/test_BinaryExpressionProcessor_shift.cpp | 6 +++---
 tests/test_OFStream.cpp                        | 2 +-
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/tests/mpi_test_main.cpp b/tests/mpi_test_main.cpp
index 4c9463417..3f195f2ec 100644
--- a/tests/mpi_test_main.cpp
+++ b/tests/mpi_test_main.cpp
@@ -27,7 +27,7 @@ main(int argc, char* argv[])
 
   const std::string output_base_name{"mpi_test_rank_"};
 
-  std::filesystem::path parallel_output(std::string{PUGS_BINARY_DIR});
+  std::filesystem::path parallel_output = std::filesystem::path{PUGS_BINARY_DIR}.append("tests");
 
   std::filesystem::path gcov_prefix = [&]() -> std::filesystem::path {
     std::string template_temp_dir = std::filesystem::temp_directory_path() / "pugs_gcov_XXXXXX";
@@ -71,7 +71,7 @@ main(int argc, char* argv[])
                                     << rang::style::reset << '\n';
 
           for (size_t i_rank = 1; i_rank < parallel::size(); ++i_rank) {
-            std::filesystem::path parallel_output(std::string{PUGS_BINARY_DIR});
+            std::filesystem::path parallel_output = std::filesystem::path{PUGS_BINARY_DIR}.append("tests");
             parallel_output /= output_base_name + std::to_string(i_rank);
             session.config().stream() << " - " << rang::fg::green << parallel_output.parent_path().string()
                                       << parallel_output.preferred_separator << rang::style::reset << rang::fgB::green
diff --git a/tests/test_BinaryExpressionProcessor_raw.cpp b/tests/test_BinaryExpressionProcessor_raw.cpp
index c115c67ca..22e32de89 100644
--- a/tests/test_BinaryExpressionProcessor_raw.cpp
+++ b/tests/test_BinaryExpressionProcessor_raw.cpp
@@ -3,6 +3,7 @@
 
 #include <language/node_processor/BinaryExpressionProcessor.hpp>
 #include <language/utils/OFStream.hpp>
+#include <utils/pugs_config.hpp>
 
 // clazy:excludeall=non-pod-global-static
 
@@ -51,8 +52,8 @@ TEST_CASE("BinaryExpressionProcessor raw operators", "[language]")
   REQUIRE(BinOp<language::divide_op>{}.eval(2.9, 3) == (2.9 / 3));
 
   {
-    std::filesystem::path path = std::filesystem::temp_directory_path();
-    path.append(std::string{"binary_expression_processor_shift_left_"} + std::to_string(getpid()));
+    std::filesystem::path path{PUGS_BINARY_DIR};
+    path.append("tests").append(std::string{"binary_expression_processor_shift_left_"} + std::to_string(getpid()));
 
     std::string filename = path.string();
 
diff --git a/tests/test_BinaryExpressionProcessor_shift.cpp b/tests/test_BinaryExpressionProcessor_shift.cpp
index 082d5fc5e..2f89f1f61 100644
--- a/tests/test_BinaryExpressionProcessor_shift.cpp
+++ b/tests/test_BinaryExpressionProcessor_shift.cpp
@@ -2,6 +2,7 @@
 #include <catch2/matchers/catch_matchers_all.hpp>
 
 #include <test_BinaryExpressionProcessor_utils.hpp>
+#include <utils/pugs_config.hpp>
 
 #include <fstream>
 #include <unistd.h>
@@ -12,9 +13,8 @@ TEST_CASE("BinaryExpressionProcessor shift", "[language]")
 {
   SECTION("<<")
   {
-    std::filesystem::path path = std::filesystem::temp_directory_path();
-
-    path.append(std::string{"binary_expression_processor_"} + std::to_string(getpid()));
+    std::filesystem::path path{PUGS_BINARY_DIR};
+    path.append("tests").append(std::string{"binary_expression_processor_"} + std::to_string(getpid()));
 
     std::string filename = path.string();
 
diff --git a/tests/test_OFStream.cpp b/tests/test_OFStream.cpp
index 5ca9c38fd..edcee2975 100644
--- a/tests/test_OFStream.cpp
+++ b/tests/test_OFStream.cpp
@@ -12,7 +12,7 @@ TEST_CASE("OFStream", "[language]")
 {
   SECTION("ofstream")
   {
-    const std::string basename = std::filesystem::temp_directory_path().append("ofstream_");
+    const std::string basename = std::filesystem::path{PUGS_BINARY_DIR}.append("tests").append("ofstream_");
     const std::string filename = basename + std::to_string(parallel::rank());
 
     // Ensures that the file is closed after this line
-- 
GitLab