Skip to content

Commit c67ce86

Browse files
bigfootjonfacebook-github-bot
authored andcommitted
Enable tests to run in OSS (#3707)
Summary: Pull Request resolved: #3707 X-link: facebook/folly#2212 Reviewed By: yfeldblum Differential Revision: D57679641 Pulled By: bigfootjon fbshipit-source-id: b683be8a0fa21fc7906faed5ce1d380d327654e7
1 parent a1e9c7a commit c67ce86

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

shim/shims.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,14 @@ def cpp_unittest(
198198
extract_helper_lib = None,
199199
compiler_specific_flags = None,
200200
default_strip_mode = None,
201+
srcs = [],
201202
**kwargs):
202203
_unused = (supports_static_listing, allocator, owner, tags, emails, extract_helper_lib, compiler_specific_flags, default_strip_mode) # @unused
204+
srcs = srcs + ["shim//third-party/googletest:gtest_main.cpp"]
203205
prelude.cxx_test(
204206
deps = _maybe_select_map(deps + external_deps_to_targets(external_deps), _fix_deps),
205207
visibility = visibility,
208+
srcs = srcs,
206209
**kwargs
207210
)
208211

shim/third-party/boost/BUCK

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ oncall("open_source")
1313
boost_libs([
1414
"container",
1515
"range",
16-
"thread",
1716
"algorithm",
1817
"regex",
1918
"program_options",
@@ -32,3 +31,8 @@ third_party_library(
3231
name = "boost_preprocessor",
3332
homebrew_package_name = "boost",
3433
)
34+
35+
third_party_library(
36+
name = "boost_thread",
37+
homebrew_package_name = "boost",
38+
)

shim/third-party/googletest/BUCK

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
66
# of this source tree.
77

8+
load("@shim//build_defs:export_files.bzl", "export_file")
89
load("@shim//third-party:third_party.bzl", "third_party_library")
910

1011
oncall("open_source")
@@ -20,3 +21,7 @@ alias(
2021
actual = ":gtest",
2122
visibility = ["PUBLIC"],
2223
)
24+
25+
export_file(
26+
name = "gtest_main.cpp",
27+
)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2006, Google Inc.
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms, with or without
5+
// modification, are permitted provided that the following conditions are
6+
// met:
7+
//
8+
// * Redistributions of source code must retain the above copyright
9+
// notice, this list of conditions and the following disclaimer.
10+
// * Redistributions in binary form must reproduce the above
11+
// copyright notice, this list of conditions and the following disclaimer
12+
// in the documentation and/or other materials provided with the
13+
// distribution.
14+
// * Neither the name of Google Inc. nor the names of its
15+
// contributors may be used to endorse or promote products derived from
16+
// this software without specific prior written permission.
17+
//
18+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+
#include <cstdio>
31+
32+
#include "gtest/gtest.h"
33+
34+
#if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) || \
35+
(defined(GTEST_OS_NRF52) && defined(ARDUINO))
36+
// Arduino-like platforms: program entry points are setup/loop instead of main.
37+
38+
#ifdef GTEST_OS_ESP8266
39+
extern "C" {
40+
#endif
41+
42+
void setup() { testing::InitGoogleTest(); }
43+
44+
void loop() { RUN_ALL_TESTS(); }
45+
46+
#ifdef GTEST_OS_ESP8266
47+
}
48+
#endif
49+
50+
#elif defined(GTEST_OS_QURT)
51+
// QuRT: program entry point is main, but argc/argv are unusable.
52+
53+
GTEST_API_ int main() {
54+
printf("Running main() from %s\n", __FILE__);
55+
testing::InitGoogleTest();
56+
return RUN_ALL_TESTS();
57+
}
58+
#else
59+
// Normal platforms: program entry point is main, argc/argv are initialized.
60+
61+
GTEST_API_ int main(int argc, char **argv) {
62+
printf("Running main() from %s\n", __FILE__);
63+
testing::InitGoogleTest(&argc, argv);
64+
return RUN_ALL_TESTS();
65+
}
66+
#endif

0 commit comments

Comments
 (0)