Skip to content

Commit

Permalink
Restored Windows tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
SDGGiesbrecht authored Aug 14, 2020
1 parent 1d41583 commit 6f42f70
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ public func testCustomStringConvertibleConformance<T, L>(
var report = ""
for localization in localizations.allCases {
if let icon = localization.icon {
print(icon, to: &report)
report.append(contentsOf: String(icon))
} else {
print(localization.code, to: &report)
report.append(contentsOf: localization.code)
}
report.append("\n")
LocalizationSetting(orderOfPrecedence: [localization.code]).do {
print(String(describing: instance), to: &report)
report.append(contentsOf: String(describing: instance))
report.append("\n")
}
print("", to: &report)
report.append("\n")
}

// #workaround(Swift 5.2.4, Web doesn’t have Foundation yet.)
Expand All @@ -82,7 +84,7 @@ public func testCustomStringConvertibleConformance<T, L>(
)
#endif

if let playround = instance as? CustomPlaygroundDisplayConvertible {
_ = playround.playgroundDescription
if let playground = instance as? CustomPlaygroundDisplayConvertible {
_ = playground.playgroundDescription
}
}
83 changes: 37 additions & 46 deletions Sources/SDGPersistenceTestUtilities/Specification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,57 +129,48 @@
.map({ String($0.line) + String($0.newline) })
let differences = stringLines.changes(from: specificationLines)

#if os(Windows)

// #workaround(Swift 5.2.4, The standard report triggers a SegFault.)
let report = "\(differences)"

#else

var removals: Set<Int> = []
var inserts: [Int: String] = [:]
for difference in differences {
switch difference {
case .remove(let offset, _, _):
removals.insert(offset)
case .insert(let offset, let element, _):
inserts[offset] = element
}
var removals: Set<Int> = []
var inserts: [Int: String] = [:]
for difference in differences {
switch difference {
case .remove(let offset, _, _):
removals.insert(offset)
case .insert(let offset, let element, _):
inserts[offset] = element
}
}

var reportArray: [String] = []
var resultOffset = 0
var originalOffset = 0
var continuingKeptRange = false
while resultOffset ≠ stringLines.count originalOffset ≠ specificationLines.count {
defer {
resultOffset += 1
originalOffset += 1
}
var reportArray: [String] = []
var resultOffset = 0
var originalOffset = 0
var continuingKeptRange = false
while resultOffset ≠ stringLines.count originalOffset ≠ specificationLines.count {
defer {
resultOffset += 1
originalOffset += 1
}

if originalOffset removals {
reportArray.append(
""
+ specificationLines[
specificationLines.index(specificationLines.startIndex, offsetBy: originalOffset)
]
)
resultOffset −= 1
continuingKeptRange = false
} else if let insert = inserts[resultOffset] {
reportArray.append("+ " + insert)
originalOffset −= 1
continuingKeptRange = false
} else {
if ¬continuingKeptRange {
reportArray.append(" [...]\n")
}
continuingKeptRange = true
if originalOffset removals {
reportArray.append(
""
+ specificationLines[
specificationLines.index(specificationLines.startIndex, offsetBy: originalOffset)
]
)
resultOffset −= 1
continuingKeptRange = false
} else if let insert = inserts[resultOffset] {
reportArray.append("+ " + insert)
originalOffset −= 1
continuingKeptRange = false
} else {
if ¬continuingKeptRange {
reportArray.append(" [...]\n")
}
continuingKeptRange = true
}
let report = reportArray.joined()

#endif
}
let report = reportArray.joined()

fail(
String(
Expand Down
39 changes: 14 additions & 25 deletions Tests/SDGBinaryDataTests/APITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ class APITests: TestCase {

let data = Data([UInt8.max])
XCTAssertEqual(data.binary.count, 8)
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
XCTAssertEqual(data.binary.map({ $0 ? "1" : "0" }).joined(), "11111111")
#endif
XCTAssertEqual(data.binary.map({ $0 ? "1" : "0" }).joined(), "11111111")

var toReverse = Data([0b11110000, 0b00000000])
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
toReverse.binary.reverse()
XCTAssertEqual(toReverse, Data([0b000000000, 0b00001111]))
#endif
toReverse.binary.reverse()
XCTAssertEqual(toReverse, Data([0b000000000, 0b00001111]))

let alternating = Data([0b01010101, 0b01010101])
let sorted = Data([0b00000000, 0b11111111])
Expand All @@ -58,15 +54,13 @@ class APITests: TestCase {
XCTAssertEqual(alternating.bitwiseExclusiveOr(with: sorted), Data([0b01010101, 0b10101010]))

var forDescription = Data([0, 0])
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
forDescription.binary[11] = true
testCustomStringConvertibleConformance(
of: forDescription.binary,
localizations: InterfaceLocalization.self,
uniqueTestName: "10th",
overwriteSpecificationInsteadOfFailing: false
)
#endif
forDescription.binary[11] = true
testCustomStringConvertibleConformance(
of: forDescription.binary,
localizations: InterfaceLocalization.self,
uniqueTestName: "10th",
overwriteSpecificationInsteadOfFailing: false
)
}

func testDataStream() {
Expand All @@ -86,20 +80,15 @@ class APITests: TestCase {
while ¬inputStream.buffer.isEmpty {
let transfer = inputStream.buffer.removeFirst()
outputStream.buffer.append(transfer)

#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
results.append(contentsOf: outputStream.extractCompleteUnits())
#endif
results.append(contentsOf: outputStream.extractCompleteUnits())
}
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
XCTAssertEqual(results, [forwards, backwards])
#endif
XCTAssertEqual(results, [forwards, backwards])
}

func testUInt() {
var forDescription: UInt8 = 0
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
forDescription.binary[0] = true
forDescription.binary[0] = true
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCustomStringConvertibleConformance(
of: forDescription.binary,
localizations: InterfaceLocalization.self,
Expand Down
34 changes: 17 additions & 17 deletions Tests/SDGCalendarTests/APITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import SDGXCTestUtilities
class APITests: TestCase {

func testCalendarComponent() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
XCTAssertEqual(GregorianDay.meanDuration, GregorianDay.maximumDuration)
XCTAssertEqual(GregorianDay.minimumDuration, GregorianDay.maximumDuration)

Expand Down Expand Up @@ -57,7 +57,7 @@ class APITests: TestCase {
}

func testCalendarDate() throws {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
// Force these to take place first.
InternalTests.testHebrewYear()

Expand Down Expand Up @@ -295,7 +295,7 @@ class APITests: TestCase {
}

func testCalendarInterval() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testMeasurementConformance(of: CalendarInterval<FloatMax>.self)
testCustomStringConvertibleConformance(
of: 1.days,
Expand All @@ -316,7 +316,7 @@ class APITests: TestCase {
}

func testGregorianDay() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: GregorianDay(12), uniqueTestName: "12")
testCustomStringConvertibleConformance(
of: GregorianDay(4),
Expand All @@ -340,7 +340,7 @@ class APITests: TestCase {
}

func testGregorianHour() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: GregorianHour(12), uniqueTestName: "12")
testDecoding(GregorianHour.self, failsFor: 600) // Invalid raw value.
testCustomStringConvertibleConformance(
Expand All @@ -353,7 +353,7 @@ class APITests: TestCase {
}

func testGregorianMinute() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: GregorianMinute(12), uniqueTestName: "12")
testCustomStringConvertibleConformance(
of: GregorianMinute(14),
Expand All @@ -365,7 +365,7 @@ class APITests: TestCase {
}

func testGregorianMonth() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: GregorianMonth.january, uniqueTestName: "January")
testDecoding(GregorianMonth.self, failsFor: 120) // Invalid raw value.
testCustomStringConvertibleConformance(
Expand Down Expand Up @@ -403,7 +403,7 @@ class APITests: TestCase {
}

func testGregorianSecond() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: GregorianSecond(12), uniqueTestName: "12")
testCustomStringConvertibleConformance(
of: GregorianSecond(12),
Expand All @@ -420,7 +420,7 @@ class APITests: TestCase {
}

func testGregorianWeekday() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: GregorianWeekday.sunday, uniqueTestName: "Sunday")
for ordinal in 1...7 {
testCustomStringConvertibleConformance(
Expand All @@ -434,7 +434,7 @@ class APITests: TestCase {
}

func testGregorianYear() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: GregorianYear(1234), uniqueTestName: "1234")
testCustomStringConvertibleConformance(
of: GregorianYear(1870),
Expand Down Expand Up @@ -466,7 +466,7 @@ class APITests: TestCase {
}

func testHebrewDay() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: HebrewDay(12), uniqueTestName: "12")

var day: HebrewDay = 30
Expand All @@ -491,7 +491,7 @@ class APITests: TestCase {
}

func testHebrewHour() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: HebrewHour(12), uniqueTestName: "12")
testCustomStringConvertibleConformance(
of: HebrewHour(3),
Expand All @@ -505,7 +505,7 @@ class APITests: TestCase {
}

func testHebrewMonth() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: HebrewMonth.tishrei, uniqueTestName: "Tishrei")
testCodableConformance(of: HebrewMonth.adar, uniqueTestName: "Adar")
testCodableConformance(of: HebrewMonth.adarI, uniqueTestName: "Adar I")
Expand Down Expand Up @@ -581,7 +581,7 @@ class APITests: TestCase {
}

func testHebrewMonthAndYear() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(
of: HebrewMonthAndYear(month: .tishrei, year: 2345),
uniqueTestName: "Tishrei, 2345"
Expand All @@ -596,7 +596,7 @@ class APITests: TestCase {
}

func testHebrewPart() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: HebrewPart(124), uniqueTestName: "124")
testCustomStringConvertibleConformance(
of: HebrewPart(82),
Expand All @@ -610,13 +610,13 @@ class APITests: TestCase {
}

func testHebrewWeekday() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: HebrewWeekday.sunday, uniqueTestName: "Sunday")
#endif
}

func testHebrewYear() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
testCodableConformance(of: HebrewYear(1234), uniqueTestName: "1234")

let length = FloatMax(HebrewYear(5777).numberOfDays) × (1 as FloatMax).days
Expand Down
10 changes: 5 additions & 5 deletions Tests/SDGCalendarTests/InternalTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import SDGXCTestUtilities
class InternalTests: TestCase {

func testDate() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
let date = CalendarDate(gregorian: .august, 28, 8232)
let datesDirectory = testSpecificationDirectory().appendingPathComponent("Date Formats")
compare(
Expand Down Expand Up @@ -68,7 +68,7 @@ class InternalTests: TestCase {
}

func testGregorianWeekdayDate() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
XCTAssertEqual(
CalendarDate(
definition: GregorianWeekdayDate(
Expand All @@ -85,7 +85,7 @@ class InternalTests: TestCase {
}

func testHebrewWeekdayDate() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
XCTAssertEqual(
CalendarDate(definition: HebrewWeekdayDate(week: 1, weekday: .thursday, hour: 0, part: 0)),
CalendarDate(hebrew: .tishrei, 15, 5758)
Expand All @@ -94,7 +94,7 @@ class InternalTests: TestCase {
}

func testHebrewYear() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
InternalTests.testHebrewYear()
#endif
}
Expand All @@ -115,7 +115,7 @@ class InternalTests: TestCase {
}

func testRelativeDate() {
#if !os(Windows) // #workaround(Swift 5.2.4, SegFault)
#if !os(Windows) // #workaround(Swift 5.2.4, Segmentation fault.)
let date = CalendarDate.hebrewNow()
XCTAssertEqual(CalendarDate(definition: date.converted(to: RelativeDate.self)), date)
#endif
Expand Down
Loading

0 comments on commit 6f42f70

Please sign in to comment.