From: Magnus Jacobsson Date: Sun, 18 Sep 2022 09:56:44 +0000 (+0200) Subject: tests: add AUTO_NAME macro and use it in the test_edge_node_overlap_simple test X-Git-Tag: 6.0.2~34^2~19 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9aeb969698f733e4af2bb8ee4c8ed7db25e97493;p=graphviz tests: add AUTO_NAME macro and use it in the test_edge_node_overlap_simple test This ensures that the generated artifact file names begin with the same name as the test case file (thanks @smattr). --- diff --git a/tests/test_edge_node_overlap_simple.cpp b/tests/test_edge_node_overlap_simple.cpp index 90a2f9c74..78321fac2 100644 --- a/tests/test_edge_node_overlap_simple.cpp +++ b/tests/test_edge_node_overlap_simple.cpp @@ -3,6 +3,7 @@ #include #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}); } diff --git a/tests/test_utilities.h b/tests/test_utilities.h index b051f8a62..4a7cddd7c 100644 --- a/tests/test_utilities.h +++ b/tests/test_utilities.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include #include @@ -38,6 +40,13 @@ extern const std::unordered_set 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);