From 1687f6ff1b391f37ee5bc3799e5f2ee2b71f855d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 5 Jan 2016 17:13:36 -0800 Subject: [PATCH] add custom command line options to unit tests - refs philsquared/Catch#381 --- test/catch.hpp | 2 +- test/unit/run.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/test/catch.hpp b/test/catch.hpp index 3b759681e..b7ac69633 100644 --- a/test/catch.hpp +++ b/test/catch.hpp @@ -6143,7 +6143,7 @@ namespace Catch { } } - Clara::CommandLine const& cli() const { + Clara::CommandLine & cli() { return m_cli; } std::vector const& unusedTokens() const { diff --git a/test/unit/run.cpp b/test/unit/run.cpp index 8ae4ddc73..caaab46dc 100644 --- a/test/unit/run.cpp +++ b/test/unit/run.cpp @@ -1,17 +1,73 @@ #define CATCH_CONFIG_RUNNER #include "catch.hpp" +#include +#include #include +#include #include "cleanup.hpp" // run_cleanup() +std::string plugin_path; + +inline void set_plugin_path(Catch::ConfigData&, std::string const& _plugin_path ) { + plugin_path = _plugin_path; +} + +std::string working_dir; + +inline void set_working_dir(Catch::ConfigData&, std::string const& _working_dir ) { + working_dir = _working_dir; +} + + int main (int argc, char* const argv[]) { - mapnik::datasource_cache::instance().register_datasources("plugins/input/"); + Catch::Session session; - int result = Catch::Session().run( argc, argv ); + auto & cli = session.cli(); + + cli["-p"]["--plugins"] + .describe("path to mapnik plugins") + .bind(&set_plugin_path, "plugins"); + + cli["-C"]["--working-directory"] + .describe("change working directory") + .bind(&set_working_dir, "working directory"); + + int result = session.applyCommandLine(argc, argv); + + if (!plugin_path.empty()) + { + if (!mapnik::util::exists(plugin_path)) + { + std::clog << "Could not find " << plugin_path << "\n"; + return -1; + } + mapnik::datasource_cache::instance().register_datasources(plugin_path); + } + else + { + mapnik::datasource_cache::instance().register_datasources("plugins/input/"); + } + + if (!working_dir.empty()) + { + if (!mapnik::util::exists(working_dir)) + { + std::clog << "Could not find " << working_dir << "\n"; + return -1; + } + boost::filesystem::current_path(working_dir); + } + + if (result == 0) + { + result = session.run(); + } testing::run_cleanup(); return result; + }