Skip to content

Commit

Permalink
Merge pull request #62 from IBM-Swift/issue_1056
Browse files Browse the repository at this point in the history
Add test for Mac vs Linux test count. Randomize test order on Linux. Kitura/Kitura#1056
  • Loading branch information
billabt authored Apr 13, 2017
2 parents ec5e04f + d4e6f02 commit eb8bea1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
28 changes: 26 additions & 2 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,33 @@
//

import XCTest

import Glibc
@testable import SocketTests

// http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift
extension MutableCollection where Indices.Iterator.Element == Index {
mutating func shuffle() {
let c = count
guard c > 1 else { return }

srand(UInt32(time(nil)))
for (firstUnshuffled , unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swap(&self[firstUnshuffled], &self[i])
}
}
}

extension Sequence {
func shuffled() -> [Iterator.Element] {
var result = Array(self)
result.shuffle()
return result
}
}

XCTMain([
testCase(SocketTests.allTests),
testCase(SocketTests.allTests.shuffled()),
])
3 changes: 1 addition & 2 deletions Tests/SocketTests/SocketTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,8 @@ class SocketTests: XCTestCase {
print("testReadWriteUnix Error reported: \(socketError.description)")
XCTFail()
}

}
static var allTests = [
("testDefaultCreate", testDefaultCreate),
("testCreateIPV6", testCreateIPV6),
Expand Down
31 changes: 31 additions & 0 deletions Tests/SocketTests/VerifyLinuxTestCount.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright IBM Corporation 2017
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#if os(OSX)
import XCTest

class VerifyLinuxTestCount: XCTestCase {
func testVerifyLinuxTestCount() {
var linuxCount: Int
var darwinCount: Int

// SocketTests
linuxCount = SocketTests.allTests.count
darwinCount = Int(SocketTests.defaultTestSuite().testCaseCount)
XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from SocketTests.allTests")
}
}
#endif

0 comments on commit eb8bea1

Please sign in to comment.