diff options
author | luigi1111 <luigi1111w@gmail.com> | 2023-10-25 21:37:09 -0400 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2023-10-25 21:37:09 -0400 |
commit | a1a40d67d295fd97e0dab15a2ed086adfc325e3d (patch) | |
tree | 85c3aa68082a9c8d90e3bb10be0b6c928e4269e7 | |
parent | Merge pull request #8974 (diff) | |
parent | unit_test: set data dir relative to exe & add log-level arg (diff) | |
download | monero-a1a40d67d295fd97e0dab15a2ed086adfc325e3d.tar.xz |
Merge pull request #8987
1025e4f unit_test: set data dir relative to exe & add log-level arg (jeff)
-rw-r--r-- | tests/unit_tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/unit_tests/main.cpp | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt index a9f0944c8..40f37c4ed 100644 --- a/tests/unit_tests/CMakeLists.txt +++ b/tests/unit_tests/CMakeLists.txt @@ -143,8 +143,6 @@ if (NOT MSVC) COMPILE_FLAGS " -Wno-undef -Wno-sign-compare") endif () -SET_PROPERTY(SOURCE main.cpp PROPERTY COMPILE_FLAGS -DDEFAULT_DATA_DIR="\\"${CMAKE_SOURCE_DIR}/tests/data\\"") - SET_PROPERTY(SOURCE memwipe.cpp PROPERTY COMPILE_FLAGS -Ofast) add_test( diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp index f690f3581..586cb7c60 100644 --- a/tests/unit_tests/main.cpp +++ b/tests/unit_tests/main.cpp @@ -62,9 +62,14 @@ int main(int argc, char** argv) ::testing::InitGoogleTest(&argc, argv); + // the default test data directory is ../data (relative to the executable's directory) + const auto default_test_data_dir = boost::filesystem::path(argv[0]).parent_path().parent_path() / "data"; + po::options_description desc_options("Command line options"); - const command_line::arg_descriptor<std::string> arg_data_dir = { "data-dir", "Data files directory", DEFAULT_DATA_DIR }; + const command_line::arg_descriptor<std::string> arg_data_dir = { "data-dir", "Data files directory", default_test_data_dir.string() }; + const command_line::arg_descriptor<std::string> arg_log_level = { "log-level", "0-4 or categories", "" }; command_line::add_arg(desc_options, arg_data_dir); + command_line::add_arg(desc_options, arg_log_level); po::variables_map vm; bool r = command_line::handle_error_helper(desc_options, [&]() @@ -76,7 +81,12 @@ int main(int argc, char** argv) if (! r) return 1; - unit_test::data_dir = command_line::get_arg(vm, arg_data_dir); + // set the test data directory + unit_test::data_dir = command_line::get_arg(vm, arg_data_dir).c_str(); + + // set the log level + if (!command_line::is_arg_defaulted(vm, arg_log_level)) + mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str()); CATCH_ENTRY_L0("main", 1); |