#include "svg_analyzer.h"
#include "test_edge_node_overlap_utilities.h"
+#include "test_utilities.h"
/// check that edges do not overlap nodes
static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer,
return success;
}
-void test_edge_node_overlap(const std::string &dot) {
+/// write SVG files for manual analysis if any of the above checks failed or if
+/// we explicitly have requested it
+static void write_svg_files(const SVGAnalyzer &svg_analyzer,
+ const write_options &write_options) {
+ const std::filesystem::path test_artifacts_directory = "test_artifacts";
+
+ if (write_options.write_original_svg) {
+ // write the original SVG generated by Graphviz to a file
+ const std::filesystem::path filename =
+ write_options.filename_base + "_original.svg";
+ write_to_file(test_artifacts_directory, filename,
+ svg_analyzer.original_svg());
+ }
+
+ if (write_options.write_recreated_svg) {
+ // write the SVG recreated by the SVG analyzer to a file
+ const std::filesystem::path filename =
+ write_options.filename_base + "_recreated.svg";
+ const auto recreated_svg = svg_analyzer.svg_string();
+ write_to_file(test_artifacts_directory, filename, recreated_svg);
+ }
+}
+
+void test_edge_node_overlap(const std::string &dot,
+ const write_options &write_options) {
auto svg_analyzer = SVGAnalyzer::make_from_dot(dot);
// The binary search in the bezier_clip function in lib/common/splines.c has a
const auto success = check_analyzed_svg(svg_analyzer, check_options);
- // FIXME: add writing of SVG files for manual inspection when not success
- REQUIRE(success);
+ if (!success || write_options.write_svg_on_success) {
+ write_svg_files(svg_analyzer, write_options);
+ }
}
double svg_rounding_error;
};
+struct write_options {
+ std::string filename_base = "test_edge_node_overlap";
+ bool write_svg_on_success = false;
+ bool write_original_svg = false;
+ bool write_recreated_svg = true;
+};
+
/// generate an SVG graph from the `dot` source and check that edges don't
/// overlap nodes
-void test_edge_node_overlap(const std::string &dot);
+void test_edge_node_overlap(const std::string &dot,
+ const write_options &write_options = {});
+#include <filesystem>
+#include <fstream>
+#include <stdexcept>
#include <string_view>
#include <unordered_set>
+#include <fmt/format.h>
+
#include "test_utilities.h"
const std::unordered_set<std::string_view> node_shapes_consisting_of_ellipse = {
const std::unordered_set<std::string_view> all_rank_directions = {"TB", "BT",
"LR", "RL"};
+void write_to_file(const std::filesystem::path &directory,
+ const std::filesystem::path &filename,
+ const std::string_view text) {
+ std::filesystem::create_directories(directory);
+ const std::filesystem::path test_artifacts_path = directory / filename;
+ std::ofstream outfile{test_artifacts_path};
+ if (!outfile.is_open()) {
+ throw std::runtime_error{fmt::format("Could not create output file \"{}\"",
+ test_artifacts_path.native())};
+ }
+ outfile << text;
+}