From 7a957c209e1eff73cf367649794ffb56c2344312 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 26 Apr 2024 15:51:56 -0700 Subject: [PATCH] [cmake] Make unittests build with swift-testing using CMake. --- .gitignore | 1 + CMakeLists.txt | 12 ++++++++++-- Tests/CMakeLists.txt | 15 +++++++++++++++ Vendor/CMakeLists.txt | 9 +++++++++ Vendor/SwiftTesting.cmake | 10 ++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Tests/CMakeLists.txt create mode 100644 Vendor/CMakeLists.txt create mode 100644 Vendor/SwiftTesting.cmake diff --git a/.gitignore b/.gitignore index 803dd3a..4405fd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store /.build /build +/b /Packages xcuserdata/ DerivedData/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 48eb8d5..2946885 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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($<$:-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() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt new file mode 100644 index 0000000..f9392de --- /dev/null +++ b/Tests/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(TestsCommon + Common/PNGUtilities.swift) + +SwiftTesting_GenerateDerivedSources() +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) diff --git a/Vendor/CMakeLists.txt b/Vendor/CMakeLists.txt new file mode 100644 index 0000000..8f617d4 --- /dev/null +++ b/Vendor/CMakeLists.txt @@ -0,0 +1,9 @@ +include(FetchContent) + +# Ignore warnings from dependencies' source code. +add_compile_options($<$:-suppress-warnings>) +add_compile_options($<$:-suppress-remarks>) + +if(BUILD_TESTING AND SWIFT_WEBDRIVER_USE_SWIFT_TESTING) + include(SwiftTesting.cmake) +endif() diff --git a/Vendor/SwiftTesting.cmake b/Vendor/SwiftTesting.cmake new file mode 100644 index 0000000..eba8696 --- /dev/null +++ b/Vendor/SwiftTesting.cmake @@ -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()