diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2019-02-21 21:06:25 +0000 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2019-02-22 19:03:54 +0000 |
commit | bd5bd0eff3fc852d55760ebb4c7ac62e394e8ce6 (patch) | |
tree | 1a074c3f35044dc91c072278f8297055d3e5b18c /src/mongo/unittest | |
parent | 493d6db58f37927e3bd267e6fd582a7e79d96678 (diff) | |
download | mongo-bd5bd0eff3fc852d55760ebb4c7ac62e394e8ce6.tar.gz |
SERVER-39725 Migrate unittest options to IDL
Diffstat (limited to 'src/mongo/unittest')
-rw-r--r-- | src/mongo/unittest/SConscript | 6 | ||||
-rw-r--r-- | src/mongo/unittest/integration_test_main.cpp | 29 | ||||
-rw-r--r-- | src/mongo/unittest/integration_test_main.idl | 43 | ||||
-rw-r--r-- | src/mongo/unittest/temp_dir.cpp | 6 | ||||
-rw-r--r-- | src/mongo/unittest/unittest.idl | 36 | ||||
-rw-r--r-- | src/mongo/unittest/unittest_main.cpp | 31 | ||||
-rw-r--r-- | src/mongo/unittest/unittest_options.idl | 55 |
7 files changed, 156 insertions, 50 deletions
diff --git a/src/mongo/unittest/SConscript b/src/mongo/unittest/SConscript index 253744b6de6..0114d81ec19 100644 --- a/src/mongo/unittest/SConscript +++ b/src/mongo/unittest/SConscript @@ -13,6 +13,7 @@ env.Library( 'temp_dir.cpp', 'unittest_helpers.cpp', 'unittest.cpp', + env.Idlc('unittest.idl')[0], ], LIBDEPS=[ '$BUILD_DIR/mongo/base', @@ -26,7 +27,8 @@ env.Library( env.Library( target="unittest_main", source=[ - 'unittest_main.cpp' + 'unittest_main.cpp', + env.Idlc('unittest_options.idl')[0], ], LIBDEPS=[ 'unittest', @@ -40,6 +42,7 @@ env.Library( target="integration_test_main", source=[ 'integration_test_main.cpp', + env.Idlc('integration_test_main.idl')[0], ], LIBDEPS=[ 'unittest', @@ -48,6 +51,7 @@ env.Library( LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/client/connection_string', '$BUILD_DIR/mongo/db/service_context', + '$BUILD_DIR/mongo/util/options_parser/options_parser', '$BUILD_DIR/mongo/util/options_parser/options_parser_init', ], ) diff --git a/src/mongo/unittest/integration_test_main.cpp b/src/mongo/unittest/integration_test_main.cpp index 9162ca64616..c446d793414 100644 --- a/src/mongo/unittest/integration_test_main.cpp +++ b/src/mongo/unittest/integration_test_main.cpp @@ -55,8 +55,6 @@ namespace { ConnectionString fixtureConnectionString{}; -const char kConnectionStringFlag[] = "connectionString"; - } // namespace namespace mongo { @@ -78,18 +76,6 @@ int main(int argc, char** argv, char** envp) { namespace moe = mongo::optionenvironment; -MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(IntegrationTestOptions)(InitializerContext*) { - auto& opts = moe::startupOptions; - opts.addOptionChaining("help", "help", moe::Switch, "Display help"); - opts.addOptionChaining(kConnectionStringFlag, - kConnectionStringFlag, - moe::String, - "The connection string associated with the test fixture that this " - "integration test should run against.") - .setDefault(moe::Value("localhost:27017")); - return Status::OK(); -} - MONGO_STARTUP_OPTIONS_VALIDATE(IntegrationTestOptions)(InitializerContext*) { auto& env = moe::startupOptionsParsed; auto& opts = moe::startupOptions; @@ -109,21 +95,18 @@ MONGO_STARTUP_OPTIONS_VALIDATE(IntegrationTestOptions)(InitializerContext*) { } MONGO_STARTUP_OPTIONS_STORE(IntegrationTestOptions)(InitializerContext*) { - auto& env = moe::startupOptionsParsed; - moe::Value connectionString; - auto ret = env.get(moe::Key(kConnectionStringFlag), &connectionString); - if (!ret.isOK()) { - return ret; - } + const auto& env = moe::startupOptionsParsed; - auto swConnectionString = ConnectionString::parse(connectionString.as<std::string>()); + std::string connectionString = env["connectionString"].as<std::string>(); + + auto swConnectionString = ConnectionString::parse(connectionString); if (!swConnectionString.isOK()) { return swConnectionString.getStatus(); } - log() << "Using test fixture with connection string = " << connectionString.as<std::string>(); - fixtureConnectionString = std::move(swConnectionString.getValue()); + log() << "Using test fixture with connection string = " << connectionString; + return Status::OK(); } diff --git a/src/mongo/unittest/integration_test_main.idl b/src/mongo/unittest/integration_test_main.idl new file mode 100644 index 00000000000..f60635e5bde --- /dev/null +++ b/src/mongo/unittest/integration_test_main.idl @@ -0,0 +1,43 @@ +# Copyright (C) 2019-present MongoDB, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Server Side Public License, version 1, +# as published by MongoDB, Inc. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Server Side Public License for more details. +# +# You should have received a copy of the Server Side Public License +# along with this program. If not, see +# <http://www.mongodb.com/licensing/server-side-public-license>. +# +# As a special exception, the copyright holders give permission to link the +# code of portions of this program with the OpenSSL library under certain +# conditions as described in each individual source file and distribute +# linked combinations including the program with the OpenSSL library. You +# must comply with the Server Side Public License in all respects for +# all of the code used other than as permitted herein. If you modify file(s) +# with this exception, you may extend this exception to your version of the +# file(s), but you are not obligated to do so. If you do not wish to do so, +# delete this exception statement from your version. If you delete this +# exception statement from all source files in the program, then also delete +# it in the license file. +# + +global: + cpp_namespace: "mongo::unittest" + configs: + source: cli + +configs: + help: + description: 'Display help' + arg_vartype: Switch + connectionString: + description: The connection string associated with the test fixture + that this integration test should run against. + arg_vartype: String + default: 'localhost:27017' + diff --git a/src/mongo/unittest/temp_dir.cpp b/src/mongo/unittest/temp_dir.cpp index a473a866769..19ab9b5d077 100644 --- a/src/mongo/unittest/temp_dir.cpp +++ b/src/mongo/unittest/temp_dir.cpp @@ -54,12 +54,6 @@ namespace moe = mongo::optionenvironment; namespace { boost::filesystem::path defaultRoot; -MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(TempDirOptions)(InitializerContext* context) { - moe::startupOptions.addOptionChaining( - "tempPath", "tempPath", moe::String, "directory to place mongo::TempDir subdirectories"); - return Status::OK(); -} - MONGO_INITIALIZER(SetTempDirDefaultRoot)(InitializerContext* context) { if (moe::startupOptionsParsed.count("tempPath")) { defaultRoot = moe::startupOptionsParsed["tempPath"].as<string>(); diff --git a/src/mongo/unittest/unittest.idl b/src/mongo/unittest/unittest.idl new file mode 100644 index 00000000000..88a9017969c --- /dev/null +++ b/src/mongo/unittest/unittest.idl @@ -0,0 +1,36 @@ +# Copyright (C) 2019-present MongoDB, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Server Side Public License, version 1, +# as published by MongoDB, Inc. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Server Side Public License for more details. +# +# You should have received a copy of the Server Side Public License +# along with this program. If not, see +# <http://www.mongodb.com/licensing/server-side-public-license>. +# +# As a special exception, the copyright holders give permission to link the +# code of portions of this program with the OpenSSL library under certain +# conditions as described in each individual source file and distribute +# linked combinations including the program with the OpenSSL library. You +# must comply with the Server Side Public License in all respects for +# all of the code used other than as permitted herein. If you modify file(s) +# with this exception, you may extend this exception to your version of the +# file(s), but you are not obligated to do so. If you do not wish to do so, +# delete this exception statement from your version. If you delete this +# exception statement from all source files in the program, then also delete +# it in the license file. +# + +global: + cpp_namespace: "mongo::unittest" + +configs: + tempPath: + description: 'Directory to place mongo::TempDir subdirectories' + arg_vartype: String + source: cli diff --git a/src/mongo/unittest/unittest_main.cpp b/src/mongo/unittest/unittest_main.cpp index 71db1c09116..f83ab75d31b 100644 --- a/src/mongo/unittest/unittest_main.cpp +++ b/src/mongo/unittest/unittest_main.cpp @@ -35,6 +35,7 @@ #include "mongo/base/status.h" #include "mongo/logger/logger.h" #include "mongo/unittest/unittest.h" +#include "mongo/unittest/unittest_options_gen.h" #include "mongo/util/options_parser/environment.h" #include "mongo/util/options_parser/option_section.h" #include "mongo/util/options_parser/options_parser.h" @@ -42,35 +43,25 @@ using mongo::Status; +namespace moe = ::mongo::optionenvironment; + int main(int argc, char** argv, char** envp) { ::mongo::clearSignalMask(); ::mongo::setupSynchronousSignalHandlers(); ::mongo::runGlobalInitializersOrDie(argc, argv, envp); - namespace moe = ::mongo::optionenvironment; - moe::OptionsParser parser; - moe::Environment environment; moe::OptionSection options; - std::map<std::string, std::string> env; - - // Register our allowed options with our OptionSection - auto listDesc = "List all test suites in this unit test."; - options.addOptionChaining("list", "list", moe::Switch, listDesc).setDefault(moe::Value(false)); - - auto suiteDesc = "Test suite name. Specify --suite more than once to run multiple suites."; - options.addOptionChaining("suite", "suite", moe::StringVector, suiteDesc); - - auto filterDesc = "Test case name filter. Specify the substring of the test names."; - options.addOptionChaining("filter", "filter", moe::String, filterDesc); - 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"))); + Status status = mongo::unittest::addUnitTestOptions(&options); + if (!status.isOK()) { + std::cerr << status; + return EXIT_FAILURE; + } + moe::OptionsParser parser; + moe::Environment environment; + std::map<std::string, std::string> env; std::vector<std::string> argVector(argv, argv + argc); Status ret = parser.run(options, argVector, env, &environment); if (!ret.isOK()) { diff --git a/src/mongo/unittest/unittest_options.idl b/src/mongo/unittest/unittest_options.idl new file mode 100644 index 00000000000..577ab2a8f3f --- /dev/null +++ b/src/mongo/unittest/unittest_options.idl @@ -0,0 +1,55 @@ +# Copyright (C) 2019-present MongoDB, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Server Side Public License, version 1, +# as published by MongoDB, Inc. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Server Side Public License for more details. +# +# You should have received a copy of the Server Side Public License +# along with this program. If not, see +# <http://www.mongodb.com/licensing/server-side-public-license>. +# +# As a special exception, the copyright holders give permission to link the +# code of portions of this program with the OpenSSL library under certain +# conditions as described in each individual source file and distribute +# linked combinations including the program with the OpenSSL library. You +# must comply with the Server Side Public License in all respects for +# all of the code used other than as permitted herein. If you modify file(s) +# with this exception, you may extend this exception to your version of the +# file(s), but you are not obligated to do so. If you do not wish to do so, +# delete this exception statement from your version. If you delete this +# exception statement from all source files in the program, then also delete +# it in the license file. +# + +global: + cpp_namespace: "mongo::unittest" + configs: + source: cli + initializer: + register: addUnitTestOptions + +configs: + list: + description: 'List all test suites in this unit test.' + arg_vartype: Switch + default: false + suite: + description: 'Test suite name. Specify --suite more than once to run multiple suites.' + arg_vartype: StringVector + filter: + description: 'Test case name filter. Specify the substring of the test names.' + arg_vartype: String + repeat: + description: 'Specifies the number of runs for each test.' + arg_vartype: Int + default: 1 + verbose: + description: "Log more verbose output. Specify one or more 'v's to increase verbosity." + arg_vartype: String + implicit: v + |