Skip to content

Commit

Permalink
[cmake] Make unittests build with swift-testing using CMake.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdav committed Apr 26, 2024
1 parent 0ab5d32 commit 2c62c38
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
/.build
/build
/b
/Packages
xcuserdata/
DerivedData/
Expand Down
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

option(SWIFT_WEBDRIVER_BUILD_WINAPPDRIVER "Build WinAppDriver functionality." TRUE)
option(SWIFT_WEBDRIVER_BUILD_WINAPPDRIVER "Build WinAppDriver functionality." YES)
option(SWIFT_WEBDRIVER_USE_SWIFT_TESTING "Use Swift Testing framework for testing." NO)

add_subdirectory(Sources/WebDriver)
if(BUILD_TESTING)
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-enable-testing>)
endif()

add_subdirectory(Vendor)
add_subdirectory(Sources/WebDriver)
if(SWIFT_WEBDRIVER_BUILD_WINAPPDRIVER)
add_subdirectory(Sources/WinAppDriver)
endif()
if(BUILD_TESTING)
add_subdirectory(Tests)
endif()
18 changes: 18 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SwiftTesting_GenerateDerivedSources()
message(STATUS "swiftwebdriver_SwiftTesting_Sources: ${swiftwebdriver_SwiftTesting_Sources}")
message(STATUS "SwiftTesting_TestingMacrosPath: ${SwiftTesting_TestingMacrosPath}")

add_library(TestsCommon
Common/PNGUtilities.swift)

add_executable(SwiftWebdriverPackageTests
UnitTests/APITests.swift
UnitTests/MockWebDriver.swift
${swiftwebdriver_SwiftTesting_Sources})
set_target_properties(SwiftWebdriverPackageTests PROPERTIES
SUFFIX .swift-testing)
target_link_libraries(SwiftWebdriverPackageTests PRIVATE
WebDriver
Testing
TestingInternals
TestsCommon)
9 changes: 9 additions & 0 deletions Vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include(FetchContent)

# Ignore warnings from dependencies' source code.
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-suppress-warnings>)
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-suppress-remarks>)

if(BUILD_TESTING AND SWIFT_WEBDRIVER_USE_SWIFT_TESTING)
include(SwiftTesting.cmake)
endif()
10 changes: 10 additions & 0 deletions Vendor/SwiftTesting.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FetchContent_Declare(SwiftTesting
# GIT_REPOSITORY https://github.com/apple/swift-testing.git
# GIT_TAG e07ef28413b5be951fa5672b290bc10fa2e3cd65)
GIT_REPOSITORY https://github.com/thebrowsercompany/swift-testing.git
GIT_TAG a191e1d53eee05a3dbe2447ca10bab0a617fad82)
FetchContent_GetProperties(SwiftTesting)
if(NOT SwiftTesting_POPULATED)
message(STATUS "syncing SwiftTesting")
FetchContent_MakeAvailable(SwiftTesting)
endif()

0 comments on commit 2c62c38

Please sign in to comment.