Skip to content

Commit

Permalink
Merge pull request #144 from stephentyrone/test-support
Browse files Browse the repository at this point in the history
Factor test support out into a module
  • Loading branch information
stephentyrone authored Aug 24, 2020
2 parents 4077cd3 + a4372aa commit fa16d7d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 10 deletions.
8 changes: 5 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
]
)
3 changes: 3 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ add_subdirectory(_NumericsShims)
add_subdirectory(ComplexModule)
add_subdirectory(Numerics)
add_subdirectory(RealModule)
if(BUILD_TESTING)
add_subdirectory(_TestSupport)
endif()
19 changes: 19 additions & 0 deletions Sources/_TestSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
public func assertClose<T>(
_ expected: TestLiteralType,
_ observed: T,
allowedError: T = 16,
Expand Down Expand Up @@ -69,7 +69,7 @@ func assertClose<T>(
return ulps
}

func assertClose<T>(
public func assertClose<T>(
_ expected: TestLiteralType,
_ observed: T,
allowedError: T = 16,
Expand All @@ -82,7 +82,7 @@ func assertClose<T>(
))
}

internal protocol FixedWidthFloatingPoint: BinaryFloatingPoint
public protocol FixedWidthFloatingPoint: BinaryFloatingPoint
where Exponent: FixedWidthInteger,
RawSignificand: FixedWidthInteger { }

Expand Down
1 change: 1 addition & 0 deletions Tests/ComplexTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ target_link_libraries(ComplexTests PUBLIC
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
ComplexModule
Numerics
_TestSupport
XCTest)
1 change: 1 addition & 0 deletions Tests/RealTests/ApproximateEqualityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import RealModule
import XCTest
import _TestSupport

final class ApproximateEqualityTests: XCTestCase {

Expand Down
4 changes: 2 additions & 2 deletions Tests/RealTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
RealModule
_TestSupport
XCTest)
1 change: 1 addition & 0 deletions Tests/RealTests/ElementaryFunctionChecks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import XCTest
import RealModule
import _TestSupport

internal extension ElementaryFunctions where Self: BinaryFloatingPoint {
static func elementaryFunctionChecks() {
Expand Down
1 change: 1 addition & 0 deletions Tests/RealTests/IntegerExponentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import XCTest
import RealModule
import _TestSupport

internal extension Real where Self: FixedWidthFloatingPoint {

Expand Down

0 comments on commit fa16d7d

Please sign in to comment.