diff options
author | jaseg <git@jaseg.de> | 2021-06-05 23:33:44 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2021-06-05 23:33:44 +0200 |
commit | 4ffb4c65825ab0a5ded00ff799b494097e7bd143 (patch) | |
tree | 68791213543bd330a094c67469a1de745c36867a /svg-flatten/src/test | |
parent | f2f0ac241672bbaac4ccb9eaa369c501951de949 (diff) | |
download | gerbolyze-4ffb4c65825ab0a5ded00ff799b494097e7bd143.tar.gz gerbolyze-4ffb4c65825ab0a5ded00ff799b494097e7bd143.tar.bz2 gerbolyze-4ffb4c65825ab0a5ded00ff799b494097e7bd143.zip |
Make svg-flatten auto-search for cargo dependencies in all call sites
Diffstat (limited to 'svg-flatten/src/test')
-rw-r--r-- | svg-flatten/src/test/nopencv_test.cpp | 21 | ||||
-rw-r--r-- | svg-flatten/src/test/svg_tests.py | 14 |
2 files changed, 15 insertions, 20 deletions
diff --git a/svg-flatten/src/test/nopencv_test.cpp b/svg-flatten/src/test/nopencv_test.cpp index e4cc078..13be6f8 100644 --- a/svg-flatten/src/test/nopencv_test.cpp +++ b/svg-flatten/src/test/nopencv_test.cpp @@ -5,6 +5,7 @@ #include <cmath> #include <filesystem> +#include "util.h" #include "nopencv.hpp" #include <subprocess.h> @@ -158,24 +159,8 @@ MU_TEST(test_complex_example_from_paper) { } int render_svg(const char *in_svg, const char *out_png) { - const char *command_line[] = {"resvg", in_svg, out_png, nullptr}; - struct subprocess_s subprocess; - int rc = subprocess_create(command_line, subprocess_option_inherit_environment, &subprocess); - if (rc) - return rc; - - int resvg_rc = -1; - rc = subprocess_join(&subprocess, &resvg_rc); - if (rc) - return rc; - if (resvg_rc) - return -resvg_rc; - - rc = subprocess_destroy(&subprocess); - if (rc) - return rc; - - return 0; + const char *command_line[] = {nullptr, in_svg, out_png, nullptr}; + return run_cargo_command("resvg", command_line, "RESVG"); } static void testdata_roundtrip(const char *fn) { diff --git a/svg-flatten/src/test/svg_tests.py b/svg-flatten/src/test/svg_tests.py index f98e367..c2e5d50 100644 --- a/svg-flatten/src/test/svg_tests.py +++ b/svg-flatten/src/test/svg_tests.py @@ -39,6 +39,16 @@ def run_svg_flatten(input_file, output_file, *args, **kwargs): print(proc.stderr) raise +def run_cargo_cmd(cmd, args, **kwargs): + if cmd.upper() in os.environ: + return subprocess.run([os.environ[cmd.upper()], *args], **kwargs) + + try: + return subprocess.run([cmd, *args], **kwargs) + + except FileNotFoundError: + return subprocess.run([str(Path.home() / '.cargo' / 'bin' / cmd), *args], **kwargs) + class SVGRoundTripTests(unittest.TestCase): # Notes on test cases: @@ -131,8 +141,8 @@ class SVGRoundTripTests(unittest.TestCase): vectorizer='binary-contours') if not use_rsvg: # default! - subprocess.run(['resvg', tmp_out_svg.name, tmp_out_png.name], check=True, stdout=subprocess.DEVNULL) - subprocess.run(['resvg', test_in_svg, tmp_in_png.name], check=True, stdout=subprocess.DEVNULL) + run_cargo_cmd('resvg', [tmp_out_svg.name, tmp_out_png.name], check=True, stdout=subprocess.DEVNULL) + run_cargo_cmd('resvg', [test_in_svg, tmp_in_png.name], check=True, stdout=subprocess.DEVNULL) else: subprocess.run(['rsvg-convert', tmp_out_svg.name, '-f', 'png', '-o', tmp_out_png.name], check=True, stdout=subprocess.DEVNULL) |