-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from silicon-heaven/default-config-dir-is-cwd
ConfigCLIOptions::configFile: --config relative paths are relative to…
- Loading branch information
Showing
5 changed files
with
188 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include <shv/core/utils/clioptions.h> | ||
#include <shv/core/utils/shvpath.h> | ||
#include <shv/core/utils.h> | ||
#include <shv/core/stringview.h> | ||
#include <necrolog.h> | ||
|
||
#include <filesystem> | ||
|
||
#define DOCTEST_CONFIG_IMPLEMENT | ||
#include <doctest/doctest.h> | ||
|
||
using namespace shv::core::utils; | ||
using namespace shv::core; | ||
using namespace std; | ||
|
||
vector<string> cmdline; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
//NecroLog::setFileLogTresholds("test_shvlog:D"); | ||
cmdline = NecroLog::setCLIOptions(argc, argv); | ||
|
||
return doctest::Context(argc, argv).run(); | ||
} | ||
|
||
DOCTEST_TEST_CASE("CliOptions") | ||
{ | ||
DOCTEST_SUBCASE("Make config dir and config file absolute") | ||
{ | ||
string req_abs_config_dir; | ||
string req_abs_config_file; | ||
string config_dir; | ||
string config_file; | ||
const auto cwd = std::filesystem::current_path().string(); | ||
const auto default_config_file_name = "test_core_clioptions.conf"s; | ||
ConfigCLIOptions cliopts; | ||
cliopts.parse(cmdline); | ||
DOCTEST_SUBCASE("Empty config dir") | ||
{ | ||
config_dir = {}; | ||
DOCTEST_SUBCASE("Empty config file") | ||
{ | ||
config_file = {}; | ||
req_abs_config_dir = cwd; | ||
req_abs_config_file = joinPath(cwd, default_config_file_name); | ||
} | ||
DOCTEST_SUBCASE("Relative config file") | ||
{ | ||
config_file = "foo/bar/baz.conf"s; | ||
req_abs_config_dir = cwd; | ||
req_abs_config_file = joinPath(cwd, config_file); | ||
} | ||
DOCTEST_SUBCASE("Absolute config file") | ||
{ | ||
config_file = "/foo/bar/baz.conf"s; | ||
req_abs_config_dir = "/foo/bar"s; | ||
req_abs_config_file = config_file; | ||
} | ||
} | ||
DOCTEST_SUBCASE("Relative config dir") | ||
{ | ||
config_dir = "foo/bar"s; | ||
DOCTEST_SUBCASE("Empty config file") | ||
{ | ||
config_file = {}; | ||
req_abs_config_dir = joinPath(cwd, config_dir); | ||
req_abs_config_file = joinPath(cwd, config_dir, default_config_file_name); | ||
} | ||
DOCTEST_SUBCASE("Relative config file") | ||
{ | ||
config_file = "foo/bar/baz.conf"s; | ||
req_abs_config_dir = joinPath(cwd, config_dir); | ||
req_abs_config_file = joinPath(cwd, config_dir, config_file); | ||
} | ||
DOCTEST_SUBCASE("Absolute config file") | ||
{ | ||
config_file = "/abs/foo/bar/baz.conf"s; | ||
req_abs_config_dir = joinPath(cwd, config_dir); | ||
req_abs_config_file = config_file; | ||
} | ||
} | ||
DOCTEST_SUBCASE("Absolute config dir") | ||
{ | ||
config_dir = "/a/foo/bar"s; | ||
DOCTEST_SUBCASE("Empty config file") | ||
{ | ||
config_file = {}; | ||
req_abs_config_dir = config_dir; | ||
req_abs_config_file = joinPath(config_dir, default_config_file_name); | ||
} | ||
DOCTEST_SUBCASE("Relative config file") | ||
{ | ||
config_file = "foo/bar/baz.conf"s; | ||
req_abs_config_dir = config_dir; | ||
req_abs_config_file = joinPath(config_dir, config_file); | ||
} | ||
DOCTEST_SUBCASE("Absolute config file") | ||
{ | ||
config_file = "/abs/foo/bar/baz.conf"s; | ||
req_abs_config_dir = config_dir; | ||
req_abs_config_file = config_file; | ||
} | ||
} | ||
auto [abs_config_dir, abs_config_file] = cliopts.absoluteConfigPaths(config_dir, config_file); | ||
REQUIRE(abs_config_dir == req_abs_config_dir); | ||
REQUIRE(abs_config_file == req_abs_config_file); | ||
} | ||
} |