mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
unit_tests: data dir is now overridden with --data-dir
rather than a raw string without option
This commit is contained in:
parent
86e9de588c
commit
fe484f3049
2 changed files with 23 additions and 10 deletions
|
@ -100,4 +100,4 @@ endif ()
|
||||||
|
|
||||||
add_test(
|
add_test(
|
||||||
NAME unit_tests
|
NAME unit_tests
|
||||||
COMMAND unit_tests "${TEST_DATA_DIR}")
|
COMMAND unit_tests --data-dir "${TEST_DATA_DIR}")
|
||||||
|
|
|
@ -31,31 +31,44 @@
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
#include "include_base_utils.h"
|
#include "include_base_utils.h"
|
||||||
|
#include "common/command_line.h"
|
||||||
#include "unit_tests_utils.h"
|
#include "unit_tests_utils.h"
|
||||||
|
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
boost::filesystem::path unit_test::data_dir;
|
boost::filesystem::path unit_test::data_dir;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
epee::string_tools::set_module_name_and_folder(argv[0]);
|
||||||
mlog_configure(mlog_get_default_log_path("unit_tests.log"), true);
|
mlog_configure(mlog_get_default_log_path("unit_tests.log"), true);
|
||||||
epee::debug::get_set_enable_assert(true, false);
|
epee::debug::get_set_enable_assert(true, false);
|
||||||
|
|
||||||
::testing::InitGoogleTest(&argc, argv);
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
|
||||||
// Process remaining arguments
|
po::options_description desc_options("Command line options");
|
||||||
if (argc == 2 && argv[1] != NULL) { // one arg: path to dir with test data
|
const command_line::arg_descriptor<std::string> arg_data_dir = {"data-dir", "Data files directory", "", true};
|
||||||
unit_test::data_dir = argv[1];
|
command_line::add_arg(desc_options, command_line::arg_data_dir, "");
|
||||||
} else if (argc == 1) { // legacy: assume test binaries in 'build/release'
|
|
||||||
epee::string_tools::set_module_name_and_folder(argv[0]);
|
po::variables_map vm;
|
||||||
|
bool r = command_line::handle_error_helper(desc_options, [&]()
|
||||||
|
{
|
||||||
|
po::store(po::parse_command_line(argc, argv, desc_options), vm);
|
||||||
|
po::notify(vm);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
if (! r)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (vm["data-dir"].defaulted())
|
||||||
unit_test::data_dir = boost::filesystem::path(epee::string_tools::get_current_module_folder())
|
unit_test::data_dir = boost::filesystem::path(epee::string_tools::get_current_module_folder())
|
||||||
.parent_path().parent_path().parent_path().parent_path()
|
.parent_path().parent_path().parent_path().parent_path()
|
||||||
.append("tests").append("data");
|
.append("tests").append("data");
|
||||||
} else {
|
else
|
||||||
std::cerr << "Usage: " << argv[0] << " [<path-to-test-data-dir>]" << std::endl;
|
unit_test::data_dir = command_line::get_arg(vm, arg_data_dir);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue