From c2d6cb716d4377532952ddcc29caffb806738806 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Mon, 24 Aug 2020 16:12:57 -0400 Subject: [PATCH 1/3] Factor test support out into a module so Real and Complex tests can use it. --- Package.swift | 8 +++++--- Sources/_TestSupport/CMakeLists.txt | 19 +++++++++++++++++++ .../_TestSupport}/RealTestSupport.swift | 10 +++++----- Tests/ComplexTests/CMakeLists.txt | 1 + .../RealTests/ApproximateEqualityTests.swift | 1 + Tests/RealTests/CMakeLists.txt | 4 ++-- .../RealTests/ElementaryFunctionChecks.swift | 1 + Tests/RealTests/IntegerExponentTests.swift | 1 + 8 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 Sources/_TestSupport/CMakeLists.txt rename {Tests/RealTests => Sources/_TestSupport}/RealTestSupport.swift (94%) diff --git a/Package.swift b/Package.swift index 20b8553..abb86c5 100644 --- a/Package.swift +++ b/Package.swift @@ -24,10 +24,12 @@ let package = Package( targets: [ .target(name: "ComplexModule", dependencies: ["RealModule"]), .target(name: "Numerics", dependencies: ["ComplexModule", "RealModule"]), - .target(name: "_NumericsShims", dependencies: []), .target(name: "RealModule", dependencies: ["_NumericsShims"]), - .testTarget(name: "ComplexTests", dependencies: ["Numerics"]), - .testTarget(name: "RealTests", dependencies: ["RealModule"]), + .target(name: "_NumericsShims", dependencies: []), + .target(name: "_TestSupport", dependencies: ["Numerics"]), + + .testTarget(name: "ComplexTests", dependencies: ["_TestSupport"]), + .testTarget(name: "RealTests", dependencies: ["_TestSupport"]), ] ) diff --git a/Sources/_TestSupport/CMakeLists.txt b/Sources/_TestSupport/CMakeLists.txt new file mode 100644 index 0000000..a42242d --- /dev/null +++ b/Sources/_TestSupport/CMakeLists.txt @@ -0,0 +1,19 @@ +#[[ +This source file is part of the Swift Numerics open source project + +Copyright (c) 2019-2020 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(TestSupport + RealTestSupport.swift) +set_target_properties(TestSupport PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +target_link_libraries(TestSupport PUBLIC + Numerics) + + +_install_target(TestSupport) +set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS TestSupport) diff --git a/Tests/RealTests/RealTestSupport.swift b/Sources/_TestSupport/RealTestSupport.swift similarity index 94% rename from Tests/RealTests/RealTestSupport.swift rename to Sources/_TestSupport/RealTestSupport.swift index edc4b16..3e65fdb 100644 --- a/Tests/RealTests/RealTestSupport.swift +++ b/Sources/_TestSupport/RealTestSupport.swift @@ -13,13 +13,13 @@ import XCTest import RealModule #if (arch(i386) || arch(x86_64)) && !os(Windows) && !os(Android) -typealias TestLiteralType = Float80 +public typealias TestLiteralType = Float80 #else -typealias TestLiteralType = Double +public typealias TestLiteralType = Double #endif @discardableResult -func assertClose( +public func assertClose( _ expected: TestLiteralType, _ observed: T, allowedError: T = 16, @@ -69,7 +69,7 @@ func assertClose( return ulps } -func assertClose( +public func assertClose( _ expected: TestLiteralType, _ observed: T, allowedError: T = 16, @@ -82,7 +82,7 @@ func assertClose( )) } -internal protocol FixedWidthFloatingPoint: BinaryFloatingPoint +public protocol FixedWidthFloatingPoint: BinaryFloatingPoint where Exponent: FixedWidthInteger, RawSignificand: FixedWidthInteger { } diff --git a/Tests/ComplexTests/CMakeLists.txt b/Tests/ComplexTests/CMakeLists.txt index d3b7b69..320af13 100644 --- a/Tests/ComplexTests/CMakeLists.txt +++ b/Tests/ComplexTests/CMakeLists.txt @@ -20,4 +20,5 @@ target_link_libraries(ComplexTests PUBLIC $<$>:Foundation> ComplexModule Numerics + _TestSupport XCTest) diff --git a/Tests/RealTests/ApproximateEqualityTests.swift b/Tests/RealTests/ApproximateEqualityTests.swift index 7009b81..bf126cb 100644 --- a/Tests/RealTests/ApproximateEqualityTests.swift +++ b/Tests/RealTests/ApproximateEqualityTests.swift @@ -12,6 +12,7 @@ import RealModule import XCTest +import _TestSupport final class ApproximateEqualityTests: XCTestCase { diff --git a/Tests/RealTests/CMakeLists.txt b/Tests/RealTests/CMakeLists.txt index ec989f3..e7ea4ff 100644 --- a/Tests/RealTests/CMakeLists.txt +++ b/Tests/RealTests/CMakeLists.txt @@ -10,11 +10,11 @@ See https://swift.org/LICENSE.txt for license information add_library(RealTests ApproximateEqualityTests.swift ElementaryFunctionChecks.swift - IntegerExponentTests.swift - RealTestSupport.swift) + IntegerExponentTests.swift) target_compile_options(RealTests PRIVATE -enable-testing) target_link_libraries(RealTests PUBLIC $<$>:Foundation> RealModule + _TestSupport XCTest) diff --git a/Tests/RealTests/ElementaryFunctionChecks.swift b/Tests/RealTests/ElementaryFunctionChecks.swift index 5eb5842..b72aa04 100644 --- a/Tests/RealTests/ElementaryFunctionChecks.swift +++ b/Tests/RealTests/ElementaryFunctionChecks.swift @@ -11,6 +11,7 @@ import XCTest import RealModule +import _TestSupport internal extension ElementaryFunctions where Self: BinaryFloatingPoint { static func elementaryFunctionChecks() { diff --git a/Tests/RealTests/IntegerExponentTests.swift b/Tests/RealTests/IntegerExponentTests.swift index dad7485..3ddf627 100644 --- a/Tests/RealTests/IntegerExponentTests.swift +++ b/Tests/RealTests/IntegerExponentTests.swift @@ -11,6 +11,7 @@ import XCTest import RealModule +import _TestSupport internal extension Real where Self: FixedWidthFloatingPoint { From 145156c40e2c0e52d475e37112c287f7690a2190 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Mon, 24 Aug 2020 16:50:10 -0400 Subject: [PATCH 2/3] Fix suggested by Saleem in review. --- Sources/_TestSupport/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/_TestSupport/CMakeLists.txt b/Sources/_TestSupport/CMakeLists.txt index a42242d..e1d7d9a 100644 --- a/Sources/_TestSupport/CMakeLists.txt +++ b/Sources/_TestSupport/CMakeLists.txt @@ -7,13 +7,13 @@ Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] -add_library(TestSupport +add_library(_TestSupport RealTestSupport.swift) -set_target_properties(TestSupport PROPERTIES +set_target_properties(_TestSupport PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) -target_link_libraries(TestSupport PUBLIC +target_link_libraries(_TestSupport PUBLIC Numerics) -_install_target(TestSupport) -set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS TestSupport) +_install_target(_TestSupport) +set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS _TestSupport) From a4372aa8d62c4270f893857aba696113e4962da8 Mon Sep 17 00:00:00 2001 From: Stephen Canon Date: Mon, 24 Aug 2020 18:31:12 -0400 Subject: [PATCH 3/3] Added change suggested by Saleem for Windows/CMake build. --- Sources/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 4107e69..c7cbf9d 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -11,3 +11,6 @@ add_subdirectory(_NumericsShims) add_subdirectory(ComplexModule) add_subdirectory(Numerics) add_subdirectory(RealModule) +if(BUILD_TESTING) + add_subdirectory(_TestSupport) +endif()