Skip to content

Commit f4a5ffc

Browse files
authored
Use gtest instead of check for C tests (#1527)
There are a few issues with using the check library to test the C language bindings: 1. check does not appear to be actively maintained 2. The latest version of check does not compile with recent versions of MinGW64 3. check only used by libsbp; all of the other swift repos have switched over to gtest This PR converts the C language bindings to use gtest, which means compiling the unit tests as C++ instead of C.
1 parent 017cd6d commit f4a5ffc

File tree

499 files changed

+113075
-131293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

499 files changed

+113075
-131293
lines changed

.github/workflows/c.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
CC: mips-linux-gnu-gcc
132132
CXX: mips-linux-gnu-g++
133133

134-
CMAKEFLAGS: -DCMAKE_EXE_LINKER_FLAGS_RELEASE="-static" -Dgtest_disable_pthreads=ON
134+
CMAKEFLAGS: -DCMAKE_EXE_LINKER_FLAGS="-static" -Dgtest_disable_pthreads=ON
135135

136136
bazel:
137137
name: Bazel

.github/workflows/generator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
3737
- name: Generate tests
3838
run: |
39-
rm c/test/auto_check_*.c c/test/cpp/auto_check_*.cc java/test/auto_check_*.java rust/sbp/tests/integration/auto_check_*.rs
39+
rm c/test/auto_check_*.cc c/test/cpp/auto_check_*.cc java/test/auto_check_*.java rust/sbp/tests/integration/auto_check_*.rs
4040
make gen-c gen-java gen-rust gen-jsonschema gen-haskell gen-python gen-javascript gen-protobuf
4141
make quicktype
4242

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
[submodule "c/cmake/common"]
22
path = c/cmake/common
33
url = https://github.com/swift-nav/cmake.git
4-
[submodule "c/third_party/check"]
5-
path = c/third_party/check
6-
url = https://github.com/swift-nav/check.git
74
[submodule "c/third_party/googletest"]
85
path = c/third_party/googletest
96
url = https://github.com/google/googletest.git

MODULE.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ register_toolchains(
2727
"@rules_swiftnav//cc/toolchains/llvm/x86_64-darwin:cc-toolchain-x86_64-darwin",
2828
)
2929

30-
bazel_dep(name = "check", version = "0.15.2.bcr.1", dev_dependency = True)
3130
bazel_dep(name = "googletest", version = "1.13.0", dev_dependency = True)
3231

3332
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)

WORKSPACE.bazel

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,3 @@ local_repository(
5757
name = "googletest",
5858
path = "c/third_party/googletest",
5959
)
60-
61-
new_local_repository(
62-
name = "check",
63-
build_file = "@rules_swiftnav//third_party:check.BUILD",
64-
path = "c/third_party/check",
65-
)

c/BUILD.bazel

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ filegroup(
6060
visibility = ["//visibility:public"],
6161
)
6262

63-
SBP_C_SOURCES = glob(["test/auto*.c"])
63+
SBP_C_SOURCES = glob(["test/auto*.cc"])
6464

65-
swift_c_test(
65+
swift_cc_test(
6666
name = "sbp-test",
6767
srcs = [
68-
"test/check_main.c",
69-
"test/check_edc.c",
70-
"test/check_sbp.c",
71-
"test/check_bitfield_macros.c",
72-
"test/check_suites.h",
68+
"test/test_edc.cc",
69+
"test/test_sbp.cc",
70+
"test/test_bitfield_macros.cc",
71+
"test/test_utils.cc",
72+
"test/test_utils.h",
7373
] + SBP_C_SOURCES,
7474
includes = ["include/libsbp"],
7575
type = UNIT,
7676
deps = [
7777
":sbp",
78-
"@check",
78+
"@googletest//:gtest_main",
7979
],
8080
)
8181

c/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ include(ClangTidy)
1515
swift_create_project_options(
1616
HAS_TESTS
1717
HAS_DOCS
18-
TEST_PACKAGES "Check"
18+
TEST_PACKAGES "Googletest"
1919
)
2020
include(CodeCoverage)
2121
include(SwiftTargets)
2222
include(TestTargets)
2323
add_code_coverage_all_targets()
2424
# TODO: Reformatting is limited to generated files; it should be expanded to cover all files
25-
swift_setup_clang_format(PATTERNS 'include/*.h' 'test/*.c' 'test/*.h' 'test/cpp/*.cc')
25+
swift_setup_clang_format(PATTERNS 'include/*.h' 'test/*.cc' 'test/*.h' 'test/cpp/*.cc')
2626

2727
if(libsbp_BUILD_TESTS)
2828
find_package(Googletest)

c/scripts/clang-format.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ set -e -x
88
GENERATED_HEADERS=$(grep -rl --include="*.h" "Automatically generated" include/libsbp/* src/)
99
GENERATED_C_SOURCES=$(grep -rl --include="*.c" "Automatically generated" src/)
1010
CLANG_FORMAT=clang-format-11
11-
$CLANG_FORMAT -i $GENERATED_HEADERS $GENERATED_C_SOURCES test/*.c test/*.h test/auto* test/cpp/auto*
11+
$CLANG_FORMAT -i $GENERATED_HEADERS $GENERATED_C_SOURCES test/*.cc test/*.h test/auto* test/cpp/auto*

c/test/CMakeLists.txt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
find_package(Threads)
2-
set(TEST_LIBS ${TEST_LIBS} check Threads::Threads swiftnav::sbp)
2+
set(TEST_LIBS ${TEST_LIBS} gtest_main Threads::Threads swiftnav::sbp)
33

44
# Check needs to be linked against Librt on Linux
55
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
66
set(TEST_LIBS ${TEST_LIBS} rt)
77
endif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
88

9-
FILE(GLOB generated_c_sources auto*.c)
9+
FILE(GLOB generated_c_sources auto*.cc)
1010

1111
set(TEST_INCLUDES ${PROJECT_SOURCE_DIR}/include/libsbp)
1212

@@ -26,24 +26,20 @@ endif()
2626
swift_add_test(test-libsbp
2727
UNIT_TEST
2828
SRCS
29-
check_main.c
30-
check_edc.c
31-
check_sbp.c
32-
check_bitfield_macros.c
29+
test_edc.cc
30+
test_sbp.cc
31+
test_bitfield_macros.cc
32+
test_utils.cc
3333
${generated_c_sources}
3434
INCLUDE
3535
${TEST_INCLUDES}
3636
LINK
3737
${TEST_LIBS}
3838
)
39+
swift_set_language_standards(test-libsbp)
3940
swift_set_compile_options(test-libsbp
4041
REMOVE
41-
-Wpointer-arith
42-
-Wformat
43-
-Wformat-security
44-
-Wformat-y2k
45-
ADD
46-
-Wformat=0
42+
-Wdisabled-optimization
4743
)
4844

4945
add_subdirectory(cpp)

c/test/auto_check_sbp_acquisition_MsgAcqResult.c

Lines changed: 0 additions & 178 deletions
This file was deleted.

0 commit comments

Comments
 (0)