Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test fixture for the assertion failure messages produced by XCTest
import XCTest // import SwiftXCTest
class Test: XCTestCase/*, XCTestCaseProvider*/ {
var allTests : [(String, () -> Void)] {
return [
("testAssert", testAssert),
("testAssertEqualOptionals", testAssertEqualOptionals),
("testAssertEqualArraySlices", testAssertEqualArraySlices),
("testAssertEqualContiguousArrays", testAssertEqualContiguousArrays),
("testAssertEqualArrays", testAssertEqualArrays),
("testAssertEqualDictionaries", testAssertEqualDictionaries),
("testAssertEqualWithAccuracy", testAssertEqualWithAccuracy),
("testAssertFalse", testAssertFalse),
("testAssertGreaterThan", testAssertGreaterThan),
("testAssertGreaterThanOrEqual", testAssertGreaterThanOrEqual),
("testAssertLessThan", testAssertLessThan),
("testAssertLessThanOrEqual", testAssertLessThanOrEqual),
("testAssertNil", testAssertNil),
("testAssertNotEqualOptionals", testAssertNotEqualOptionals),
("testAssertNotEqualArraySlices", testAssertNotEqualArraySlices),
("testAssertNotEqualContiguousArrays", testAssertNotEqualContiguousArrays),
("testAssertNotEqualArrays", testAssertNotEqualArrays),
("testAssertNotEqualDictionaries", testAssertNotEqualDictionaries),
("testAssertNotEqualWithAccuracy", testAssertNotEqualWithAccuracy),
("testAssertNotNil", testAssertNotNil),
("testAssertTrue", testAssertTrue),
("testFail", testFail),
]
}
func testAssert() {
XCTAssert(false, "message", file: "test.swift")
}
func testAssertEqualOptionals() {
XCTAssertEqual(1, 2, "message", file: "test.swift")
}
func testAssertEqualArraySlices() {
XCTAssertEqual([1][0..<1], [2][0..<1], "message", file: "test.swift")
}
func testAssertEqualContiguousArrays() {
XCTAssertEqual(ContiguousArray(arrayLiteral: 1), ContiguousArray(arrayLiteral: 2), "message", file: "test.swift")
}
func testAssertEqualArrays() {
XCTAssertEqual([1], [2], "message", file: "test.swift")
}
func testAssertEqualDictionaries() {
XCTAssertEqual([1:2], [3:4], "message", file: "test.swift")
}
func testAssertEqualWithAccuracy() {
XCTAssertEqualWithAccuracy(1, 2, accuracy: 0.1, "message", file: "test.swift")
}
func testAssertFalse() {
XCTAssertFalse(true, "message", file: "test.swift")
}
func testAssertGreaterThan() {
XCTAssertGreaterThan(0, 0, "message", file: "test.swift")
}
func testAssertGreaterThanOrEqual() {
XCTAssertGreaterThanOrEqual(-1, 0, "message", file: "test.swift")
}
func testAssertLessThan() {
XCTAssertLessThan(0, 0, "message", file: "test.swift")
}
func testAssertLessThanOrEqual() {
XCTAssertLessThanOrEqual(1, 0, "message", file: "test.swift")
}
func testAssertNil() {
XCTAssertNil("notnil", "message", file: "test.swift")
}
func testAssertNotEqualOptionals() {
XCTAssertNotEqual(1, 1, "message", file: "test.swift")
}
func testAssertNotEqualArraySlices() {
XCTAssertNotEqual([1][0..<1], [1][0..<1], "message", file: "test.swift")
}
func testAssertNotEqualContiguousArrays() {
XCTAssertNotEqual(ContiguousArray(arrayLiteral: 1), ContiguousArray(arrayLiteral: 1), "message", file: "test.swift")
}
func testAssertNotEqualArrays() {
XCTAssertNotEqual([1], [1], "message", file: "test.swift")
}
func testAssertNotEqualDictionaries() {
XCTAssertNotEqual([1:1], [1:1], "message", file: "test.swift")
}
func testAssertNotEqualWithAccuracy() {
XCTAssertNotEqualWithAccuracy(1, 1, 0.1, "message", file: "test.swift")
}
func testAssertNotNil() {
XCTAssertNotNil(nil, "message", file: "test.swift")
}
func testAssertTrue() {
XCTAssertTrue(false, "message", file: "test.swift")
}
func testFail() {
XCTFail("message", file: "test.swift")
}
}
Test Suite 'All tests' started at 2015-12-22 20:40:53.818
Test Suite 'Test.xctest' started at 2015-12-22 20:40:53.819
Test Suite 'Test' started at 2015-12-22 20:40:53.820
Test Case '-[Test.Test testAssert]' started.
test.swift:32: error: -[Test.Test testAssert] : XCTAssertTrue failed - message
Test Case '-[Test.Test testAssert]' failed (0.003 seconds).
Test Case '-[Test.Test testAssertEqualArrays]' started.
test.swift:48: error: -[Test.Test testAssertEqualArrays] : XCTAssertEqual failed: ("[1]") is not equal to ("[2]") - message
Test Case '-[Test.Test testAssertEqualArrays]' failed (0.003 seconds).
Test Case '-[Test.Test testAssertEqualArraySlices]' started.
test.swift:40: error: -[Test.Test testAssertEqualArraySlices] : XCTAssertEqual failed: ("[1]") is not equal to ("[2]") - message
Test Case '-[Test.Test testAssertEqualArraySlices]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertEqualContiguousArrays]' started.
test.swift:44: error: -[Test.Test testAssertEqualContiguousArrays] : XCTAssertEqual failed: ("[1]") is not equal to ("[2]") - message
Test Case '-[Test.Test testAssertEqualContiguousArrays]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertEqualDictionaries]' started.
test.swift:52: error: -[Test.Test testAssertEqualDictionaries] : XCTAssertEqual failed: ("[1: 2]") is not equal to ("[3: 4]") - message
Test Case '-[Test.Test testAssertEqualDictionaries]' failed (0.056 seconds).
Test Case '-[Test.Test testAssertEqualOptionals]' started.
test.swift:36: error: -[Test.Test testAssertEqualOptionals] : XCTAssertEqual failed: ("Optional(1)") is not equal to ("Optional(2)") - message
Test Case '-[Test.Test testAssertEqualOptionals]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertEqualWithAccuracy]' started.
test.swift:56: error: -[Test.Test testAssertEqualWithAccuracy] : XCTAssertEqualWithAccuracy failed: ("1.0") is not equal to ("2.0") +/- ("0.1") - message
Test Case '-[Test.Test testAssertEqualWithAccuracy]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertFalse]' started.
test.swift:60: error: -[Test.Test testAssertFalse] : XCTAssertFalse failed - message
Test Case '-[Test.Test testAssertFalse]' failed (0.086 seconds).
Test Case '-[Test.Test testAssertGreaterThan]' started.
test.swift:64: error: -[Test.Test testAssertGreaterThan] : XCTAssertGreaterThan failed: ("0") is not greater than ("0") - message
Test Case '-[Test.Test testAssertGreaterThan]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertGreaterThanOrEqual]' started.
test.swift:68: error: -[Test.Test testAssertGreaterThanOrEqual] : XCTAssertGreaterThanOrEqual failed: ("-1") is less than ("0") - message
Test Case '-[Test.Test testAssertGreaterThanOrEqual]' failed (0.002 seconds).
Test Case '-[Test.Test testAssertLessThan]' started.
test.swift:72: error: -[Test.Test testAssertLessThan] : XCTAssertLessThan failed: ("0") is not less than ("0") - message
Test Case '-[Test.Test testAssertLessThan]' failed (0.002 seconds).
Test Case '-[Test.Test testAssertLessThanOrEqual]' started.
test.swift:76: error: -[Test.Test testAssertLessThanOrEqual] : XCTAssertLessThanOrEqual failed: ("1") is greater than ("0") - message
Test Case '-[Test.Test testAssertLessThanOrEqual]' failed (0.002 seconds).
Test Case '-[Test.Test testAssertNil]' started.
test.swift:80: error: -[Test.Test testAssertNil] : XCTAssertNil failed: "notnil" - message
Test Case '-[Test.Test testAssertNil]' failed (0.025 seconds).
Test Case '-[Test.Test testAssertNotEqualArrays]' started.
test.swift:96: error: -[Test.Test testAssertNotEqualArrays] : XCTAssertNotEqual failed: ("[1]") is equal to ("[1]") - message
Test Case '-[Test.Test testAssertNotEqualArrays]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertNotEqualArraySlices]' started.
test.swift:88: error: -[Test.Test testAssertNotEqualArraySlices] : XCTAssertNotEqual failed: ("[1]") is equal to ("[1]") - message
Test Case '-[Test.Test testAssertNotEqualArraySlices]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertNotEqualContiguousArrays]' started.
test.swift:92: error: -[Test.Test testAssertNotEqualContiguousArrays] : XCTAssertNotEqual failed: ("[1]") is equal to ("[1]") - message
Test Case '-[Test.Test testAssertNotEqualContiguousArrays]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertNotEqualDictionaries]' started.
test.swift:100: error: -[Test.Test testAssertNotEqualDictionaries] : XCTAssertNotEqual failed: ("[1: 1]") is equal to ("[1: 1]") - message
Test Case '-[Test.Test testAssertNotEqualDictionaries]' failed (0.002 seconds).
Test Case '-[Test.Test testAssertNotEqualOptionals]' started.
test.swift:84: error: -[Test.Test testAssertNotEqualOptionals] : XCTAssertNotEqual failed: ("Optional(1)") is equal to ("Optional(1)") - message
Test Case '-[Test.Test testAssertNotEqualOptionals]' failed (0.002 seconds).
Test Case '-[Test.Test testAssertNotEqualWithAccuracy]' started.
test.swift:104: error: -[Test.Test testAssertNotEqualWithAccuracy] : XCTAssertNotEqualWithAccuracy failed: ("1.0") is equal to ("1.0") +/- ("0.1") - message
Test Case '-[Test.Test testAssertNotEqualWithAccuracy]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertNotNil]' started.
test.swift:108: error: -[Test.Test testAssertNotNil] : XCTAssertNotNil failed - message
Test Case '-[Test.Test testAssertNotNil]' failed (0.001 seconds).
Test Case '-[Test.Test testAssertTrue]' started.
test.swift:112: error: -[Test.Test testAssertTrue] : XCTAssertTrue failed - message
Test Case '-[Test.Test testAssertTrue]' failed (0.002 seconds).
Test Case '-[Test.Test testFail]' started.
test.swift:116: error: -[Test.Test testFail] : failed - message
Test Case '-[Test.Test testFail]' failed (0.002 seconds).
Test Suite 'Test' failed at 2015-12-22 20:40:54.136.
Executed 22 tests, with 22 failures (0 unexpected) in 0.198 (0.316) seconds
Test Suite 'Test.xctest' failed at 2015-12-22 20:40:54.138.
Executed 22 tests, with 22 failures (0 unexpected) in 0.198 (0.318) seconds
Test Suite 'All tests' failed at 2015-12-22 20:40:54.175.
Executed 22 tests, with 22 failures (0 unexpected) in 0.198 (0.357) seconds
Test session log:
/var/folders/_v/_fff7r3n7zg1h27zpz5dv1g5bd9ssr/T/com.apple.dt.XCTest-status/Session-2015-12-22_20:40:44-0rXpSj.log
Program ended with exit code: 1
test.swift:32: error: -[Test.Test testAssert] : XCTAssertTrue failed - message
test.swift:36: error: -[Test.Test testAssertEqualOptionals] : XCTAssertEqual failed: ("Optional(1)") is not equal to ("Optional(2)") - message
test.swift:40: error: -[Test.Test testAssertEqualArraySlices] : XCTAssertEqual failed: ("[1]") is not equal to ("[2]") - message
test.swift:44: error: -[Test.Test testAssertEqualContiguousArrays] : XCTAssertEqual failed: ("[1]") is not equal to ("[2]") - message
test.swift:48: error: -[Test.Test testAssertEqualArrays] : XCTAssertEqual failed: ("[1]") is not equal to ("[2]") - message
test.swift:52: error: -[Test.Test testAssertEqualDictionaries] : XCTAssertEqual failed: ("[1: 2]") is not equal to ("[3: 4]") - message
test.swift:56: error: -[Test.Test testAssertEqualWithAccuracy] : XCTAssertEqualWithAccuracy failed: ("1.0") is not equal to ("2.0") +/- ("0.1") - message
test.swift:60: error: -[Test.Test testAssertFalse] : XCTAssertFalse failed - message
test.swift:64: error: -[Test.Test testAssertGreaterThan] : XCTAssertGreaterThan failed: ("0") is not greater than ("0") - message
test.swift:68: error: -[Test.Test testAssertGreaterThanOrEqual] : XCTAssertGreaterThanOrEqual failed: ("-1") is less than ("0") - message
test.swift:72: error: -[Test.Test testAssertLessThan] : XCTAssertLessThan failed: ("0") is not less than ("0") - message
test.swift:76: error: -[Test.Test testAssertLessThanOrEqual] : XCTAssertLessThanOrEqual failed: ("1") is greater than ("0") - message
test.swift:80: error: -[Test.Test testAssertNil] : XCTAssertNil failed: "notnil" - message
test.swift:84: error: -[Test.Test testAssertNotEqualOptionals] : XCTAssertNotEqual failed: ("Optional(1)") is equal to ("Optional(1)") - message
test.swift:88: error: -[Test.Test testAssertNotEqualArraySlices] : XCTAssertNotEqual failed: ("[1]") is equal to ("[1]") - message
test.swift:92: error: -[Test.Test testAssertNotEqualContiguousArrays] : XCTAssertNotEqual failed: ("[1]") is equal to ("[1]") - message
test.swift:96: error: -[Test.Test testAssertNotEqualArrays] : XCTAssertNotEqual failed: ("[1]") is equal to ("[1]") - message
test.swift:100: error: -[Test.Test testAssertNotEqualDictionaries] : XCTAssertNotEqual failed: ("[1: 1]") is equal to ("[1: 1]") - message
test.swift:104: error: -[Test.Test testAssertNotEqualWithAccuracy] : XCTAssertNotEqualWithAccuracy failed: ("1.0") is equal to ("1.0") +/- ("0.1") - message
test.swift:108: error: -[Test.Test testAssertNotNil] : XCTAssertNotNil failed - message
test.swift:112: error: -[Test.Test testAssertTrue] : XCTAssertTrue failed - message
test.swift:116: error: -[Test.Test testFail] : failed - message
@briancroom

This comment has been minimized.

Copy link
Owner Author

@briancroom briancroom commented Dec 23, 2015

Test.swift - An XCTestCase fixture that illustrates the failure output of every XCTAssert* function available in Swift. It builds and runs as-is on Darwin with Xcode's XCTest, and builds with swift-corelibs-xctest by including the currently-commented elements.
XCTest-Darwin-Output-Complete.txt - The output produced by Darwin XCTest when executing the fixture
XCTest-Darwin-Output-Filtered.txt - The XCTest output filtered to only include the lines containing an assertion failure message.

This is intended to be used when developing swift-corelibs-xctest to help verify that it appropriately mimics Darwin's XCTest output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment