Skip to content

Commit

Permalink
build: support the test suite on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
compnerd committed Jun 25, 2020
1 parent f30f73e commit 697e935
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
24 changes: 24 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 21 additions & 0 deletions Tests/ComplexTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
ComplexModule
XCTest)
19 changes: 19 additions & 0 deletions Tests/RealTests/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 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
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
RealModule
XCTest)
76 changes: 76 additions & 0 deletions Tests/WindowsMain.swift
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 697e935

Please sign in to comment.