Skip to content

Commit

Permalink
Integrate GTests into SPM. (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Mar 11, 2024
1 parent 3b7dc43 commit ffe9f3d
Show file tree
Hide file tree
Showing 69 changed files with 42,453 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration-workflow-spm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- name: Build
run: swift build
- name: Build-And-Test
run: swift run TekkonCC_GTests
Empty file added GTests/include/placeholder.h
Empty file.
46 changes: 46 additions & 0 deletions GTests/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===--- utils/unittest/UnitTestMain/TestMain.cpp - unittest driver -------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <stdlib.h>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

#if defined(_WIN32)
#include <windows.h>
#if defined(_MSC_VER)
#include <crtdbg.h>
#endif
#endif

const char *TestMainArgv0;

int main(int argc, char **argv) {
// Initialize both gmock and gtest.
testing::InitGoogleMock(&argc, argv);

// Make it easy for a test to re-execute itself by saving argv[0].
TestMainArgv0 = argv[0];

#if defined(_WIN32)
// Disable all of the possible ways Windows conspires to make automated
// testing impossible.
::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
#if defined(_MSC_VER)
::_set_error_mode(_OUT_TO_STDERR);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
#endif
#endif

return RUN_ALL_TESTS();
}
54 changes: 53 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ let package = Package(
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Tekkon",
targets: ["Tekkon"]),
targets: ["Tekkon"]
),
.executable(
name: "TekkonCC_GTests",
targets: ["TekkonCC_GTests"]
)
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand All @@ -23,6 +28,53 @@ let package = Package(
dependencies: ["Tekkon"]
// swiftSettings: [.interoperabilityMode(.Cxx)]
),
// MARK: - GoogleTest Targets
.executableTarget(
name: "TekkonCC_GTests",
dependencies: ["gmocklib"],
path: "GTests",
cxxSettings: [
.headerSearchPath("../Sources/Tekkon/include/"),
.headerSearchPath("../utils/unittest/googlemock/include"),
.headerSearchPath("../utils/unittest/googletest/include"),
]
),
// MARK: - GoogleTest Dependency Targets
.target(
name: "gtestlib",
path: "utils/unittest/googletest/src",
exclude: [
"gtest-death-test.cc",
"gtest-filepath.cc",
"gtest-matchers.cc",
"gtest-port.cc",
"gtest-printers.cc",
"gtest-test-part.cc",
"gtest-typed-test.cc",
"gtest.cc",
],
cxxSettings: [
.headerSearchPath("../"),
.headerSearchPath("../include"),
]
),
.target(
name: "gmocklib",
dependencies: ["gtestlib"],
path: "utils/unittest/googlemock/src",
exclude: [
"gmock-cardinalities.cc",
"gmock-internal-utils.cc",
"gmock-matchers.cc",
"gmock-spec-builders.cc",
"gmock.cc",
],
cxxSettings: [
.headerSearchPath("../"),
.headerSearchPath("../include"),
.headerSearchPath("../../googletest/include"),
]
),
],
cxxLanguageStandard: .cxx17
)
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
- [僅 Apple 平台] 使用 Xcode 的話,須至少 Xcode 15.1。 // Xcode 15.0 因為 Bug 太多的原因不推薦使用。

該專案推薦使用的單元測試手段:
- [僅 Apple 平台] SPM 單元測試,直接使用上文提到的 SPM 或 Xcode 即可。
- [跨平台 OS] GoogleTests,詳見 GTests 目錄下的內容。
- 但因為 GoogleTests 官方程式包 Archive 無法在某些國家和地區穩定獲取的緣故,敝倉庫不推薦在這些市場使用這個測試手段。
- SPM 的單元測試是 Objective-C 寫的,但 SPM 在非 Apple 平台下無法使用 ObjC 來完成單元測試。
- [跨平台 OS] SPM 單元測試「`TekkonCC_GTests`」(使用倉庫內建的 GoogleTest),直接運行「`swift run TekkonCC_GTests`」。
- [僅 Apple 平台] SPM 單元測試「`TekkonCCTests`」,直接使用上文提到的 SPM 或 Xcode 即可。
- [跨平台 OS] 使用 Google 官方的 Git 倉庫提供的 GoogleTests,詳見倉庫根目錄下的「`GoogleTest.sh`」與「`CMakeLists.txt`」檔案。
- 因為 GoogleTests 官方程式包 Archive 無法在某些國家和地區穩定獲取的緣故,敝倉庫不推薦在這些市場使用這個測試手段。請直接「`swift run TekkonCC_GTests`」。
- SPM 的「`TekkonCCTests`」單元測試是 Objective-C 寫的,但 SPM 在非 Apple 平台下無法使用 ObjC 來完成單元測試。此時請用上文提到的「`TekkonCC_GTests`」。

> 注意:該引擎會將「ㄅㄨㄥ ㄆㄨㄥ ㄇㄨㄥ ㄈㄨㄥ」這四種讀音自動轉換成「ㄅㄥ ㄆㄥ ㄇㄥ ㄈㄥ」、將「ㄅㄨㄛ ㄆㄨㄛ ㄇㄨㄛ ㄈㄨㄛ」這四種讀音自動轉換成「ㄅㄛ ㄆㄛ ㄇㄛ ㄈㄛ」。如果您正在開發的輸入法的詞庫內的「甮」字的讀音沒有從「ㄈㄨㄥˋ」改成「ㄈㄥˋ」、或者說需要保留「ㄈㄨㄥˋ」的讀音的話,請按需修改「receiveKeyfromPhonabet()」函式當中的相關步驟、來跳過該轉換。該情形為十分罕見之情形。類似情形則是台澎金馬審音的慣用讀音「ㄌㄩㄢˊ」,因為使用者眾、所以不會被該引擎自動轉換成「ㄌㄨㄢˊ」。威注音輸入法內部已經從辭典角度做了處理、允許在敲「ㄌㄨㄢˊ」的時候出現以「ㄌㄩㄢˊ」為讀音的漢字。我們鼓勵輸入法開發者們使用 [威注音語彙庫](https://gitee.com/vChewing/libvchewing-data) 來實現對兩岸讀音習慣的同時兼顧。
Expand Down
28 changes: 28 additions & 0 deletions utils/unittest/googlemock/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright 2008, Google Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 changes: 23 additions & 0 deletions utils/unittest/googlemock/README.LLVM
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
LLVM notes
----------

This directory contains the 'googlemock' component of Google Test 1.10.0, with
all elements removed except for the actual source code, to minimize the
addition to the LLVM distribution.

Cleaned up as follows:

# Remove all the unnecessary files and directories
$ rm -f CMakeLists.txt configure* Makefile* CHANGES CONTRIBUTORS README README.md .gitignore
$ rm -rf build-aux make msvc scripts test docs
$ rm -f `find . -name \*\.pump`
$ rm -f src/gmock_main.cc

# Put the license in the consistent place for LLVM.
$ mv LICENSE LICENSE.TXT

Modified as follows:
* Support for std::begin/std::end in gmock-matchers.h
* IWYU pragmas
* Disabled -Wdeprecated-copy for clang
* Added IWYU pragmas from https://github.com/google/googletest/commit/100f6fbf5f81a82d163c1e29735e8a2936eacd4f
Loading

0 comments on commit ffe9f3d

Please sign in to comment.