2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
+ #include < iostream>
6
+ #include < optional>
7
+ #include < string>
8
+
5
9
#include " flutter/fml/build_config.h"
10
+ #include " flutter/fml/command_line.h"
11
+ #include " flutter/testing/debugger_detection.h"
6
12
#include " flutter/testing/test_timeout_listener.h"
7
13
#include " gtest/gtest.h"
8
14
9
15
#ifdef OS_IOS
10
16
#include < asl.h>
11
17
#endif // OS_IOS
12
18
19
+ std::optional<fml::TimeDelta> GetTestTimeoutFromArgs (int argc, char ** argv) {
20
+ const auto command_line = fml::CommandLineFromArgcArgv (argc, argv);
21
+
22
+ std::string timeout_seconds;
23
+ if (!command_line.GetOptionValue (" timeout" , &timeout_seconds)) {
24
+ // No timeout specified. Default to 30s.
25
+ return fml::TimeDelta::FromSeconds (30u );
26
+ }
27
+
28
+ const auto seconds = std::stoi (timeout_seconds);
29
+
30
+ if (seconds < 1 ) {
31
+ return std::nullopt ;
32
+ }
33
+
34
+ return fml::TimeDelta::FromSeconds (seconds);
35
+ }
36
+
13
37
int main (int argc, char ** argv) {
14
38
#ifdef OS_IOS
15
39
asl_log_descriptor (NULL , NULL , ASL_LEVEL_NOTICE, STDOUT_FILENO,
@@ -19,7 +43,23 @@ int main(int argc, char** argv) {
19
43
#endif // OS_IOS
20
44
21
45
::testing::InitGoogleTest (&argc, argv);
22
- auto timeout_listener = new flutter::testing::TestTimeoutListener ();
46
+
47
+ // Check if the user has specified a timeout.
48
+ const auto timeout = GetTestTimeoutFromArgs (argc, argv);
49
+ if (!timeout.has_value ()) {
50
+ FML_LOG (INFO) << " Timeouts disabled via a command line flag." ;
51
+ return RUN_ALL_TESTS ();
52
+ }
53
+
54
+ // Check if the user is debugging the process.
55
+ if (flutter::testing::GetDebuggerStatus () ==
56
+ flutter::testing::DebuggerStatus::kAttached ) {
57
+ FML_LOG (INFO) << " Debugger is attached. Suspending test timeouts." ;
58
+ return RUN_ALL_TESTS ();
59
+ }
60
+
61
+ auto timeout_listener =
62
+ new flutter::testing::TestTimeoutListener (timeout.value ());
23
63
auto & listeners = ::testing::UnitTest::GetInstance ()->listeners ();
24
64
listeners.Append (timeout_listener);
25
65
auto result = RUN_ALL_TESTS ();
0 commit comments