Skip to content

Commit fa16d7d

Browse files
Merge pull request #144 from stephentyrone/test-support
Factor test support out into a module
2 parents 4077cd3 + a4372aa commit fa16d7d

File tree

9 files changed

+38
-10
lines changed

9 files changed

+38
-10
lines changed

Package.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ let package = Package(
2424
targets: [
2525
.target(name: "ComplexModule", dependencies: ["RealModule"]),
2626
.target(name: "Numerics", dependencies: ["ComplexModule", "RealModule"]),
27-
.target(name: "_NumericsShims", dependencies: []),
2827
.target(name: "RealModule", dependencies: ["_NumericsShims"]),
2928

30-
.testTarget(name: "ComplexTests", dependencies: ["Numerics"]),
31-
.testTarget(name: "RealTests", dependencies: ["RealModule"]),
29+
.target(name: "_NumericsShims", dependencies: []),
30+
.target(name: "_TestSupport", dependencies: ["Numerics"]),
31+
32+
.testTarget(name: "ComplexTests", dependencies: ["_TestSupport"]),
33+
.testTarget(name: "RealTests", dependencies: ["_TestSupport"]),
3234
]
3335
)

Sources/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ add_subdirectory(_NumericsShims)
1111
add_subdirectory(ComplexModule)
1212
add_subdirectory(Numerics)
1313
add_subdirectory(RealModule)
14+
if(BUILD_TESTING)
15+
add_subdirectory(_TestSupport)
16+
endif()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019-2020 Apple Inc. and the Swift Numerics project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
add_library(_TestSupport
11+
RealTestSupport.swift)
12+
set_target_properties(_TestSupport PROPERTIES
13+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
14+
target_link_libraries(_TestSupport PUBLIC
15+
Numerics)
16+
17+
18+
_install_target(_TestSupport)
19+
set_property(GLOBAL APPEND PROPERTY SWIFT_NUMERICS_EXPORTS _TestSupport)

Tests/RealTests/RealTestSupport.swift renamed to Sources/_TestSupport/RealTestSupport.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import XCTest
1313
import RealModule
1414

1515
#if (arch(i386) || arch(x86_64)) && !os(Windows) && !os(Android)
16-
typealias TestLiteralType = Float80
16+
public typealias TestLiteralType = Float80
1717
#else
18-
typealias TestLiteralType = Double
18+
public typealias TestLiteralType = Double
1919
#endif
2020

2121
@discardableResult
22-
func assertClose<T>(
22+
public func assertClose<T>(
2323
_ expected: TestLiteralType,
2424
_ observed: T,
2525
allowedError: T = 16,
@@ -69,7 +69,7 @@ func assertClose<T>(
6969
return ulps
7070
}
7171

72-
func assertClose<T>(
72+
public func assertClose<T>(
7373
_ expected: TestLiteralType,
7474
_ observed: T,
7575
allowedError: T = 16,
@@ -82,7 +82,7 @@ func assertClose<T>(
8282
))
8383
}
8484

85-
internal protocol FixedWidthFloatingPoint: BinaryFloatingPoint
85+
public protocol FixedWidthFloatingPoint: BinaryFloatingPoint
8686
where Exponent: FixedWidthInteger,
8787
RawSignificand: FixedWidthInteger { }
8888

Tests/ComplexTests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ target_link_libraries(ComplexTests PUBLIC
2020
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
2121
ComplexModule
2222
Numerics
23+
_TestSupport
2324
XCTest)

Tests/RealTests/ApproximateEqualityTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import RealModule
1414
import XCTest
15+
import _TestSupport
1516

1617
final class ApproximateEqualityTests: XCTestCase {
1718

Tests/RealTests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ See https://swift.org/LICENSE.txt for license information
1010
add_library(RealTests
1111
ApproximateEqualityTests.swift
1212
ElementaryFunctionChecks.swift
13-
IntegerExponentTests.swift
14-
RealTestSupport.swift)
13+
IntegerExponentTests.swift)
1514
target_compile_options(RealTests PRIVATE
1615
-enable-testing)
1716
target_link_libraries(RealTests PUBLIC
1817
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
1918
RealModule
19+
_TestSupport
2020
XCTest)

Tests/RealTests/ElementaryFunctionChecks.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import XCTest
1313
import RealModule
14+
import _TestSupport
1415

1516
internal extension ElementaryFunctions where Self: BinaryFloatingPoint {
1617
static func elementaryFunctionChecks() {

Tests/RealTests/IntegerExponentTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import XCTest
1313
import RealModule
14+
import _TestSupport
1415

1516
internal extension Real where Self: FixedWidthFloatingPoint {
1617

0 commit comments

Comments
 (0)