tests: add AUTO_NAME macro and use it in the test_edge_node_overlap_simple test
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Sun, 18 Sep 2022 09:56:44 +0000 (11:56 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 20 Sep 2022 15:53:06 +0000 (17:53 +0200)
This ensures that the generated artifact file names begin with the
same name as the test case file (thanks @smattr).

tests/test_edge_node_overlap_simple.cpp
tests/test_utilities.h

index 90a2f9c74de267a46d90b5a500d5ca3eb119ac63..78321fac22cfd197293dc230ef525628b6dda477 100644 (file)
@@ -3,6 +3,7 @@
 #include <catch2/catch.hpp>
 
 #include "test_edge_node_overlap_utilities.h"
+#include "test_utilities.h"
 
 TEST_CASE(
     "Overlap",
@@ -11,5 +12,7 @@ TEST_CASE(
   std::string dot =
       "digraph {node[shape=polygon penwidth=2 fontname=Courier] a -> b}";
 
-  test_edge_node_overlap(dot);
+  const auto filename_base = AUTO_NAME();
+
+  test_edge_node_overlap(dot, {.filename_base = filename_base});
 }
index b051f8a62add7f35bb5d76d4c3cc730d042d43ae..4a7cddd7c73e113520117ab92588aa48ddad8558 100644 (file)
@@ -1,6 +1,8 @@
 #pragma once
 
 #include <filesystem>
+#include <string.h>
+#include <string>
 #include <string_view>
 #include <unordered_set>
 
@@ -38,6 +40,13 @@ extern const std::unordered_set<std::string_view> all_rank_directions;
 
 /// misc utilities
 
+/// get the base name of the test case file without file extension
+#define AUTO_NAME()                                                            \
+  ({                                                                           \
+    std::string s_{strrchr(__FILE__, '/')};                                    \
+    s_.substr(1, s_.rfind('.') - 1);                                           \
+  })
+
 void write_to_file(const std::filesystem::path &directory,
                    const std::filesystem::path &filename,
                    std::string_view text);