Skip to content

TimeInterval -> NSTimeInterval #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/XCTest/XCTestMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

#if os(Linux) || os(FreeBSD)
import Glibc
import Foundation
#else
import Darwin
import SwiftFoundation
#endif

internal func XCTPrint(message: String) {
Expand All @@ -36,7 +38,7 @@ struct XCTFailure {
}

internal struct XCTRun {
var duration: TimeInterval
var duration: NSTimeInterval
var method: String
var passed: Bool
var failures: [XCTFailure]
Expand Down
14 changes: 7 additions & 7 deletions Sources/XCTest/XCTimeUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

#if os(Linux) || os(FreeBSD)
import Glibc
import Foundation
#else
import Darwin
import SwiftFoundation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should borrow a page from swift-package-manager and extract these checks into a single location.

Something to consider for another pull request! ☝️

#endif

internal typealias TimeInterval = Double

/// Returns the number of seconds since the reference time as a Double.
private func currentTimeIntervalSinceReferenceTime() -> TimeInterval {
private func currentTimeIntervalSinceReferenceTime() -> NSTimeInterval {
var tv = timeval()
let currentTime = withUnsafeMutablePointer(&tv, { (t: UnsafeMutablePointer<timeval>) -> TimeInterval in
let currentTime = withUnsafeMutablePointer(&tv, { (t: UnsafeMutablePointer<timeval>) -> NSTimeInterval in
gettimeofday(t, nil)
return TimeInterval(t.pointee.tv_sec) + TimeInterval(t.pointee.tv_usec) / 1000000.0
return NSTimeInterval(t.pointee.tv_sec) + NSTimeInterval(t.pointee.tv_usec) / 1000000.0
})
return currentTime
}

/// Execute the given block and return the time spent during execution
internal func measureTimeExecutingBlock(@noescape block: () -> Void) -> TimeInterval {
internal func measureTimeExecutingBlock(@noescape block: () -> Void) -> NSTimeInterval {
let start = currentTimeIntervalSinceReferenceTime()
block()
let end = currentTimeIntervalSinceReferenceTime()
Expand All @@ -39,6 +39,6 @@ internal func measureTimeExecutingBlock(@noescape block: () -> Void) -> TimeInte
}

/// Returns a string version of the given time interval rounded to no more than 3 decimal places.
internal func printableStringForTimeInterval(timeInterval: TimeInterval) -> String {
internal func printableStringForTimeInterval(timeInterval: NSTimeInterval) -> String {
return String(round(timeInterval * 1000.0) / 1000.0)
}