Skip to content

Commit 697e935

Browse files
committed
build: support the test suite on Windows
1 parent f30f73e commit 697e935

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1818
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
1919
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
2020

21+
include(CTest)
2122
include(SwiftSupport)
2223

2324
add_subdirectory(Sources)
25+
if(BUILD_TESTING)
26+
add_subdirectory(Tests)
27+
endif()
2428

2529
get_property(SWIFT_NUMERICS_EXPORTS GLOBAL PROPERTY SWIFT_NUMERICS_EXPORTS)
2630
export(TARGETS ${SWIFT_NUMERICS_EXPORTS}

Tests/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 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+
find_package(dispatch CONFIG QUIET)
11+
find_package(Foundation CONFIG QUIET)
12+
find_package(XCTest CONFIG QUIET)
13+
14+
add_subdirectory(ComplexTests)
15+
add_subdirectory(RealTests)
16+
17+
add_executable(SwiftNumericsTestRunner
18+
WindowsMain.swift)
19+
target_link_libraries(SwiftNumericsTestRunner PRIVATE
20+
ComplexTests
21+
RealTests)
22+
23+
add_test(NAME SwiftNumericsTestRunner
24+
COMMAND SwiftNumericsTestRunner)

Tests/ComplexTests/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[[
2+
This source file is part of the Swift Numerics open source project
3+
4+
Copyright (c) 2019 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(ComplexTests
11+
ArithmeticTests.swift
12+
DifferentiableTests.swift
13+
PropertyTests.swift)
14+
set_target_properties(ComplexTests PROPERTIES
15+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
16+
target_compile_options(ComplexTests PRIVATE
17+
-enable-testing)
18+
target_link_libraries(ComplexTests PUBLIC
19+
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
20+
ComplexModule
21+
XCTest)

Tests/RealTests/CMakeLists.txt

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 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(RealTests
11+
IntegerExponentTests.swift
12+
RealTests.swift
13+
RealTestSupport.swift)
14+
target_compile_options(RealTests PRIVATE
15+
-enable-testing)
16+
target_link_libraries(RealTests PUBLIC
17+
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
18+
RealModule
19+
XCTest)

Tests/WindowsMain.swift

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//===--- WindowsMain.swift ------------------------------------*- swift -*-===//
2+
//
3+
// This source file is part of the Swift Numerics open source project
4+
//
5+
// Copyright (c) 2019 Apple Inc. and the Swift Numerics project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
//
10+
//===----------------------------------------------------------------------===//
11+
12+
#if os(Windows)
13+
import XCTest
14+
15+
@testable
16+
import RealTests
17+
18+
@testable
19+
import ComplexTests
20+
21+
extension ElementaryFunctionChecks {
22+
static var all = testCase([
23+
("testFloat", ElementaryFunctionChecks.testFloat),
24+
("testDouble", ElementaryFunctionChecks.testDouble),
25+
])
26+
}
27+
28+
extension IntegerExponentTests {
29+
static var all = testCase([
30+
("testFloat", IntegerExponentTests.testFloat),
31+
("testDouble", IntegerExponentTests.testDouble),
32+
])
33+
}
34+
35+
extension ArithmeticTests {
36+
static var all = testCase([
37+
("testPolar", ArithmeticTests.testPolar),
38+
("testBaudinSmith", ArithmeticTests.testBaudinSmith),
39+
("testDivisionByZero", ArithmeticTests.testDivisionByZero),
40+
])
41+
}
42+
43+
#if canImport(_Differentiation)
44+
extension DifferentiableTests {
45+
static var all = testCase([
46+
("testComponentGetter", DifferentiableTests.testComponentGetter),
47+
("testConjugate", DifferentiableTests.testConjugate),
48+
("testArithmetics", DifferentiableTests.testArithmetics),
49+
])
50+
}
51+
#endif
52+
53+
extension PropertyTests {
54+
static var all = testCase([
55+
("testProperties", PropertyTests.testProperties),
56+
("testEquatableHashable", PropertyTests.testEquatableHashable),
57+
("testCodable", PropertyTests.testCodable),
58+
])
59+
}
60+
61+
var testCases = [
62+
ElementaryFunctionChecks.all,
63+
IntegerExponentTests.all,
64+
ArithmeticTests.all,
65+
PropertyTests.all,
66+
]
67+
68+
#if canImport(_Differentiation)
69+
testCases += [
70+
DifferentiableTests.all
71+
]
72+
#endif
73+
74+
XCTMain(testCases)
75+
76+
#endif

0 commit comments

Comments
 (0)