iOS C++ Unit Tests Bazel target & running on CI (#1534)
This commit is contained in:
@@ -13,45 +13,84 @@ cc_library(
|
||||
|
||||
cc_library(
|
||||
name = "testlib",
|
||||
srcs = glob(
|
||||
[
|
||||
"src/mbgl/test/*.cpp",
|
||||
],
|
||||
exclude = [
|
||||
"src/mbgl/test/test.cpp",
|
||||
"src/mbgl/test/http_server.cpp",
|
||||
],
|
||||
),
|
||||
srcs = select({
|
||||
"//:ios": glob(
|
||||
["src/mbgl/test/*.cpp"],
|
||||
allow_empty = False,
|
||||
),
|
||||
"//conditions:default": glob(
|
||||
["src/mbgl/test/*.cpp"],
|
||||
allow_empty = False,
|
||||
exclude = ["src/mbgl/test/http_server.cpp"],
|
||||
),
|
||||
}) + [
|
||||
"include/mbgl/test.hpp",
|
||||
],
|
||||
hdrs = glob([
|
||||
"src/mbgl/test/*.hpp",
|
||||
]),
|
||||
copts = CPP_FLAGS + MAPLIBRE_FLAGS,
|
||||
copts = CPP_FLAGS + MAPLIBRE_FLAGS + select({
|
||||
"//:ios": ["-DUSE_CPP_TEST_SERVER"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = [
|
||||
"include",
|
||||
],
|
||||
strip_include_prefix = "src",
|
||||
visibility = [
|
||||
"//platform/ios/test/core:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"testutils",
|
||||
"//:mbgl-core",
|
||||
],
|
||||
] + select({
|
||||
"//:ios": ["//vendor:httplib"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "core",
|
||||
cc_library(
|
||||
name = "tests",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*.test.cpp",
|
||||
],
|
||||
),
|
||||
args = [
|
||||
"--gtest_filter=-Map.StyleNetworkErrorRetry:Map.StyleNotFound:MainResourceLoader.CachedResourceLowPriority",
|
||||
],
|
||||
copts = CPP_FLAGS + MAPLIBRE_FLAGS,
|
||||
data = glob(["fixtures/**/*"]) + [
|
||||
"//:scripts/style-spec-reference/v8.json",
|
||||
visibility = [
|
||||
"//platform/ios/test/core:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"testlib",
|
||||
"testutils",
|
||||
"//:mbgl-core",
|
||||
"//platform/linux:impl",
|
||||
"//platform/default:mbgl-default",
|
||||
"//vendor/googletest:gtest_main",
|
||||
],
|
||||
alwayslink = True,
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "fixtures",
|
||||
srcs = glob(
|
||||
["fixtures/**/*"],
|
||||
allow_empty = False,
|
||||
),
|
||||
visibility = [
|
||||
"//platform/ios/test/core:__pkg__",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "core",
|
||||
args = [
|
||||
"--gtest_filter=-Map.StyleNetworkErrorRetry:Map.StyleNotFound:MainResourceLoader.CachedResourceLowPriority",
|
||||
],
|
||||
data = glob(["fixtures/**/*"]) + [
|
||||
"//:scripts/style-spec-reference/v8.json",
|
||||
],
|
||||
deps = [
|
||||
"tests",
|
||||
"//platform/linux:impl",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -187,18 +187,6 @@ target_include_directories(
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/cpp-httplib.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/googletest.cmake)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL iOS)
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}")
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode)
|
||||
set_target_properties(mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>)
|
||||
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "${IOS_DEPLOYMENT_TARGET}")
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode)
|
||||
set_target_properties(mbgl-test PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
set_target_properties(mbgl-test mbgl-vendor-googletest PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>)
|
||||
set_target_properties(mbgl-test mbgl-vendor-googletest
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>UnitTestsApp</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleLongVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>com.mapbox.UnitTestsApp</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>MBGL</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>7877</string>
|
||||
<key>CSResourcesFileMapped</key>
|
||||
<true/>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>© 2014–2020 Mapbox</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>fetch</string>
|
||||
<string>remote-notification</string>
|
||||
</array>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,12 +0,0 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NSString *dataDir = @"test-data";
|
||||
NSString *resultFilePath = @"test/results.xml";
|
||||
|
||||
__attribute__((visibility ("default")))
|
||||
@interface IosTestRunner : NSObject
|
||||
|
||||
- (NSString*) getResultPath;
|
||||
- (BOOL) getTestStatus;
|
||||
|
||||
@end
|
||||
@@ -1,31 +0,0 @@
|
||||
#include <ios_test_runner.hpp>
|
||||
|
||||
#include <mbgl/test.hpp>
|
||||
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#define EXPORT __attribute__((visibility("default")))
|
||||
|
||||
EXPORT
|
||||
bool TestRunner::startTest(const std::string& basePath) {
|
||||
std::vector<std::string> arguments = {"mbgl-test-runner", "--gtest_output=xml:" + basePath + "/test/results.xml"};
|
||||
std::vector<char*> argv;
|
||||
for (const auto& arg : arguments) {
|
||||
argv.push_back(const_cast<char*>(arg.data()));
|
||||
}
|
||||
argv.push_back(nullptr);
|
||||
|
||||
if (chdir(basePath.c_str())) {
|
||||
mbgl::Log::Error(mbgl::Event::General, "Failed to change the directory to " + basePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
mbgl::Log::Info(mbgl::Event::General, "Start TestRunner");
|
||||
int status = mbgl::runTests(static_cast<uint32_t>(argv.size()), argv.data());
|
||||
mbgl::Log::Info(mbgl::Event::General, "TestRunner finished with status: '%d'", status);
|
||||
|
||||
return status == 0;
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
namespace mbgl {
|
||||
|
||||
int runTests(int argc, char *argv[]) {
|
||||
#if TEST_HAS_SERVER && defined(__QT__)
|
||||
#if (TEST_HAS_SERVER && defined(__QT__)) || USE_CPP_TEST_SERVER
|
||||
auto server = std::make_unique<test::HttpServer>();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
virtual void setClientOptions(ClientOptions) override {}
|
||||
|
||||
virtual ClientOptions getClientOptions() { return ClientOptions{}; }
|
||||
virtual ClientOptions getClientOptions() override { return ClientOptions{}; }
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::shared_ptr<std::string>> assets;
|
||||
|
||||
Reference in New Issue
Block a user