Merge pull request #252 from compnerd/separation-anxiety
Tests: adjust paths for Windows
diff --git a/.gitignore b/.gitignore
index 2e3f3e3..1f07c20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.*.sw[nop]
.DS_Store
xcuserdata
*.xcscmblueprint
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aa705ba..e16cd14 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,8 @@
LANGUAGES
C)
+option(BUILD_SHARED_LIBS "Build shared libraries" ON)
+
option(XCTEST_PATH_TO_LIBDISPATCH_SOURCE "Path to libdispatch source" "")
option(XCTEST_PATH_TO_LIBDISPATCH_BUILD "Path to libdispatch build" "")
@@ -127,11 +129,12 @@
"Copying swiftmodule/swiftdoc to build directory")
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
- set(LIT_COMMAND "${PYTHON_EXECUTABLE};${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py"
+ set(LIT_COMMAND "${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py"
CACHE STRING "command used to spawn llvm-lit")
else()
find_program(LIT_COMMAND NAMES llvm-lit lit.py lit)
endif()
+find_package(PythonInterp)
add_custom_target(check-xctest
COMMAND
${CMAKE_COMMAND} -E env
@@ -142,7 +145,7 @@
LIBDISPATCH_BUILD_DIR=${XCTEST_PATH_TO_LIBDISPATCH_BUILD}
LIBDISPATCH_OVERLAY_DIR=${XCTEST_PATH_TO_LIBDISPATCH_BUILD}/src/swift
SWIFT_EXEC=${CMAKE_SWIFT_COMPILER}
- ${LIT_COMMAND} -sv ${CMAKE_SOURCE_DIR}/Tests/Functional
+ ${PYTHON_EXECUTABLE} ${LIT_COMMAND} -sv ${CMAKE_SOURCE_DIR}/Tests/Functional
COMMENT
"Running XCTest functional test suite"
DEPENDS
diff --git a/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift b/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift
index 0a404c5..13a232f 100644
--- a/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift
+++ b/Sources/XCTest/Public/Asynchronous/XCTWaiter.swift
@@ -217,9 +217,9 @@
self.manager = manager
// Begin the core wait loop.
- let timeoutTimestamp = CFAbsoluteTimeGetCurrent() + timeout
+ let timeoutTimestamp = Date.timeIntervalSinceReferenceDate + timeout
while !isFinished {
- let remaining = timeoutTimestamp - CFAbsoluteTimeGetCurrent()
+ let remaining = timeoutTimestamp - Date.timeIntervalSinceReferenceDate
if remaining <= 0 {
break
}
@@ -367,7 +367,11 @@
func cancelPrimitiveWait() {
guard let runLoop = runLoop else { return }
+#if os(Windows)
+ runLoop._stop()
+#else
CFRunLoopStop(runLoop.getCFRunLoop())
+#endif
}
}
diff --git a/Tests/Functional/Asynchronous/Expectations/main.swift b/Tests/Functional/Asynchronous/Expectations/main.swift
index d7ec8e9..0fce781 100644
--- a/Tests/Functional/Asynchronous/Expectations/main.swift
+++ b/Tests/Functional/Asynchronous/Expectations/main.swift
@@ -216,11 +216,11 @@
bar.fulfill()
}
- let start = CFAbsoluteTimeGetCurrent()
+ let start = Date.timeIntervalSinceReferenceDate
waitForExpectations(timeout: 0.5)
// Make sure we actually waited long enough.
- XCTAssertGreaterThanOrEqual(CFAbsoluteTimeGetCurrent() - start, 0.5)
+ XCTAssertGreaterThanOrEqual(Date.timeIntervalSinceReferenceDate - start, 0.5)
}
// CHECK: Test Case 'ExpectationsTestCase.test_combiningInverseAndStandardExpectationsFailWithTimeout' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
@@ -231,11 +231,11 @@
foo.isInverted = true
expectation(description: "bar")
- let start = CFAbsoluteTimeGetCurrent()
+ let start = Date.timeIntervalSinceReferenceDate
waitForExpectations(timeout: 0.5)
// Make sure we actually waited long enough.
- XCTAssertGreaterThanOrEqual(CFAbsoluteTimeGetCurrent() - start, 0.5)
+ XCTAssertGreaterThanOrEqual(Date.timeIntervalSinceReferenceDate - start, 0.5)
}
// CHECK: Test Case 'ExpectationsTestCase.test_combiningInverseAndStandardExpectationsFailWithInverseFulfillment' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
@@ -269,9 +269,9 @@
c.fulfill()
}
- start = CFAbsoluteTimeGetCurrent()
+ start = Date.timeIntervalSinceReferenceDate
wait(for: [a, b, c], timeout: 0.2, enforceOrder: true)
- XCTAssertGreaterThanOrEqual(CFAbsoluteTimeGetCurrent() - start, 0.2)
+ XCTAssertGreaterThanOrEqual(Date.timeIntervalSinceReferenceDate - start, 0.2)
a = XCTestExpectation(description: "a")
a.isInverted = true
@@ -282,9 +282,9 @@
c.fulfill()
}
- start = CFAbsoluteTimeGetCurrent()
+ start = Date.timeIntervalSinceReferenceDate
wait(for: [b, a, c], timeout: 0.2, enforceOrder: true)
- XCTAssertGreaterThanOrEqual(CFAbsoluteTimeGetCurrent() - start, 0.2)
+ XCTAssertGreaterThanOrEqual(Date.timeIntervalSinceReferenceDate - start, 0.2)
a = XCTestExpectation(description: "a")
a.isInverted = true
@@ -295,9 +295,9 @@
c.fulfill()
}
- start = CFAbsoluteTimeGetCurrent()
+ start = Date.timeIntervalSinceReferenceDate
wait(for: [b, c, a], timeout: 0.2, enforceOrder: true)
- XCTAssertGreaterThanOrEqual(CFAbsoluteTimeGetCurrent() - start, 0.2)
+ XCTAssertGreaterThanOrEqual(Date.timeIntervalSinceReferenceDate - start, 0.2)
}
// PRAGMA MARK: - Counted Expectations
@@ -362,9 +362,9 @@
}
}
- let start = CFAbsoluteTimeGetCurrent()
+ let start = Date.timeIntervalSinceReferenceDate
let result = outerWaiter.wait(for: [outerExpectation], timeout: 0.1)
- let durationOfOuterWait = CFAbsoluteTimeGetCurrent() - start
+ let durationOfOuterWait = Date.timeIntervalSinceReferenceDate - start
XCTAssertEqual(result, .timedOut)
// The theoretical best-case duration in the current implementation is:
@@ -383,7 +383,7 @@
var outerExpectationFulfillTime = CFAbsoluteTime(0)
RunLoop.main.perform {
RunLoop.main.perform {
- outerExpectationFulfillTime = CFAbsoluteTimeGetCurrent()
+ outerExpectationFulfillTime = Date.timeIntervalSinceReferenceDate
outerExpectation.fulfill()
}
let innerWaiter = XCTWaiter(delegate: self)
@@ -391,10 +391,10 @@
XCTAssertEqual(innerWaiter.wait(for: [innerExpectation], timeout: 1), .timedOut)
}
- let start = CFAbsoluteTimeGetCurrent()
+ let start = Date.timeIntervalSinceReferenceDate
XCTAssertEqual(outerWaiter.wait(for: [outerExpectation], timeout: 1), .completed)
XCTAssertLessThanOrEqual(outerExpectationFulfillTime - start, 0.1)
- XCTAssertGreaterThanOrEqual(CFAbsoluteTimeGetCurrent() - start, 1)
+ XCTAssertGreaterThanOrEqual(Date.timeIntervalSinceReferenceDate - start, 1)
}
// PRAGMA MARK: - Waiter Conveniences
diff --git a/Tests/Functional/lit.cfg b/Tests/Functional/lit.cfg
index 840ad08..9c38ebd 100644
--- a/Tests/Functional/lit.cfg
+++ b/Tests/Functional/lit.cfg
@@ -38,15 +38,21 @@
built_products_dir = _getenv('BUILT_PRODUCTS_DIR')
# Force tests to build with -swift-version 4 for now.
-swift_exec = [
- _getenv('SWIFT_EXEC'),
- '-swift-version', '4',
- '-Xlinker', '-rpath',
- '-Xlinker', built_products_dir,
+swift_exec = [ _getenv('SWIFT_EXEC'), '-swift-version', '4', ]
+if not platform.system() == 'Windows':
+ swift_exec.extend(['-Xlinker', '-rpath', '-Xlinker', built_products_dir,])
+swift_exec.extend([
'-L', built_products_dir,
'-I', built_products_dir,
'-I', os.path.join(built_products_dir, 'swift'),
-]
+])
+
+if platform.system() == 'Linux':
+ swift_exec.extend(['-Xcc', '-DDEPLOYMENT_TARGET_LINUX'])
+elif platform.system() == 'Darwin':
+ swift_exec.extend(['-Xcc', '-DDEPLOYMENT_TARGET_MACOSX'])
+elif platform.system() == 'Windows':
+ swift_exec.extend(['-Xcc', '-DDEPLOYMENT_TARGET_WINDOWS'])
if platform.system() == 'Darwin':
# On Darwin, we need to make sure swiftc references the
@@ -68,13 +74,14 @@
'-I', os.path.join(built_products_dir, 'usr', 'local', 'include'),
])
else:
- # On Linux, we need to jump through extra hoops to link
- # swift-corelibs-foundation.
+ # We need to jump through extra hoops to link swift-corelibs-foundation.
foundation_dir = _getenv('FOUNDATION_BUILT_PRODUCTS_DIR')
core_foundation_dir = _getenv('CORE_FOUNDATION_BUILT_PRODUCTS_DIR')
+ if platform.system() == 'Windows':
+ swift_exec.extend(['-Xlinker', '-nodefaultlib:libcmt'])
+ else:
+ swift_exec.extend(['-Xlinker', '-rpath', '-Xlinker', foundation_dir,])
swift_exec.extend([
- '-Xlinker', '-rpath',
- '-Xlinker', foundation_dir,
'-L', foundation_dir,
'-I', foundation_dir,
'-I', os.path.join(foundation_dir, 'swift'),
@@ -110,7 +117,7 @@
os.path.dirname(os.path.abspath(__file__)),
'xctest_checker',
'xctest_checker.py')
-config.substitutions.append(('%{xctest_checker}', xctest_checker))
+config.substitutions.append(('%{xctest_checker}', '%%{python} %s' % xctest_checker))
# Add Python to run xctest_checker.py tests as part of XCTest tests
config.substitutions.append( ('%{python}', sys.executable) )