diff options
author | Jonathan Abrahams <jonathan@mongodb.com> | 2018-08-21 10:29:00 -0400 |
---|---|---|
committer | Jonathan Abrahams <jonathan@mongodb.com> | 2018-08-22 17:52:35 -0400 |
commit | 6dd6e4d307c54912f6aaa502a581af9cb9dbf055 (patch) | |
tree | 7cd99d82855e1798c5ea16521a79a027988d2064 /src/mongo/unittest | |
parent | 600351dc35fba5ef1f0a7987770e307a38ffbcd4 (diff) | |
download | mongo-6dd6e4d307c54912f6aaa502a581af9cb9dbf055.tar.gz |
SERVER-35203 Add verbose option to unittests
Diffstat (limited to 'src/mongo/unittest')
-rw-r--r-- | src/mongo/unittest/unittest_main.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/mongo/unittest/unittest_main.cpp b/src/mongo/unittest/unittest_main.cpp index f3f0e63754d..33e99099020 100644 --- a/src/mongo/unittest/unittest_main.cpp +++ b/src/mongo/unittest/unittest_main.cpp @@ -33,6 +33,7 @@ #include "mongo/base/initializer.h" #include "mongo/base/status.h" +#include "mongo/logger/logger.h" #include "mongo/unittest/unittest.h" #include "mongo/util/options_parser/environment.h" #include "mongo/util/options_parser/option_section.h" @@ -66,6 +67,10 @@ int main(int argc, char** argv, char** envp) { auto repeatDesc = "Specifies the number of runs for each test."; options.addOptionChaining("repeat", "repeat", moe::Int, repeatDesc).setDefault(moe::Value(1)); + auto verboseDesc = "Log more verbose output. Specify one or more 'v's to increase verbosity."; + options.addOptionChaining("verbose", "verbose", moe::String, verboseDesc) + .setImplicit(moe::Value(std::string("v"))); + std::vector<std::string> argVector(argv, argv + argc); Status ret = parser.run(options, argVector, env, &environment); if (!ret.isOK()) { @@ -77,12 +82,23 @@ int main(int argc, char** argv, char** envp) { moe::StringVector_t suites; std::string filter; int repeat = 1; + std::string verbose; // "list" and "repeat" will be assigned with default values, if not present. invariant(environment.get("list", &list)); invariant(environment.get("repeat", &repeat)); - // The default values of "suite" and "filter" are empty. + // The default values of "suite" "filter" and "verbose" are empty. environment.get("suite", &suites).ignore(); environment.get("filter", &filter).ignore(); + environment.get("verbose", &verbose).ignore(); + + if (std::any_of(verbose.cbegin(), verbose.cend(), [](char ch) { return ch != 'v'; })) { + std::cerr << "The string for the --verbose option cannot contain characters other than 'v'" + << std::endl; + std::cerr << options.helpString(); + return EXIT_FAILURE; + } + ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity( + ::mongo::logger::LogSeverity::Debug(verbose.length())); if (list) { auto suiteNames = ::mongo::unittest::getAllSuiteNames(); @@ -91,5 +107,6 @@ int main(int argc, char** argv, char** envp) { } return EXIT_SUCCESS; } + return ::mongo::unittest::Suite::run(suites, filter, repeat); } |