Move initialization of GoogleMock and flags to main from test_main_lib

Bug: None
Change-Id: Ie3aed382d4e468c4adbfdbcc1bdb3f069d3eaae2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/181364
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Andrey Logvin <landrey@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31909}
This commit is contained in:
Artem Titov 2020-08-11 12:19:18 +02:00 committed by Commit Bot
parent 07b7dece9a
commit bcb42f1e4b
4 changed files with 15 additions and 8 deletions

View file

@ -422,7 +422,6 @@ if (rtc_include_tests) {
]
absl_deps = [
"//third_party/abseil-cpp/absl/flags:flag",
"//third_party/abseil-cpp/absl/flags:parse",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings:strings",
"//third_party/abseil-cpp/absl/types:optional",
@ -434,10 +433,15 @@ if (rtc_include_tests) {
testonly = true
sources = [ "test_main.cc" ]
deps = [ ":test_main_lib" ]
deps = [
":test_main_lib",
":test_support",
]
absl_deps = [
"//third_party/abseil-cpp/absl/debugging:failure_signal_handler",
"//third_party/abseil-cpp/absl/debugging:symbolize",
"//third_party/abseil-cpp/absl/flags:parse",
]
}

View file

@ -12,17 +12,21 @@
#include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/symbolize.h"
#include "absl/flags/parse.h"
#include "test/gmock.h"
#include "test/test_main_lib.h"
int main(int argc, char* argv[]) {
// Initialize the symbolizer to get a human-readable stack trace
absl::InitializeSymbolizer(argv[0]);
testing::InitGoogleMock(&argc, argv);
absl::ParseCommandLine(argc, argv);
absl::FailureSignalHandlerOptions options;
absl::InstallFailureSignalHandler(options);
std::unique_ptr<webrtc::TestMain> main = webrtc::TestMain::Create();
int err_code = main->Init(&argc, argv);
int err_code = main->Init();
if (err_code != 0) {
return err_code;
}

View file

@ -15,7 +15,6 @@
#include <string>
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/memory/memory.h"
#include "absl/strings/match.h"
#include "absl/types/optional.h"
@ -28,7 +27,6 @@
#include "system_wrappers/include/field_trial.h"
#include "system_wrappers/include/metrics.h"
#include "test/field_trial.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/testsupport/perf_test.h"
#include "test/testsupport/resources_dir_flag.h"
@ -157,10 +155,9 @@ class TestMainImpl : public TestMain {
std::unique_ptr<rtc::Thread> thread_;
};
int Init(int* argc, char* argv[]) override {
::testing::InitGoogleMock(argc, argv);
absl::ParseCommandLine(*argc, argv);
int Init(int* argc, char* argv[]) override { return Init(); }
int Init() override {
// Make sure we always pull in the --resources_dir flag, even if the test
// binary doesn't link with fileutils (downstream expects all test mains to
// have this flag).

View file

@ -25,6 +25,8 @@ class TestMain {
// Initializes test environment. Clients can add their own initialization
// steps after call to this method and before running tests.
// Returns 0 if initialization was successful and non 0 otherwise.
virtual int Init() = 0;
// Temporary for backward compatibility
virtual int Init(int* argc, char* argv[]) = 0;
// Runs test end return result error code. 0 - no errors.