Skip to content

Commit 07b2b17

Browse files
author
David Ungar
committed
Fixed up test
1 parent 8ac661a commit 07b2b17

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

Sources/SwiftDriver/Utilities/DateAdditions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public extension Date {
2525
self = Date(timeIntervalSince1970: Double(secs) + Double(nanos) / 1e9)
2626
}
2727
var legacyDriverSecsAndNanos: [Int] {
28-
let totalNanos = timeIntervalSince1970
29-
let secs = Int( floor(totalNanos))
30-
let nanos = Int((totalNanos - floor(totalNanos)) * 1e9)
28+
let totalSecs = timeIntervalSince1970
29+
let secs = Int( floor(totalSecs))
30+
let nanos = Int((totalSecs - floor(totalSecs)) * 1e9)
3131
return [secs, nanos]
3232
}
3333
}

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ final class IncrementalCompilationTests: XCTestCase {
132132
XCTAssertTrue(foundEdge)
133133
}
134134

135+
func testDateConversion() {
136+
let sn = [0, 8000]
137+
let d = try! Date(legacyDriverSecsAndNanos: sn)
138+
XCTAssert(isCloseEnough(d.legacyDriverSecsAndNanos, sn))
139+
}
135140
func testReadAndWriteBuildRecord() throws {
136141
let version = "Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)"
137142
let options = "abbbfbcaf36b93e58efaadd8271ff142"
@@ -142,24 +147,41 @@ final class IncrementalCompilationTests: XCTestCase {
142147
"""
143148
version: "\(version)"
144149
options: "\(options)"
145-
build_time: [1570318779, 32358000]
150+
build_time: [1570318779, 32357931]
146151
inputs:
147152
"\(file2)": !dirty [1570318778, 0]
148153
"\(main)": [1570083660, 0]
149-
"\(gazorp)": !private [0,0]
154+
"\(gazorp)": !private [0, 0]
155+
150156
"""
151157
let buildRecord = try InputInfoMap(contents: inputString)
152158
XCTAssertEqual(buildRecord.swiftVersion, version)
153159
XCTAssertEqual(buildRecord.argsHash, options)
154160
XCTAssertEqual(buildRecord.inputInfos.count, 3)
161+
XCTAssert(isCloseEnough(buildRecord.buildTime.legacyDriverSecsAndNanos,
162+
[1570318779, 32357931]))
163+
155164
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: file2 )]!.status,
156165
.needsCascadingBuild)
166+
XCTAssert(try! isCloseEnough(buildRecord.inputInfos[VirtualPath(path: file2 )]!
167+
.previousModTime.legacyDriverSecsAndNanos,
168+
[1570318778, 0]))
157169
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: gazorp)]!.status,
158170
.needsNonCascadingBuild)
171+
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: gazorp)]!
172+
.previousModTime.legacyDriverSecsAndNanos,
173+
[0, 0])
159174
XCTAssertEqual(try! buildRecord.inputInfos[VirtualPath(path: main )]!.status,
160175
.upToDate)
176+
XCTAssert(try! isCloseEnough( buildRecord.inputInfos[VirtualPath(path: main )]!
177+
.previousModTime.legacyDriverSecsAndNanos,
178+
[1570083660, 0]))
161179

162180
let outputString = try buildRecord.encode()
163181
XCTAssertEqual(inputString, outputString)
164182
}
183+
/// The date conversions are not exact
184+
func isCloseEnough(_ a: [Int], _ b: [Int]) -> Bool {
185+
a[0] == b[0] && abs(a[1] - b[1]) <= 100
186+
}
165187
}

0 commit comments

Comments
 (0)