From 697e9351e82fd150fe178bc6e94fc247331163d7 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 3 May 2020 19:40:42 -0700 Subject: [PATCH] build: support the test suite on Windows --- CMakeLists.txt | 4 ++ Tests/CMakeLists.txt | 24 ++++++++++ Tests/ComplexTests/CMakeLists.txt | 21 +++++++++ Tests/RealTests/CMakeLists.txt | 19 ++++++++ Tests/WindowsMain.swift | 76 +++++++++++++++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 Tests/CMakeLists.txt create mode 100644 Tests/ComplexTests/CMakeLists.txt create mode 100644 Tests/RealTests/CMakeLists.txt create mode 100644 Tests/WindowsMain.swift diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d22626..e0e8058 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,9 +18,13 @@ 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) +include(CTest) include(SwiftSupport) add_subdirectory(Sources) +if(BUILD_TESTING) + add_subdirectory(Tests) +endif() get_property(SWIFT_NUMERICS_EXPORTS GLOBAL PROPERTY SWIFT_NUMERICS_EXPORTS) export(TARGETS ${SWIFT_NUMERICS_EXPORTS} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt new file mode 100644 index 0000000..b879f0e --- /dev/null +++ b/Tests/CMakeLists.txt @@ -0,0 +1,24 @@ +#[[ +This source file is part of the Swift Numerics open source project + +Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors +Licensed under Apache License v2.0 with Runtime Library Exception + +See https://swift.org/LICENSE.txt for license information +#]] + +find_package(dispatch CONFIG QUIET) +find_package(Foundation CONFIG QUIET) +find_package(XCTest CONFIG QUIET) + +add_subdirectory(ComplexTests) +add_subdirectory(RealTests) + +add_executable(SwiftNumericsTestRunner + WindowsMain.swift) +target_link_libraries(SwiftNumericsTestRunner PRIVATE + ComplexTests + RealTests) + +add_test(NAME SwiftNumericsTestRunner + COMMAND SwiftNumericsTestRunner) diff --git a/Tests/ComplexTests/CMakeLists.txt b/Tests/ComplexTests/CMakeLists.txt new file mode 100644 index 0000000..88502cf --- /dev/null +++ b/Tests/ComplexTests/CMakeLists.txt @@ -0,0 +1,21 @@ +#[[ +This source file is part of the Swift Numerics open source project + +Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors +Licensed under Apache License v2.0 with Runtime Library Exception + +See https://swift.org/LICENSE.txt for license information +#]] + +add_library(ComplexTests + ArithmeticTests.swift + DifferentiableTests.swift + PropertyTests.swift) +set_target_properties(ComplexTests PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +target_compile_options(ComplexTests PRIVATE + -enable-testing) +target_link_libraries(ComplexTests PUBLIC + $<$>:Foundation> + ComplexModule + XCTest) diff --git a/Tests/RealTests/CMakeLists.txt b/Tests/RealTests/CMakeLists.txt new file mode 100644 index 0000000..53c9a4f --- /dev/null +++ b/Tests/RealTests/CMakeLists.txt @@ -0,0 +1,19 @@ +#[[ +This source file is part of the Swift Numerics open source project + +Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors +Licensed under Apache License v2.0 with Runtime Library Exception + +See https://swift.org/LICENSE.txt for license information +#]] + +add_library(RealTests + IntegerExponentTests.swift + RealTests.swift + RealTestSupport.swift) +target_compile_options(RealTests PRIVATE + -enable-testing) +target_link_libraries(RealTests PUBLIC + $<$>:Foundation> + RealModule + XCTest) diff --git a/Tests/WindowsMain.swift b/Tests/WindowsMain.swift new file mode 100644 index 0000000..9414d23 --- /dev/null +++ b/Tests/WindowsMain.swift @@ -0,0 +1,76 @@ +//===--- WindowsMain.swift ------------------------------------*- swift -*-===// +// +// This source file is part of the Swift Numerics open source project +// +// Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +#if os(Windows) +import XCTest + +@testable +import RealTests + +@testable +import ComplexTests + +extension ElementaryFunctionChecks { + static var all = testCase([ + ("testFloat", ElementaryFunctionChecks.testFloat), + ("testDouble", ElementaryFunctionChecks.testDouble), + ]) +} + +extension IntegerExponentTests { + static var all = testCase([ + ("testFloat", IntegerExponentTests.testFloat), + ("testDouble", IntegerExponentTests.testDouble), + ]) +} + +extension ArithmeticTests { + static var all = testCase([ + ("testPolar", ArithmeticTests.testPolar), + ("testBaudinSmith", ArithmeticTests.testBaudinSmith), + ("testDivisionByZero", ArithmeticTests.testDivisionByZero), + ]) +} + +#if canImport(_Differentiation) + extension DifferentiableTests { + static var all = testCase([ + ("testComponentGetter", DifferentiableTests.testComponentGetter), + ("testConjugate", DifferentiableTests.testConjugate), + ("testArithmetics", DifferentiableTests.testArithmetics), + ]) + } +#endif + +extension PropertyTests { + static var all = testCase([ + ("testProperties", PropertyTests.testProperties), + ("testEquatableHashable", PropertyTests.testEquatableHashable), + ("testCodable", PropertyTests.testCodable), + ]) +} + +var testCases = [ + ElementaryFunctionChecks.all, + IntegerExponentTests.all, + ArithmeticTests.all, + PropertyTests.all, +] + +#if canImport(_Differentiation) +testCases += [ + DifferentiableTests.all +] +#endif + +XCTMain(testCases) + +#endif